[
https://issues.apache.org/jira/browse/CALCITE-6680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17896692#comment-17896692
]
Chris Dennis commented on CALCITE-6680:
---------------------------------------
That seems to fix things for my usecase:
{code:sql}
!use default
!set outputformat mysql
SELECT * FROM "complex";
+-----+--------------+------+------------------------+
| KEY | list | long | map |
+-----+--------------+------+------------------------+
| 0 | | 5 | |
| 1 | [] | 4 | |
| 2 | [0] | 3 | {} |
| 3 | [0, 1] | 2 | {zero=0} |
| 4 | [0, 1, 2] | 1 | {zero=0, one=1} |
| 5 | [0, 1, 2, 3] | 0 | {zero=0, one=1, two=2} |
+-----+--------------+------+------------------------+
(6 rows)
!ok
SELECT * FROM "complex" WHERE "list" IS EMPTY;
+-----+------+------+-----+
| KEY | list | long | map |
+-----+------+------+-----+
| 1 | [] | 4 | |
+-----+------+------+-----+
(1 row)
!ok
SELECT * FROM "complex" WHERE "map" IS EMPTY;
+-----+------+------+-----+
| KEY | list | long | map |
+-----+------+------+-----+
| 2 | [0] | 3 | {} |
+-----+------+------+-----+
(1 row)
!ok
{code}
I looked through the other methods defined as {{NullPolicy.NONE}} and
identified a bunch more suspicious calls. I created a PR against your fix
branch showing the changes I think are correct:
https://github.com/mihaibudiu/calcite/pull/1
> RexImpTable erroneously declares NullPolicy.NONE for IS_EMPTY
> -------------------------------------------------------------
>
> Key: CALCITE-6680
> URL: https://issues.apache.org/jira/browse/CALCITE-6680
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Chris Dennis
> Assignee: Mihai Budiu
> Priority: Major
> Labels: pull-request-available
> Attachments: is-empty-nullable.patch
>
>
> RexImpTable implements {{IS EMPTY}} and {{IS NOT EMPTY}} using
> {{Collections.isEmpty()}} but declares them as {{NullPolicy.NONE}}. ThisĀ
> causes nullable array and map columns to throw NPE at execution time when
> hitting null values. I strongly suspect that other collection operators are
> similarly misclassified and would run in to issues is used against nullable
> types.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)