[
https://issues.apache.org/jira/browse/CALCITE-4085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17143475#comment-17143475
]
Danny Chen commented on CALCITE-4085:
-------------------------------------
Thanks [~dwysakowicz] for the discussion and fix ~
I'm a little confused what your request is, if you need a way to create
nullable record type with non-null fields, it seems adding another tool method
is enough, such as in the RelDataTypeFactory#Builder [1], the nullability of
whole record type configuration is missing ~
For expression "[A].[B]", if [A] is nullable then [A].[B] should also be
nullable, based on that, the code in [2] seems reasonable.
Can you share again in which case we *must* have non-nullable field for a
nullable record type ? From the previous discussion, it seems you want to do a
type inference promotion of POJO type. So you change the type factory
nullability propagation strategy. And in order to make the sql
validation/conversion nullability correct, you have to modify all kinds of
contexts (i.e. the validator, per-operators, the rex builder) ..
For a POJO
{code:java}
class User { int id, int age }
{code}
You want the int type to be nullable. But in the POJO code, you want to
translate the id to int instead of integer. In my point, the type inference of
current Calcite is very close to correct. What we should do is the QE (when we
translate the POJO, to do a promotion in the code instead) which seems more
feasible.
Personally i think such a modification is fragile and hard to maintain, you can
not prevent people to add new sql contexts(new syntax, new operators).
the fix in
* RexBuilder#makeFieldAccessInternal
* SqlValidatorImpl.DeriveTypeVisitor#visit(SqlIdentifier)
seems not necessary, because the nullability propagation is already done by the
type factory.
[1]
https://github.com/apache/calcite/blob/0769a8b31cbbeb5bca66ade30cf3710523da4aaa/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactory.java#L518
[2]
https://github.com/apache/calcite/blob/0769a8b31cbbeb5bca66ade30cf3710523da4aaa/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java#L338
> Improve nullability support for fields of structured type
> ---------------------------------------------------------
>
> Key: CALCITE-4085
> URL: https://issues.apache.org/jira/browse/CALCITE-4085
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Dawid Wysakowicz
> Assignee: Dawid Wysakowicz
> Priority: Major
> Time Spent: 10m
> Remaining Estimate: 0h
>
> As discussed in
> https://lists.apache.org/thread.html/r602ac95fff23dd1ef974fb396df7be061ab861384ec42f5c57ce0bc2%40%3Cdev.calcite.apache.org%3E
> I would like to change the way a type of a field of a record is derived at
> couple of locations. This helps frameworks such as Apache Flink to build
> support for nullable records with not null fields.
> I suggest to change:
> * SqlDotOperator#deriveType
> * SqlItemOperator#inferReturnType
> * AliasNamespace#validateImpl
> * RexBuilder#makeFieldAccessInternal
> * SqlValidatorImpl.DeriveTypeVisitor#visit(SqlIdentifier)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)