Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up ExprFunction test #529

Merged
merged 5 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lang/src/org/partiql/lang/eval/Exceptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ internal fun errNoContext(message: String, errorCode: ErrorCode, internal: Boole
internal fun err(message: String, errorCode: ErrorCode, errorContext: PropertyValueMap?, internal: Boolean): Nothing =
throw EvaluationException(message, errorCode, errorContext, internal = internal)

internal fun expectedArgTypeErrorMsg (types: List<ExprValueType>) : String = when (types.size) {
0 -> throw IllegalStateException("Should have at least one expected argument type. ")
1 -> types[0].toString()
else -> {
val window = types.size - 1
val (most, last) = types.windowed(window, window, true)
most.joinToString(", ") + ", or ${last.first()}"
}
}

/** Throw an [ErrorCode.EVALUATOR_INCORRECT_TYPE_OF_ARGUMENTS_TO_FUNC_CALL] error */
internal fun errInvalidArgumentType(
signature: FunctionSignature,
Expand All @@ -62,14 +72,7 @@ internal fun errInvalidArgumentType(
): Nothing {
val arity = signature.arity

val expectedTypeMsg = when(expectedTypes.size) {
1 -> expectedTypes[0]
else -> {
val window = expectedTypes.size - 1
val (most, last) = expectedTypes.windowed(window, window, true)
most.joinToString(", ") + ", or ${last.first()}"
}
}
val expectedTypeMsg = expectedArgTypeErrorMsg(expectedTypes)

val errorContext = propertyValueMapOf(
Property.FUNCTION_NAME to signature.name,
Expand Down
2 changes: 1 addition & 1 deletion lang/src/org/partiql/lang/syntax/SqlParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class SqlParser(
else -> errMalformedParseTree("Unsupported path component: ${it.type}")
}
}
path(rootExpr, pathComponents, metas)
path(rootExpr, pathComponents, rootExpr.metas) // Here we use its root source location, since itself has no source location (not a token).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for future PRs, it would be helpful to start with a clean commit history (i.e. not including commits from other PRs). GitHub shows this as a changed file even though your target branch, main, already has this change, which can be confusing for the reviewer.

You could start by creating the branch directly off of main:

git checkout main
git pull
git checkout feature-branch
... (make and commit changes) ...
... (create PR with feature-branch) ...

If the origin GitHub branch already has the commits, you can rebase and force push to the origin branch.

}
ParseType.PARAMETER -> parameter(token!!.value!!.longValue(), metas)
ParseType.CASE -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.partiql.lang.eval.builtins

import com.amazon.ion.Timestamp
import org.partiql.lang.ION
import org.partiql.lang.eval.Bindings
import org.partiql.lang.eval.EvaluationSession
import org.partiql.lang.eval.ExprValue
import org.partiql.lang.eval.ExprValueFactory
import org.partiql.lang.util.newFromIonText

/**
* Internal function used by ExprFunctionTest to test invalid argument type.
*/
internal val invalidArgTypeChecker = InvalidArgTypeChecker()
internal fun checkInvalidArgType(funcName: String, syntaxSuffix: String = "(", args: List<Argument>) =
invalidArgTypeChecker.checkInvalidArgType(funcName, syntaxSuffix, args)

/**
* Internal function used by ExprFunctionTest to test invalid arity.
*/
internal val invalidArityChecker = InvalidArityChecker()
internal fun checkInvalidArity(funcName: String, minArity: Int, maxArity: Int) =
invalidArityChecker.checkInvalidArity(funcName, minArity, maxArity)

private val valueFactory = ExprValueFactory.standard(ION)

private fun String.toExprValue(): ExprValue = valueFactory.newFromIonText(this)

private fun Map<String, String>.toBindings(): Bindings<ExprValue> = Bindings.ofMap(mapValues { it.value.toExprValue() })

/**
* Internal function used by ExprFunctionTest to build EvaluationSession.
*/
internal fun Map<String, String>.toSession() = EvaluationSession.build { globals(this@toSession.toBindings()) }

/**
* Internal function used by ExprFunctionTest to build EvaluationSession with now.
*/
internal fun buildSessionWithNow(numMillis: Long, localOffset: Int) =
EvaluationSession.build { now(Timestamp.forMillis(numMillis, localOffset)) }

/**
* Used by ExprFunctionTest to represent a test case.
*/
data class ExprFunctionTestCase(
val source: String,
val expected: String,
val session: EvaluationSession = EvaluationSession.standard()
)

This file was deleted.

52 changes: 0 additions & 52 deletions lang/test/org/partiql/lang/eval/builtins/ConcatEvaluationTest.kt

This file was deleted.

83 changes: 0 additions & 83 deletions lang/test/org/partiql/lang/eval/builtins/DateAddEvaluationTest.kt

This file was deleted.

Loading