Skip to content

Commit

Permalink
Adds IS <TYPE> tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell committed Dec 22, 2023
1 parent 1843c0a commit caca049
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ internal object PartiQLHeader : Header() {
parameters = listOf(
FunctionParameter("value", ANY)
),
isNullCall = false, // TODO: Should this be true?
isNullable = false
isNullable = false,
isNullCall = false,
)
}

Expand All @@ -427,7 +427,7 @@ internal object PartiQLHeader : Header() {
FunctionParameter("type_parameter_1", INT32),
FunctionParameter("value", ANY)
),
isNullable = false, // TODO: Should this be true?
isNullable = false,
isNullCall = false
)
}
Expand Down Expand Up @@ -455,8 +455,8 @@ internal object PartiQLHeader : Header() {
FunctionParameter("type_parameter_2", INT32),
FunctionParameter("value", ANY) // TODO: Decide if we need to further segment this
),
isNullCall = false,
isNullable = false
isNullable = false,
isNullCall = false
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,66 @@ class PlanTyperTestsPorted {
),
)

@JvmStatic
fun isTypeCases() = listOf(
SuccessTestCase(
name = "IS BOOL",
key = key("is-type-00"),
catalog = "pql",
catalogPath = listOf("main"),
expected = StaticType.BOOL
),
SuccessTestCase(
name = "IS INT",
key = key("is-type-01"),
catalog = "pql",
catalogPath = listOf("main"),
expected = StaticType.BOOL
),
SuccessTestCase(
name = "IS STRING",
key = key("is-type-02"),
catalog = "pql",
catalogPath = listOf("main"),
expected = StaticType.BOOL
),
SuccessTestCase(
name = "IS NULL",
key = key("is-type-03"),
catalog = "pql",
expected = StaticType.BOOL,
),
SuccessTestCase(
name = "MISSING IS NULL",
key = key("is-type-04"),
catalog = "pql",
expected = StaticType.BOOL,
),
SuccessTestCase(
name = "NULL IS NULL",
key = key("is-type-05"),
catalog = "pql",
expected = StaticType.BOOL,
),
SuccessTestCase(
name = "MISSING IS MISSING",
key = key("is-type-06"),
catalog = "pql",
expected = StaticType.BOOL,
),
SuccessTestCase(
name = "NULL IS MISSING",
key = key("is-type-07"),
catalog = "pql",
expected = StaticType.BOOL,
),
ErrorTestCase(
name = "ERROR always MISSING",
key = key("is-type-08"),
catalog = "pql",
),
)

@JvmStatic
fun sessionVariables() = listOf(
SuccessTestCase(
Expand Down Expand Up @@ -536,7 +596,10 @@ class PlanTyperTestsPorted {
problemHandler = assertProblemExists {
Problem(
UNKNOWN_PROBLEM_LOCATION,
PlanningProblemDetails.UnknownFunction("bitwise_and", listOf(StaticType.INT4, StaticType.STRING))
PlanningProblemDetails.UnknownFunction(
"bitwise_and",
listOf(StaticType.INT4, StaticType.STRING)
)
)
}
),
Expand Down Expand Up @@ -2972,6 +3035,11 @@ class PlanTyperTestsPorted {
@Execution(ExecutionMode.CONCURRENT)
fun testPivot(tc: TestCase) = runTest(tc)

@ParameterizedTest
@MethodSource("isTypeCases")
@Execution(ExecutionMode.CONCURRENT)
fun testIsType(tc: TestCase) = runTest(tc)

// --------- Finish Parameterized Tests ------

//
Expand All @@ -2980,7 +3048,7 @@ class PlanTyperTestsPorted {
private fun infer(
query: String,
session: PartiQLPlanner.Session,
problemCollector: ProblemCollector
problemCollector: ProblemCollector,
): PartiQLPlan {
val ast = parser.parse(query).root
return planner.plan(ast, session, problemCollector).plan
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--#[is-type-00]
false IS BOOL;

--#[is-type-01]
item.i_class_id IS INT;

--#[is-type-02]
item.i_brand IS STRING;

--#[is-type-03]
1 IS NULL;

--#[is-type-04]
MISSING IS NULL;

--#[is-type-05]
NULL IS NULL;

--#[is-type-06]
MISSING IS MISSING;

--#[is-type-07]
NULL IS MISSING;

--#[is-type-08]
-- ERROR! always MISSING
MISSING IS BOOL;

0 comments on commit caca049

Please sign in to comment.