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

Mihai Budiu commented on CALCITE-6275:
--------------------------------------

The Calcite IR can actually represent all these types unambiguously.

Are you implying that array and map elements can always be null? That's a 
possible interpretation. Ideally the interpretation should be dialect-specific.

The array constructor may infer array types that have non-nullable elements; 
e.g.: ARRAY[1,2] has type INTEGER NOT NULL ARRAY. If all arrays have nullable 
elements, the inferred type should instead be INTEGER ARRAY.

Every language that has an Option type 
[https://en.wikipedia.org/wiki/Option_type] has done this right, including 
Standard ML, maybe more than 30 years ago.

It does look messy. I will think about this a bit more and decide whether this 
issue should be closed as invalid or not.

> Parser for data types ignores element nullability in collections
> ----------------------------------------------------------------
>
>                 Key: CALCITE-6275
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6275
>             Project: Calcite
>          Issue Type: Bug
>          Components: core, server
>    Affects Versions: 1.36.0
>            Reporter: Mihai Budiu
>            Priority: Major
>              Labels: pull-request-available
>
> The parser (Parser.jj) has this production rule for DataType:
> {code}
> // Type name with optional scale and precision.
> SqlDataTypeSpec DataType() :
> {
>     SqlTypeNameSpec typeName;
>     final Span s;
> }
> {
>     typeName = TypeName() {
>         s = Span.of(typeName.getParserPos());
>     }
>     (
>         typeName = CollectionsTypeName(typeName)
>     )*
>     {
>         return new SqlDataTypeSpec(typeName, 
> s.add(typeName.getParserPos()).pos());
>     }
> }
> {code}
> Note that there is no way to specify the nullability for the elements of a 
> collection, they are always assumed to be non-null. This is most pertinent 
> for the server component, where in DDL one cannot specify a table column of 
> type INTEGER ARRAY; one always gets an INTEGER NOT NULL ARRAY instead.
> But note that SqlCollectionTypeNameSpec cannot even represent the nullability 
> of the elements' type, it takes a SqlTypeNameSpec instead of a 
> SqlDataTypeSpec.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to