[ 
https://issues.apache.org/jira/browse/CALCITE-2464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17140353#comment-17140353
 ] 

Danny Chen commented on CALCITE-2464:
-------------------------------------

> If someone declares a column r ROW(x INT NOT NULL, y INT NOT NULL) should we 
> implicitly add NOT NULL to r?

> if someone declares r ROW(x INT, y INT) NOT NULL should be implicitly add NOT 
> NULL to x and y?

If both answers are no, it seems that the member nullability has no 
relationship with the record nullability, thus, the fix in [1]
seems not right, because when we create with nullability true, all it's nested 
members would also be nullable, assumes there is a Java class User

{code:java}
class User {
  int id,
  int age
}
{code}

If we assumes that User is nullable, then when create type for User, id and age 
would also become nullable, that means we should both use the boxed type to 
represent, that is a regression, i think.

The actually affect for type inference is the DOT and ITEM operators, now we 
follow the nullability for members of the record type [2], that means, all the 
nested items has the same nullability with the record.

[1] 
https://github.com/apache/calcite/blob/fa8349069d141d3c75bafa06d5fb8800711ec8d6/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java#L338
[2] 
https://github.com/apache/calcite/blob/fa8349069d141d3c75bafa06d5fb8800711ec8d6/core/src/main/java/org/apache/calcite/sql/fun/SqlDotOperator.java#L180

> Allow to set nullability for columns of structured types
> --------------------------------------------------------
>
>                 Key: CALCITE-2464
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2464
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.17.0
>            Reporter: Stamatis Zampetakis
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.19.0
>
>          Time Spent: 3h 10m
>  Remaining Estimate: 0h
>
> Struct types are always not nullable. This can lead to bugs in many parts of 
> Calcite (e.g., expression simplification, optimization, code generation) that 
> are considering the nullability of a RelDataType. 
> The method 
> [isNullable|https://github.com/apache/calcite/blob/3c6b5ec759caadabb67f09d7a4963cc7d9386d0c/core/src/main/java/org/apache/calcite/rel/type/RelRecordType.java#L55]
>  in the RelRecordType, which is used to represent a structured type, always 
> returns false. The nullability of the RelRecordType should be a parameter in 
> the constructor as it is the case for various other RelDataTypes. 
> Additionally, the data type cache should also take into account the 
> nullability of the type in order to return a correct equivalent.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to