diff --git a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala index 7238990ad..8c7ef3d11 100644 --- a/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala +++ b/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala @@ -2073,6 +2073,13 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim scalarExprToProtoWithReturnType(algorithm, StringType, childExpr) } + case Base64(child) => + val castExpr = Cast(child, StringType) + val childExpr = exprToProtoInternal(castExpr, inputs) + val encoding = exprToProtoInternal(Literal("base64"), inputs) + val optExpr = scalarExprToProto("encode", childExpr, encoding) + optExprWithInfo(optExpr, expr, castExpr) + case _ => withInfo(expr, s"${expr.prettyName} is not supported", expr.children: _*) None diff --git a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala index 28027c5cb..58b372c2b 100644 --- a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala +++ b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala @@ -1467,4 +1467,22 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper { } } + test("base64") { + val table = "test" + withTable(table) { + sql(s"create table $table(col string) using parquet") + sql(s"""INSERT INTO $table VALUES + |('537061726B2053514C'), + |('737472696E67'), + |('\\0'), + |(''), + |('###'), + |('G123'), + |('hello'), + |('A1B'), + |('0A1B')""".stripMargin) + + checkSparkAnswerAndOperator(s"SELECT base64(col) FROM $table") + } + } }