[
https://issues.apache.org/jira/browse/CALCITE-6764?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17913128#comment-17913128
]
Mihai Budiu commented on CALCITE-6764:
--------------------------------------
Regarding the standard, I actually reverse engineered the Calcite
implementation and I assumed that it attempts to follow the standard. By
looking at many other databases, I now doubt it.
The main problem that this issue is addressing is the use of ROW types that may
be nullable. ROW types can appear anywhere in a type expression, including in
table columns, nested ROWs, or as elements of ARRAY or values in MAPs. The
current Calcite implementation does *not* support nullable ROW types.
Attempting to make a ROW type nullable actually sets all of the row fields to
"nullable" and keeps the ROW type non-nullable. I think this is a mistake,
which confuses the type with some implementation constraints. (This is enforced
in the type factory, which is the wrong place to do this kind of enforcement).
So the PR fixes this by (1) enhancing the type factory to allow creating
nullable ROW types, and (2) changing some typing rules, so that a field
reference in a nullable ROW is always nullable, even if the original ROW field
was not nullable.
> Field access from a nullable ROW should be nullable
> ---------------------------------------------------
>
> Key: CALCITE-6764
> URL: https://issues.apache.org/jira/browse/CALCITE-6764
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.38.0
> Reporter: Mihai Budiu
> Assignee: Mihai Budiu
> Priority: Minor
> Labels: pull-request-available
> Fix For: 1.39.0
>
>
> Consider the following SQL:
> {code:sql}
> CREATE TABLE T(p MAP<VARCHAR, ROW(k VARCHAR, v VARCHAR)>);
> SELECT p['a'].k FROM T;
> {code}
> The MAP values are ROW values, which can be null.
> The type of p['a'] is nullable, so p['a'].k should also be nullable.
> The validator will crash while validating this query with the following error:
> {code}
> java.lang.RuntimeException: java.lang.AssertionError: Conversion to
> relational algebra failed to preserve datatypes:
> validated type:
> RecordType(VARCHAR EXPR$0) NOT NULL
> converted type:
> RecordType(VARCHAR NOT NULL EXPR$0) NOT NULL
> rel:
> LogicalProject(EXPR$0=[ITEM($0, 'a').k])
> LogicalTableScan(table=[[schema, t]])
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)