[
https://issues.apache.org/jira/browse/CALCITE-6764?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Mihai Budiu reopened CALCITE-6764:
----------------------------------
This problem exists also for tables that contain nested ROW records that can be
nullable.
(I think that standard SQL really does not allow nullable ROW values in a
table, so perhaps this problem does not arise for normal table declarations.
But if a ROW type *is* allowed to be nullable, the problem exists. And a schema
can declare a field with a ROW type as being nullable).
Consider this program:
{code:sql}
CREATE TABLE T(p ROW(k VARCHAR, v VARCHAR) NULL);
CREATE VIEW V AS SELECT t.p.k FROM T;
{code}
Because p is nullable, t.p.k should also be nullable. However, the validator
infers the type as non-nullable.
The problem is in DeriveTypeVisitor.visit(SqlIdentifier i), which uses the
field type. If the ROW containing the field is nullable, the field type should
also be 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)