@@ -112,7 +112,7 @@ internal class PlanTyper(
112
112
/* *
113
113
* Rewrite the statement with inferred types and resolved variables
114
114
*/
115
- public fun resolve (statement : Statement ): Statement {
115
+ fun resolve (statement : Statement ): Statement {
116
116
if (statement !is Statement .Query ) {
117
117
throw IllegalArgumentException (" PartiQLPlanner only supports Query statements" )
118
118
}
@@ -182,15 +182,15 @@ internal class PlanTyper(
182
182
}
183
183
184
184
// compute element type
185
- val t = rex.type as StructType
185
+ val t = rex.type
186
186
val e = if (t.contentClosed) {
187
187
StaticType .unionOf(t.fields.map { it.value }.toSet()).flatten()
188
188
} else {
189
- StaticType . ANY
189
+ ANY
190
190
}
191
191
192
192
// compute rel type
193
- val kType = StaticType . STRING
193
+ val kType = STRING
194
194
val vType = e
195
195
val type = ctx!! .copyWithSchema(listOf (kType, vType))
196
196
@@ -419,7 +419,7 @@ internal class PlanTyper(
419
419
420
420
if (resolvedVar == null ) {
421
421
handleUndefinedVariable(path.steps.last())
422
- return rex(StaticType . ANY , rexOpErr(" Undefined variable ${node.identifier} " ))
422
+ return rex(ANY , rexOpErr(" Undefined variable ${node.identifier} " ))
423
423
}
424
424
val type = resolvedVar.type
425
425
val op = when (resolvedVar) {
@@ -439,7 +439,7 @@ internal class PlanTyper(
439
439
* Match path as far as possible (rewriting the steps), then infer based on resolved root and rewritten steps.
440
440
*/
441
441
override fun visitRexOpPath (node : Rex .Op .Path , ctx : StaticType ? ): Rex {
442
- val visitedSteps = node.steps.map { visitRexOpPathStep(it, null ) as Rex . Op . Path . Step }
442
+ val visitedSteps = node.steps.map { visitRexOpPathStep(it, null ) }
443
443
// 1. Resolve path prefix
444
444
val (root, steps) = when (val rootOp = node.root.op) {
445
445
is Rex .Op .Var .Unresolved -> {
@@ -448,7 +448,7 @@ internal class PlanTyper(
448
448
val resolvedVar = env.resolve(path, locals, rootOp.scope)
449
449
if (resolvedVar == null ) {
450
450
handleUndefinedVariable(path.steps.last())
451
- return rex(StaticType . ANY , node)
451
+ return rex(ANY , node)
452
452
}
453
453
val type = resolvedVar.type
454
454
val (op, steps) = when (resolvedVar) {
@@ -498,7 +498,7 @@ internal class PlanTyper(
498
498
}
499
499
500
500
// 4. Invalid path reference; always MISSING
501
- if (type == StaticType . MISSING ) {
501
+ if (type == MISSING ) {
502
502
handleAlwaysMissing()
503
503
return rexErr(" Unknown identifier $node " )
504
504
}
@@ -540,7 +540,7 @@ internal class PlanTyper(
540
540
is FnMatch .Dynamic -> {
541
541
val types = mutableSetOf<StaticType >()
542
542
if (match.isMissable && ! isNotMissable) {
543
- types.add(StaticType . MISSING )
543
+ types.add(MISSING )
544
544
}
545
545
val candidates = match.candidates.map { candidate ->
546
546
val rex = toRexCall(candidate, args, isNotMissable)
@@ -574,7 +574,7 @@ internal class PlanTyper(
574
574
newArgs.forEach {
575
575
if (it.type == MissingType && ! isNotMissable) {
576
576
handleAlwaysMissing()
577
- return rex(StaticType . MISSING , rexOpCallStatic(newFn, newArgs))
577
+ return rex(MISSING , rexOpCallStatic(newFn, newArgs))
578
578
}
579
579
}
580
580
@@ -615,14 +615,14 @@ internal class PlanTyper(
615
615
616
616
// Return type with calculated nullability
617
617
var type = when {
618
- isNull -> StaticType . NULL
618
+ isNull -> NULL
619
619
isNullable -> returns.toStaticType()
620
620
else -> returns.toNonNullStaticType()
621
621
}
622
622
623
623
// Some operators can return MISSING during runtime
624
624
if (match.isMissable && ! isNotMissable) {
625
- type = StaticType .unionOf(type, StaticType . MISSING )
625
+ type = StaticType .unionOf(type, MISSING )
626
626
}
627
627
628
628
// Finally, rewrite this node
@@ -740,8 +740,8 @@ internal class PlanTyper(
740
740
}
741
741
val ref = call.args.getOrNull(0 ) ? : error(" IS STRUCT requires an argument." )
742
742
val simplifiedCondition = when {
743
- ref.type.allTypes.all { it is StructType } -> rex(StaticType . BOOL , rexOpLit(boolValue(true )))
744
- ref.type.allTypes.none { it is StructType } -> rex(StaticType . BOOL , rexOpLit(boolValue(false )))
743
+ ref.type.allTypes.all { it is StructType } -> rex(BOOL , rexOpLit(boolValue(true )))
744
+ ref.type.allTypes.none { it is StructType } -> rex(BOOL , rexOpLit(boolValue(false )))
745
745
else -> condition
746
746
}
747
747
@@ -789,9 +789,9 @@ internal class PlanTyper(
789
789
when (field.k.op) {
790
790
is Rex .Op .Lit -> {
791
791
// A field is only included in the StructType if its key is a text literal
792
- val key = field.k.op as Rex . Op . Lit
792
+ val key = field.k.op
793
793
if (key.value is TextValue <* >) {
794
- val name = ( key.value as TextValue < * >) .string!!
794
+ val name = key.value.string!!
795
795
val type = field.v.type
796
796
structKeysSeent.add(name)
797
797
structTypeFields.add(StructType .Field (name, type))
@@ -919,7 +919,7 @@ internal class PlanTyper(
919
919
}
920
920
921
921
override fun visitRexOpErr (node : Rex .Op .Err , ctx : StaticType ? ): PlanNode {
922
- val type = ctx ? : StaticType . ANY
922
+ val type = ctx ? : ANY
923
923
return rex(type, node)
924
924
}
925
925
@@ -968,13 +968,13 @@ internal class PlanTyper(
968
968
PlanningProblemDetails .CompileError (" TupleUnion wasn't normalized to exclude union types." )
969
969
)
970
970
)
971
- possibleOutputTypes.add(StaticType . MISSING )
971
+ possibleOutputTypes.add(MISSING )
972
972
}
973
973
is NullType -> {
974
- return StaticType . NULL
974
+ return NULL
975
975
}
976
976
else -> {
977
- return StaticType . MISSING
977
+ return MISSING
978
978
}
979
979
}
980
980
}
@@ -1057,7 +1057,7 @@ internal class PlanTyper(
1057
1057
*/
1058
1058
private fun inferPathStep (type : StaticType , step : Rex .Op .Path .Step ): Pair <StaticType , Rex .Op .Path .Step > =
1059
1059
when (type) {
1060
- is AnyType -> StaticType . ANY to step
1060
+ is AnyType -> ANY to step
1061
1061
is StructType -> inferPathStep(type, step)
1062
1062
is ListType , is SexpType -> inferPathStep(type as CollectionType , step) to step
1063
1063
is AnyOfType -> {
@@ -1066,7 +1066,7 @@ internal class PlanTyper(
1066
1066
else -> {
1067
1067
val prevTypes = type.allTypes
1068
1068
if (prevTypes.any { it is AnyType }) {
1069
- StaticType . ANY to step
1069
+ ANY to step
1070
1070
} else {
1071
1071
val results = prevTypes.map { inferPathStep(it, step) }
1072
1072
val types = results.map { it.first }
@@ -1081,7 +1081,7 @@ internal class PlanTyper(
1081
1081
}
1082
1082
}
1083
1083
}
1084
- else -> StaticType . MISSING to step
1084
+ else -> MISSING to step
1085
1085
}
1086
1086
1087
1087
/* *
@@ -1156,13 +1156,13 @@ internal class PlanTyper(
1156
1156
isClosed && isOrdered -> {
1157
1157
struct.fields.firstOrNull { entry -> binding.isEquivalentTo(entry.key) }?.let {
1158
1158
(sensitive(it.key) to it.value)
1159
- } ? : (key to StaticType . MISSING )
1159
+ } ? : (key to MISSING )
1160
1160
}
1161
1161
// 2. Struct is closed
1162
1162
isClosed -> {
1163
1163
val matches = struct.fields.filter { entry -> binding.isEquivalentTo(entry.key) }
1164
1164
when (matches.size) {
1165
- 0 -> (key to StaticType . MISSING )
1165
+ 0 -> (key to MISSING )
1166
1166
1 -> matches.first().let { (sensitive(it.key) to it.value) }
1167
1167
else -> {
1168
1168
val firstKey = matches.first().key
@@ -1175,7 +1175,7 @@ internal class PlanTyper(
1175
1175
}
1176
1176
}
1177
1177
// 3. Struct is open
1178
- else -> (key to StaticType . ANY )
1178
+ else -> (key to ANY )
1179
1179
}
1180
1180
return type to name
1181
1181
}
@@ -1197,7 +1197,7 @@ internal class PlanTyper(
1197
1197
* Let TX be the single-column table that is the result of applying the <value expression>
1198
1198
* to each row of T and eliminating null values <--- all NULL values are eliminated as inputs
1199
1199
*/
1200
- public fun resolveAgg (agg : Agg .Unresolved , arguments : List <Rex >): Pair <Rel .Op .Aggregate .Call , StaticType > {
1200
+ fun resolveAgg (agg : Agg .Unresolved , arguments : List <Rex >): Pair <Rel .Op .Aggregate .Call , StaticType > {
1201
1201
var missingArg = false
1202
1202
val args = arguments.map {
1203
1203
val arg = visitRex(it, null )
@@ -1227,7 +1227,7 @@ internal class PlanTyper(
1227
1227
1228
1228
// Some operators can return MISSING during runtime
1229
1229
if (match.isMissable) {
1230
- type = StaticType .unionOf(type, StaticType . MISSING ).flatten()
1230
+ type = StaticType .unionOf(type, MISSING ).flatten()
1231
1231
}
1232
1232
1233
1233
// Finally, rewrite this node
@@ -1248,7 +1248,7 @@ internal class PlanTyper(
1248
1248
1249
1249
private fun Rex.type (typeEnv : TypeEnv ) = RexTyper (typeEnv).visitRex(this , this .type)
1250
1250
1251
- private fun rexErr (message : String ) = rex(StaticType . MISSING , rexOpErr(message))
1251
+ private fun rexErr (message : String ) = rex(MISSING , rexOpErr(message))
1252
1252
1253
1253
/* *
1254
1254
* I found decorating the tree with the binding names (for resolution) was easier than associating introduced
@@ -1315,7 +1315,7 @@ internal class PlanTyper(
1315
1315
private fun getElementTypeForFromSource (fromSourceType : StaticType ): StaticType = when (fromSourceType) {
1316
1316
is BagType -> fromSourceType.elementType
1317
1317
is ListType -> fromSourceType.elementType
1318
- is AnyType -> StaticType . ANY
1318
+ is AnyType -> ANY
1319
1319
is AnyOfType -> AnyOfType (fromSourceType.types.map { getElementTypeForFromSource(it) }.toSet())
1320
1320
// All the other types coerce into a bag of themselves (including null/missing/sexp).
1321
1321
else -> fromSourceType
@@ -1437,7 +1437,7 @@ internal class PlanTyper(
1437
1437
private fun Fn.Unresolved.isNotMissable (): Boolean {
1438
1438
return when (identifier) {
1439
1439
is Identifier .Qualified -> false
1440
- is Identifier .Symbol -> when (( identifier as Identifier . Symbol ) .symbol) {
1440
+ is Identifier .Symbol -> when (identifier.symbol) {
1441
1441
" and" -> true
1442
1442
" or" -> true
1443
1443
" not" -> true
@@ -1450,7 +1450,7 @@ internal class PlanTyper(
1450
1450
}
1451
1451
1452
1452
private fun Fn.Unresolved.isTypeAssertion (): Boolean {
1453
- return (identifier is Identifier .Symbol && ( identifier as Identifier . Symbol ) .symbol.startsWith(" is" ))
1453
+ return (identifier is Identifier .Symbol && identifier.symbol.startsWith(" is" ))
1454
1454
}
1455
1455
1456
1456
/* *
0 commit comments