Skip to content

Commit

Permalink
Updated planner.rs, expr.proto, QueryPlanSerde.scala for enum support
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantksharma committed Jun 1, 2024
1 parent 0b76c4a commit 773d8d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
14 changes: 5 additions & 9 deletions core/src/execution/datafusion/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,12 @@ impl PhysicalPlanner {
let child = self.create_expr(expr.child.as_ref().unwrap(), input_schema)?;
let datatype = to_arrow_datatype(expr.datatype.as_ref().unwrap());
let timezone = expr.timezone.clone();
let eval_mode = match expr.eval_mode {
0 => EvalMode::Legacy,
1 => EvalMode::Try,
2 => EvalMode::Ansi,
other => {
return Err(ExecutionError::GeneralError(format!(
"Invalid Cast EvalMode: \"{other}\""
)))
}
let eval_mode = match spark_expression::EvalMode::try_from(expr.eval_mode)? {
spark_expression::EvalMode::Legacy => EvalMode::Legacy,
spark_expression::EvalMode::Try => EvalMode::Try,
spark_expression::EvalMode::Ansi => EvalMode::Ansi,
};

Ok(Arc::new(Cast::new(child, datatype, eval_mode, timezone)))
}
ExprStruct::Hour(expr) => {
Expand Down
4 changes: 1 addition & 3 deletions core/src/execution/proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ message Cast {
Expr child = 1;
DataType datatype = 2;
string timezone = 3;
// Depreciateid: LEGACY, ANSI, or TRY - preserved for backward compatibity
string eval_mode_string= 4; // for backward compatibility
EvalMode eval_mode = 5; // New enum field
EvalMode eval_mode = 4;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde {
case "LEGACY" => ExprOuterClass.EvalMode.LEGACY
case "TRY" => ExprOuterClass.EvalMode.TRY
case "ANSI" => ExprOuterClass.EvalMode.ANSI
case _ =>
case invalid =>
throw new IllegalArgumentException(
"Invalid eval mode"
s"Invalid eval mode '$invalid' "
) // Assuming we want to catch errors strictly
}

Expand Down Expand Up @@ -1223,7 +1223,7 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde {
.newBuilder()
.setChild(e)
.setDatatype(serializeDataType(IntegerType).get)
.setEvalMode(stringToEvalMode("LEGACY")) // year is not affected by ANSI mode
.setEvalMode(ExprOuterClass.EvalMode.LEGACY)
.build())
.build()
})
Expand Down

0 comments on commit 773d8d1

Please sign in to comment.