fix: correct array_append return type and mark as Compatible#3795
Merged
comphead merged 4 commits intoapache:mainfrom Mar 27, 2026
Merged
fix: correct array_append return type and mark as Compatible#3795comphead merged 4 commits intoapache:mainfrom
comphead merged 4 commits intoapache:mainfrom
Conversation
…usion DataFusion's array_append always returns a list with nullable elements (nullable: true on the inner field), but Spark's ArrayAppend.dataType can have containsNull = false when the input array has non-null elements (e.g. array(1, 2, 3)). This caused a runtime assertion failure when the promised type did not match the actual DataFusion output type. Fixes the literal-only query: SELECT array_append(array(1, 2, 3), 4), ...
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
CometArrayAppendhad two bugs:Runtime assertion failure for literal arrays. DataFusion's
array_appendalways returns a list withnullable: trueon the element field. But when the input array has non-null elements (e.g.array(1, 2, 3)), Spark'sArrayAppend.dataTypereturnsArrayType(IntegerType, containsNull = false). The serde code was passingexpr.dataTypeas the "promised" return type to DataFusion, which caused a runtime assertion failure:Incorrect
Incompatibleclassification.CometArrayAppendwas markedIncompatible(None)with no explanation, which disabled it by default. TheCaseWhen(IsNotNull(arr), array_append(arr, elem), null)wrapper already handles the only genuine incompatibility (DataFusion'sarray_appenddoes not preserve null top-level array rows on its own), so the expression matches Spark's behavior fully.What changes are included in this PR?
arrays.scala: UseArrayType(elementType, containsNull = true)as the promised return type forarray_append, matching what DataFusion actually returns. ChangegetSupportLevelfromIncompatibletoCompatible.array_append.sql: Removespark.comet.expression.ArrayAppend.allowIncompatible=true(no longer needed now that it'sCompatible). Add comment explaining whyArrayInsert.allowIncompatible=trueis still needed on Spark 4.0 (wherearray_appendis aRuntimeReplaceablethat rewrites toarray_insert(-1)).expressions.md: MarkArrayAppendas Spark-compatible.How are these changes tested?
Existing SQL file test
expressions/array/array_append.sqlcovers column inputs, literal inputs, NULL arrays, and NULL elements across both dictionary and non-dictionary Parquet. The literal-only query that previously triggered the assertion failure now passes.