You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For this, I think there are 2 approaches. One is to fix upstream: make check_datatypes() ignore inner field nullability. Another is to fix in Comet: normalize inner nullability before calling array_except. Avoids upstream change but adds overhead.
I'd lean toward (1), but I'd like to confirm how others think @comphead
I tried to replace .equals_datatype to .contains which is more nullability friendly, however it would still doesn't work this scenario.
.contains ignores nullability if the primary datatype is nullable, but let data_type = args[0].data_type(); doesn't guarantee exactly this datatype would be nullable.
I feel we can tweak check_datatype and if incoming datatypes are lists then take first NULLABLE datatype instead of just first
@comphead could you share the Spark and Comet version you used to produce this error? I can't seem to reproduce it with a local script running Spark 3.5.8 and the Comet local build based on latest of comet.
I'd like to take this. It still reproduces on a recent main (1c25b492) with allowIncompatible on: removing the ignore on the literal query in array_except.sql fails with array_except received incompatible types: List(Int32), List(non-null Int32).
The plan is to make both sides agree on a nullable element in the serde, reusing normalizeContainerNullability as suggested on #4237, and then re-enable that query. #5526 unifies nested element types for the set ops and leaves primitive elements alone, so I'll keep this to the list-level nullability and rebase onto it if it lands first.
I've analyzed the issue and identified the root cause:
Problem
The error occurs because DataFusion's array_except function receives arrays with different element nullability:
One array: List(Int32) (nullable elements)
Other array: List(non-null Int32) (non-nullable elements)
Root Cause
In CometArrayExcept.convert, we're passing the raw Spark expressions without normalizing the element type nullability. DataFusion is strict about type compatibility and rejects the mismatch.
Proposed Fix
Normalize element type nullability before calling the native function:
// In CometArrayExcept.convertvalleftType= expr.left.dataType.asInstanceOf[ArrayType]
valrightType= expr.right.dataType.asInstanceOf[ArrayType]
// Cast to nullable if needed to ensure compatibilityvalnormalizedLeft=if (!leftType.containsNull) {
Cast(expr.left, ArrayType(leftType.elementType, containsNull =true))
} else {
expr.left
}
valnormalizedRight=if (!rightType.containsNull) {
Cast(expr.right, ArrayType(rightType.elementType, containsNull =true))
} else {
expr.right
}
This ensures both arrays have the same element nullability before passing to DataFusion.
Testing
The fix should enable the ignored test case in array_except.sql:
Activity
n0r0shi commentedon Mar 7, 2026
For this, I think there are 2 approaches. One is to fix upstream: make
check_datatypes()ignore inner field nullability. Another is to fix in Comet: normalize innernullabilitybefore callingarray_except. Avoids upstream change but adds overhead.I'd lean toward (1), but I'd like to confirm how others think @comphead
comphead commentedon Mar 7, 2026
I tried to replace
.equals_datatypeto.containswhich is more nullability friendly, however it would still doesn't work this scenario..containsignores nullability if the primary datatype is nullable, butlet data_type = args[0].data_type();doesn't guarantee exactly this datatype would be nullable.I feel we can tweak
check_datatypeand if incoming datatypes are lists then take first NULLABLE datatype instead of just firstyuboxx commentedon May 7, 2026
@comphead could you share the Spark and Comet version you used to produce this error? I can't seem to reproduce it with a local script running Spark 3.5.8 and the Comet local build based on latest of comet.
comphead commentedon May 7, 2026
Thanks @yuboxx
I think you can reproduce by running src/test/resources/sql-tests/expressions/array/array_except.sql
stantheman0128 commentedon Sep 25, 2026
I'd like to take this. It still reproduces on a recent main (
1c25b492) withallowIncompatibleon: removing the ignore on the literal query inarray_except.sqlfails witharray_except received incompatible types: List(Int32), List(non-null Int32).The plan is to make both sides agree on a nullable element in the serde, reusing
normalizeContainerNullabilityas suggested on #4237, and then re-enable that query. #5526 unifies nested element types for the set ops and leaves primitive elements alone, so I'll keep this to the list-level nullability and rebase onto it if it lands first.contentforge-press commentedon Oct 2, 2026
Working on a fix for this! 🔧
I've analyzed the issue and identified the root cause:
Problem
The error occurs because DataFusion's
array_exceptfunction receives arrays with different element nullability:List(Int32)(nullable elements)List(non-null Int32)(non-nullable elements)Root Cause
In
CometArrayExcept.convert, we're passing the raw Spark expressions without normalizing the element type nullability. DataFusion is strict about type compatibility and rejects the mismatch.Proposed Fix
Normalize element type nullability before calling the native function:
This ensures both arrays have the same element nullability before passing to DataFusion.
Testing
The fix should enable the ignored test case in
array_except.sql:Next Steps
spark/src/main/scala/org/apache/comet/serde/arrays.scalaI'll submit a PR shortly. Working on it now!
cc: @andygrove @parthchandra @kazuyukitanimura
Fix nested array regression in array_except type normalization