Skip to content

Commit

Permalink
Adds a CompilationErrorHandling flag to evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Apr 8, 2024
1 parent 3db0221 commit b4e5dfb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
31 changes: 30 additions & 1 deletion partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,40 @@ public interface PartiQLEngine {

public class Session(
val catalogs: Map<String, Connector> = mapOf(),
val mode: Mode = Mode.PERMISSIVE
val mode: Mode = Mode.PERMISSIVE,
val errorHandling: CompilationErrorHandling = CompilationErrorHandling.SIGNALING
)

/**
* This determines the behavior when the evaluator encounters scenarios in which a type check exception occurs.
*/
public enum class Mode {
/**
* Returns MISSING when a type check exception occurs.
*/
PERMISSIVE,

/**
* Propagates the type check exception.
*/
STRICT // AKA, Type Checking Mode in the PartiQL Specification
}

/**
* When the PartiQL Plan has determined that a function call or variable reference will always error, the
* [CompilationErrorHandling] will determine how the internal compiler will treat the error. Note that this is subtly
* different than [Mode]. [CompilationErrorHandling] is specifically used when nodes are known to ALWAYS return
* MISSING. The difference can be understood as compile-time ([CompilationErrorHandling]) vs run-time ([Mode]).
*/
public enum class CompilationErrorHandling {
/**
* Returns a literal MISSING.
*/
QUIET,

/**
* Errors out.
*/
SIGNALING
}
}
19 changes: 15 additions & 4 deletions partiql-eval/src/main/kotlin/org/partiql/eval/internal/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.partiql.eval.internal.operator.rex.ExprCallStatic
import org.partiql.eval.internal.operator.rex.ExprCase
import org.partiql.eval.internal.operator.rex.ExprCast
import org.partiql.eval.internal.operator.rex.ExprCollection
import org.partiql.eval.internal.operator.rex.ExprError
import org.partiql.eval.internal.operator.rex.ExprLiteral
import org.partiql.eval.internal.operator.rex.ExprPathIndex
import org.partiql.eval.internal.operator.rex.ExprPathKey
Expand Down Expand Up @@ -67,12 +68,22 @@ internal class Compiler(
TODO("Not yet implemented")
}

/**
* [Rex.Op.Err] comes from the inability for the planner to resolve a variable/function/etc. Depending on the
* configuration, this will either return MISSING or throw an error.
*/
@OptIn(PartiQLValueExperimental::class)
override fun visitRexOpErr(node: Rex.Op.Err, ctx: StaticType?): Operator {
val message = buildString {
this.appendLine(node.message)
PlanPrinter.append(this, plan)
return when (session.errorHandling) {
PartiQLEngine.CompilationErrorHandling.QUIET -> ExprError()
PartiQLEngine.CompilationErrorHandling.SIGNALING -> {
val message = buildString {
this.appendLine(node.message)
PlanPrinter.append(this, plan)
}
throw IllegalStateException(message)
}
}
throw IllegalStateException(message)
}

override fun visitRelOpErr(node: Rel.Op.Err, ctx: StaticType?): Operator {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 ExprError : Operator.Expr {
@OptIn(PartiQLValueExperimental::class)
override fun eval(env: Environment): PartiQLValue {
throw TypeCheckException()
}
}

0 comments on commit b4e5dfb

Please sign in to comment.