You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by ag...@apache.org on 2026/06/03 15:19:51 UTC

(datafusion-comet) branch main updated: fix: array_size returns -1 instead of null for null input (#4578)

This is an automated email from the ASF dual-hosted git repository.

andygrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion-comet.git


The following commit(s) were added to refs/heads/main by this push:
     new 755dcd29f1 fix: array_size returns -1 instead of null for null input (#4578)
755dcd29f1 is described below

commit 755dcd29f1ff4fd6e84c7d33eae645c7dffc0d8e
Author: Andy Grove <ag...@apache.org>
AuthorDate: Wed Jun 3 09:19:45 2026 -0600

    fix: array_size returns -1 instead of null for null input (#4578)
---
 .../expression-audits/collection_funcs.md              |  2 +-
 docs/source/user-guide/latest/expressions.md           | 14 +++++++-------
 .../src/main/scala/org/apache/comet/serde/arrays.scala |  2 +-
 .../org/apache/comet/CometArrayExpressionSuite.scala   | 18 ++++++++++++++++++
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/docs/source/contributor-guide/expression-audits/collection_funcs.md b/docs/source/contributor-guide/expression-audits/collection_funcs.md
index 2499d9572f..a2dd7bd511 100644
--- a/docs/source/contributor-guide/expression-audits/collection_funcs.md
+++ b/docs/source/contributor-guide/expression-audits/collection_funcs.md
@@ -23,7 +23,7 @@
 
 ## array_size
 
-- Native via `size`; returns -1 instead of NULL for NULL input (https://github.com/apache/datafusion-comet/issues/4560).
+- Native via `size`. `array_size` lowers to `Size(child, legacySizeOfNull = false)`, so it returns NULL for NULL input. `CometSize` reads the per-expression `legacySizeOfNull` flag.
 
 ## concat
 
diff --git a/docs/source/user-guide/latest/expressions.md b/docs/source/user-guide/latest/expressions.md
index 217d06936a..05db6fe6a3 100644
--- a/docs/source/user-guide/latest/expressions.md
+++ b/docs/source/user-guide/latest/expressions.md
@@ -180,13 +180,13 @@ The tables below list every Spark built-in expression with its current status.
 
 ## collection_funcs
 
-| Function      | Status | Notes                                                                                                       |
-| ------------- | ------ | ----------------------------------------------------------------------------------------------------------- |
-| `array_size`  | ⚠️     | Returns -1 instead of NULL for NULL input ([#4560](https://github.com/apache/datafusion-comet/issues/4560)) |
-| `cardinality` | ✅     | MapType input falls back                                                                                    |
-| `concat`      | ✅     | Binary/array children fall back                                                                             |
-| `reverse`     | ✅     | Binary-element arrays fall back (Incompatible) ([details](compatibility/expressions/array.md))              |
-| `size`        | ✅     | MapType input falls back                                                                                    |
+| Function      | Status | Notes                                                                                          |
+| ------------- | ------ | ---------------------------------------------------------------------------------------------- |
+| `array_size`  | ✅     |                                                                                                |
+| `cardinality` | ✅     | MapType input falls back                                                                       |
+| `concat`      | ✅     | Binary/array children fall back                                                                |
+| `reverse`     | ✅     | Binary-element arrays fall back (Incompatible) ([details](compatibility/expressions/array.md)) |
+| `size`        | ✅     | MapType input falls back                                                                       |
 
 ---
 
diff --git a/spark/src/main/scala/org/apache/comet/serde/arrays.scala b/spark/src/main/scala/org/apache/comet/serde/arrays.scala
index b3ea8d7c4f..2f89b0e2e3 100644
--- a/spark/src/main/scala/org/apache/comet/serde/arrays.scala
+++ b/spark/src/main/scala/org/apache/comet/serde/arrays.scala
@@ -688,7 +688,7 @@ object CometSize extends CometExpressionSerde[Size] {
     for {
       isNotNullExprProto <- createIsNotNullExprProto(expr, inputs, binding)
       sizeScalarExprProto <- scalarFunctionExprToProto("size", arrayExprProto)
-      emptyLiteralExprProto <- createLiteralExprProto(SQLConf.get.legacySizeOfNull)
+      emptyLiteralExprProto <- createLiteralExprProto(expr.legacySizeOfNull)
     } yield {
       val caseWhenExpr = ExprOuterClass.CaseWhen
         .newBuilder()
diff --git a/spark/src/test/scala/org/apache/comet/CometArrayExpressionSuite.scala b/spark/src/test/scala/org/apache/comet/CometArrayExpressionSuite.scala
index 081e99fc68..1c83a5b03f 100644
--- a/spark/src/test/scala/org/apache/comet/CometArrayExpressionSuite.scala
+++ b/spark/src/test/scala/org/apache/comet/CometArrayExpressionSuite.scala
@@ -1008,6 +1008,24 @@ class CometArrayExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelp
     }
   }
 
+  // https://github.com/apache/datafusion-comet/issues/4560
+  test("array_size returns null for null input") {
+    val table = "t1"
+    withTable(table) {
+      sql(s"create table $table(col array<int>) using parquet")
+      sql(s"insert into $table values(array(1, 2, 3)), (array()), (null)")
+      // array_size lowers to Size(child, legacySizeOfNull = false), so it must return null
+      // for a null input regardless of the legacySizeOfNull conf.
+      Seq("false", "true").foreach { legacy =>
+        withSQLConf(
+          SQLConf.LEGACY_SIZE_OF_NULL.key -> legacy,
+          SQLConf.ANSI_ENABLED.key -> "false") {
+          checkSparkAnswerAndOperator(sql(s"select array_size(col) from $table"))
+        }
+      }
+    }
+  }
+
   // https://github.com/apache/datafusion-comet/issues/3375
   test("(ansi) array access out of bounds - GetArrayItem") {
     withSQLConf(


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org