Skip to content

Commit

Permalink
Promote Rex.Op.Missing to compile time error in strict (partiql#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell authored Apr 22, 2024
1 parent 82e6dcb commit cc05d7f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions partiql-eval/src/main/kotlin/org/partiql/eval/internal/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.partiql.eval.internal.operator.rex.ExprCast
import org.partiql.eval.internal.operator.rex.ExprCoalesce
import org.partiql.eval.internal.operator.rex.ExprCollection
import org.partiql.eval.internal.operator.rex.ExprLiteral
import org.partiql.eval.internal.operator.rex.ExprMissing
import org.partiql.eval.internal.operator.rex.ExprNullIf
import org.partiql.eval.internal.operator.rex.ExprPathIndex
import org.partiql.eval.internal.operator.rex.ExprPathKey
Expand All @@ -47,6 +48,7 @@ import org.partiql.plan.Rel
import org.partiql.plan.Rex
import org.partiql.plan.Statement
import org.partiql.plan.debug.PlanPrinter
import org.partiql.plan.rexOpErr
import org.partiql.plan.visitor.PlanBaseVisitor
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.FnExperimental
Expand Down Expand Up @@ -233,6 +235,19 @@ internal class Compiler(
return ExprCast(visitRex(node.arg, ctx), node.cast)
}

override fun visitRexOpMissing(node: Rex.Op.Missing, ctx: StaticType?): Operator {
return when (session.mode) {
PartiQLEngine.Mode.PERMISSIVE -> {
// Make a runtime TypeCheckException.
ExprMissing(node.message)
}
PartiQLEngine.Mode.STRICT -> {
// Promote to error.
visitRexOpErr(rexOpErr(node.message, node.causes), null)
}
}
}

// REL
override fun visitRel(node: Rel, ctx: StaticType?): Operator.Relation {
return super.visitRelOp(node.op, ctx) as Operator.Relation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.partiql.eval.internal.operator.rex

import org.partiql.errors.TypeCheckException
import org.partiql.eval.internal.Environment
import org.partiql.eval.internal.operator.Operator
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental

internal class ExprMissing(
private val message: String,
) : Operator.Expr {

@OptIn(PartiQLValueExperimental::class)
override fun eval(env: Environment): PartiQLValue {
throw TypeCheckException(message)
}
}

0 comments on commit cc05d7f

Please sign in to comment.