Skip to content

Commit

Permalink
Removes unnecessary evaluation session properties
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Apr 16, 2024
1 parent 0bc754a commit 4304118
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 51 deletions.
31 changes: 1 addition & 30 deletions partiql-eval/src/main/kotlin/org/partiql/eval/PartiQLEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,11 @@ public interface PartiQLEngine {

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

/**
* 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
}
}
27 changes: 8 additions & 19 deletions partiql-eval/src/main/kotlin/org/partiql/eval/internal/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ import org.partiql.plan.Ref
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.visitor.PlanBaseVisitor
import org.partiql.spi.fn.Agg
import org.partiql.spi.fn.FnExperimental
import org.partiql.types.StaticType
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.PartiQLValueType
import org.partiql.value.missingValue
import java.lang.IllegalStateException

internal class Compiler(
Expand All @@ -70,20 +68,16 @@ internal class Compiler(
}

/**
* [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.
* Realistically, this should never execute -- since the problems of severity ERROR are sent to the problem handler
* at planning time. Implementors SHOULD fail compilation, however, if they decide not to, we will allow its execution
* and will treat this identically to [visitRexOpMissing].
*/
override fun visitRexOpErr(node: Rex.Op.Err, ctx: StaticType?): Operator {
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)
}
}
return ExprError(node.message)
}

override fun visitRexOpMissing(node: Rex.Op.Missing, ctx: StaticType?): Operator {
return ExprError(node.message)
}

override fun visitRelOpErr(node: Rel.Op.Err, ctx: StaticType?): Operator {
Expand Down Expand Up @@ -117,11 +111,6 @@ internal class Compiler(
return ExprStruct(fields)
}

@OptIn(PartiQLValueExperimental::class)
override fun visitRexOpMissing(node: Rex.Op.Missing, ctx: StaticType?): Operator {
return ExprLiteral(missingValue())
}

override fun visitRexOpSelect(node: Rex.Op.Select, ctx: StaticType?): Operator {
val rel = visitRel(node.rel, ctx)
val ordered = node.rel.type.props.contains(Rel.Prop.ORDERED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import org.partiql.eval.internal.operator.Operator
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental

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

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

0 comments on commit 4304118

Please sign in to comment.