Skip to content

Commit cc05d7f

Browse files
authored
Promote Rex.Op.Missing to compile time error in strict (#1437)
1 parent 82e6dcb commit cc05d7f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

partiql-eval/src/main/kotlin/org/partiql/eval/internal/Compiler.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.partiql.eval.internal.operator.rex.ExprCast
2626
import org.partiql.eval.internal.operator.rex.ExprCoalesce
2727
import org.partiql.eval.internal.operator.rex.ExprCollection
2828
import org.partiql.eval.internal.operator.rex.ExprLiteral
29+
import org.partiql.eval.internal.operator.rex.ExprMissing
2930
import org.partiql.eval.internal.operator.rex.ExprNullIf
3031
import org.partiql.eval.internal.operator.rex.ExprPathIndex
3132
import org.partiql.eval.internal.operator.rex.ExprPathKey
@@ -47,6 +48,7 @@ import org.partiql.plan.Rel
4748
import org.partiql.plan.Rex
4849
import org.partiql.plan.Statement
4950
import org.partiql.plan.debug.PlanPrinter
51+
import org.partiql.plan.rexOpErr
5052
import org.partiql.plan.visitor.PlanBaseVisitor
5153
import org.partiql.spi.fn.Agg
5254
import org.partiql.spi.fn.FnExperimental
@@ -233,6 +235,19 @@ internal class Compiler(
233235
return ExprCast(visitRex(node.arg, ctx), node.cast)
234236
}
235237

238+
override fun visitRexOpMissing(node: Rex.Op.Missing, ctx: StaticType?): Operator {
239+
return when (session.mode) {
240+
PartiQLEngine.Mode.PERMISSIVE -> {
241+
// Make a runtime TypeCheckException.
242+
ExprMissing(node.message)
243+
}
244+
PartiQLEngine.Mode.STRICT -> {
245+
// Promote to error.
246+
visitRexOpErr(rexOpErr(node.message, node.causes), null)
247+
}
248+
}
249+
}
250+
236251
// REL
237252
override fun visitRel(node: Rel, ctx: StaticType?): Operator.Relation {
238253
return super.visitRelOp(node.op, ctx) as Operator.Relation
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.partiql.eval.internal.operator.rex
2+
3+
import org.partiql.errors.TypeCheckException
4+
import org.partiql.eval.internal.Environment
5+
import org.partiql.eval.internal.operator.Operator
6+
import org.partiql.value.PartiQLValue
7+
import org.partiql.value.PartiQLValueExperimental
8+
9+
internal class ExprMissing(
10+
private val message: String,
11+
) : Operator.Expr {
12+
13+
@OptIn(PartiQLValueExperimental::class)
14+
override fun eval(env: Environment): PartiQLValue {
15+
throw TypeCheckException(message)
16+
}
17+
}

0 commit comments

Comments
 (0)