Skip to content

Commit

Permalink
Fix compilation issue with Spark 3.2 and 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Apr 20, 2024
1 parent 40feb17 commit cc1905a
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,18 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde {
timeZoneId: Option[String],
dt: DataType,
childExpr: Option[Expr],
evalMode: EvalMode.Value): Option[Expr] = {
evalMode: String): Option[Expr] = {
val dataType = serializeDataType(dt)

if (childExpr.isDefined && dataType.isDefined) {
val castBuilder = ExprOuterClass.Cast.newBuilder()
castBuilder.setChild(childExpr.get)
castBuilder.setDatatype(dataType.get)
castBuilder.setEvalMode(evalMode)

val timeZone = timeZoneId.getOrElse("UTC")
castBuilder.setTimezone(timeZone)

castBuilder.setEvalMode(evalMode.toString)

Some(
ExprOuterClass.Expr
.newBuilder()
Expand All @@ -451,7 +450,14 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde {

case Cast(child, dt, timeZoneId, evalMode) =>
val childExpr = exprToProtoInternal(child, inputs)
castToProto(timeZoneId, dt, childExpr, evalMode)
val evalModeStr = if (evalMode.isInstanceOf[Boolean]) {
// Spark 3.2 & 3.3 has ansiEnabled boolean
if (evalMode.asInstanceOf[Boolean]) "ANSI" else "LEGACY"
} else {
// Spark 3.4+ has EvalMode enum with values LEGACY, ANSI, and TRY
evalMode.toString
}
castToProto(timeZoneId, dt, childExpr, evalModeStr)

case add @ Add(left, right, _) if supportedDataType(left.dataType) =>
val leftExpr = exprToProtoInternal(left, inputs)
Expand Down Expand Up @@ -1568,7 +1574,7 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde {
val childExpr = scalarExprToProto("coalesce", exprChildren: _*)
// TODO: Remove this once we have new DataFusion release which includes
// the fix: https://github.com/apache/arrow-datafusion/pull/9459
castToProto(None, a.dataType, childExpr, EvalMode.LEGACY)
castToProto(None, a.dataType, childExpr, "LEGACY")

// With Spark 3.4, CharVarcharCodegenUtils.readSidePadding gets called to pad spaces for
// char types. Use rpad to achieve the behavior.
Expand Down

0 comments on commit cc1905a

Please sign in to comment.