feat: add base64 expression#4159
Open
andygrove wants to merge 1 commit intoapache:mainfrom
Open
Conversation
Implement Spark base64 in Comet. Output is unchunked padded base64; the expression is marked Compatible only when chunkBase64=false (Spark 3.5+ with `spark.sql.chunkBase64String.enabled=false`), and Incompatible otherwise so users opt in via `spark.comet.expr.allowIncompatible=true`. Closes apache#419
8df5a35 to
0f00230
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #419.
Rationale for this change
base64is a commonly used Spark string function. The expression coverage doc previously listed it as unsupported, so queries using it fell back to Spark.What changes are included in this PR?
spark_base64innative/spark-expr/src/string_funcs/base64.rsthat produces padded RFC 4648 base64 (no line breaks). Wired intocreate_comet_physical_funas"base64".spark/src/main/scala/org/apache/comet/serde/strings.scala:CometBase64for the Spark 3.4 case-class shape (Base64(child)). Always returnsIncompatiblebecause Spark 3.4 always chunks the output.CometBase64StaticInvokefor the Spark 3.5+ shape, whereBase64isRuntimeReplaceableand arrives asStaticInvoke(classOf[Base64], "encode", Seq(child, Literal(chunkBase64))). ReturnsCompatibleonly when the literalchunkBase64isfalse; otherwiseIncompatible.CometStaticInvokenow delegatesgetSupportLevelandgetExprConfigNameto its inner handler so theBase64-specific support level and config name (spark.comet.expr.Base64.allowIncompatible) take effect through the StaticInvoke dispatch path.spark/src/test/resources/sql-tests/expressions/string/base64.sqlcovers binary and string columns, literals, NULL, empty input, the SPARK-47307 58-byte chunking boundary, a 200-byte input, and the full 0x00..0xFF byte range.spark/src/test/resources/sql-tests/expressions/string/base64_chunked_fallback.sqlasserts that on Spark 3.5+ Comet falls back to Spark whenspark.sql.chunkBase64String.enabled=trueand incompatible expressions have not been opted in.docs/source/contributor-guide/spark_expressions_support.mdupdated with audit annotations for Spark 3.4.3 / 3.5.8 / 4.0.1.This change was scaffolded with the
implement-comet-expressionClaude skill and the resulting implementation was reviewed with theaudit-comet-expressionskill.How are these changes tested?
spark/src/test/resources/sql-tests/expressions/string/cover both the compatible (chunkBase64String.enabled=false) and the fallback (chunkBase64String.enabled=true) paths.native/spark-expr/src/string_funcs/base64.rscover array, scalar, NULL, and padding cases.make format,cargo clippy --all-targets --workspace -- -D warnings, and the targetedCometSqlFileTestSuiteruns all pass locally.