feat: support Spark expression slice#4149
Open
andygrove wants to merge 2 commits intoapache:mainfrom
Open
Conversation
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 #.
Rationale for this change
Add native support for Spark's
slice(array, start, length)expression so it runs on Comet instead of falling back to Spark.The
datafusion-sparkcrate already ships aSparkSlice, but it is not Spark-compatible: when a negativestartlies before the beginning of the array (e.g.slice([a], -2, 2)), it returns the first element instead of an empty array. We can upstream the fix later; for now this PR ships a Comet-local implementation.What changes are included in this PR?
native/spark-expr/src/array_funcs/array_slice.rs: newSparkArraySliceUDF (spark_array_slice) implementing Spark's slice semantics, including 1-based indexing, negative-start-from-end, error onstart = 0orlength < 0, and clamping length to the array end. Supports bothListandLargeListelement storage.native/spark-expr/src/comet_scalar_funcs.rs: register the new UDF.spark/src/main/scala/org/apache/comet/serde/arrays.scala:CometSliceserde casts the start/length args toLongand serialises a call tospark_array_slice, promisingcontainsNull = trueto match DataFusion's list nullability.spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala: registerSliceinarrayExpressions.How are these changes tested?
array_slice.rscovering positive / negative / zero / overflowing start, length 0, length past end, null inputs, empty arrays, and the error cases.spark/src/test/resources/sql-tests/expressions/array/slice.sqlcovering all-literal, column + literal, and column-only argument combinations across boolean, tinyint, smallint, int, bigint, float, double, decimal, date, timestamp, timestamp_ntz, string, and nested array element types, plus the negative-start-overflow case that exposed the upstream bug.