You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "silver-ymz (via GitHub)" <gi...@apache.org> on 2026/02/24 15:16:24 UTC

[I] `cardinality()` on an empty array incorrectly returns `NULL` instead of `0` [datafusion]

silver-ymz opened a new issue, #20526:
URL: https://github.com/apache/datafusion/issues/20526

   ### Describe the bug
   
   When executing a query to get the `cardinality()` of an explicitly casted empty array (e.g., `[]::int[]`), DataFusion returns `NULL`. 
   
   In standard SQL behavior across most database engines (such as PostgreSQL, DuckDB, and ClickHouse), the cardinality or length of an empty array is `0`. Returning `NULL` implies the array itself is null or unknown, which is incorrect for an explicitly defined empty array.
   
   
   ### To Reproduce
   
   Run the following query in the DataFusion CLI:
   
   ```sql
   ❯ select cardinality([]::int[]);
   +---------------------------+
   | cardinality(make_array()) |
   +---------------------------+
   | NULL                      |
   +---------------------------+
   1 row(s) fetched.
   
   ### Expected behavior
   
   +---------------------------+
   | cardinality(make_array()) |
   +---------------------------+
   | 0                         |
   +---------------------------+
   
   ### Additional context
   
   DataFusion version: DataFusion CLI v52.1.0


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [I] `cardinality()` on an empty array incorrectly returns `NULL` instead of `0` [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb closed issue #20526: `cardinality()` on an empty array incorrectly returns `NULL` instead of `0`
URL: https://github.com/apache/datafusion/issues/20526


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [I] `cardinality()` on an empty array incorrectly returns `NULL` instead of `0` [datafusion]

Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on issue #20526:
URL: https://github.com/apache/datafusion/issues/20526#issuecomment-3954174068

   This also seems a bit odd:
   
   ```
   > select cardinality(NULL);
   +-------------------+
   | cardinality(NULL) |
   +-------------------+
   | 0                 |
   +-------------------+
   1 row(s) fetched.
   Elapsed 0.082 seconds.
   
   > select cardinality(NULL::int[]);
   +-------------------+
   | cardinality(NULL) |
   +-------------------+
   | NULL              |
   +-------------------+
   1 row(s) fetched.
   Elapsed 0.007 seconds.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [I] `cardinality()` on an empty array incorrectly returns `NULL` instead of `0` [datafusion]

Posted by "neilconway (via GitHub)" <gi...@apache.org>.
neilconway commented on issue #20526:
URL: https://github.com/apache/datafusion/issues/20526#issuecomment-3953476911

   take


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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