[
https://issues.apache.org/jira/browse/CALCITE-2464?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16585687#comment-16585687
]
Stamatis Zampetakis commented on CALCITE-2464:
----------------------------------------------
The following extracts are taken by a draft of SQL:2011 (IWD 9075-1:2011 and
IWD 9075-2:2011).
*Part I: 4.5.3*
_Every site has a nullability characteristic, which indicates whether it may
contain the null value (is possibly_
_nullable) or not (is known not nullable). Only the columns of base tables may
be constrained to be known not_
_nullable, but columns derived from such columns may inherit the
characteristic._
*Part II: 4.13*
_The terms column, field, and attribute refer to structural components of
tables, row types, and structured types,_
_respectively, in_ analogous _fashion._
_A column C is described by a column descriptor. A column descriptor includes:_
* _The name of the column._
* _Whether the name of the column is an implementation-dependent name._
* _If the column is based on a domain, then the name of that domain;
otherwise, the data type descriptor of_
_the declared type of C._
* _The value of <default option>, if any, of C._
* _The nullability characteristic of C._
_An attribute A is described by an attribute descriptor. An attribute
descriptor includes:_
* _The name of the attribute._
* _The data type descriptor of the declared type of A._
* _The ordinal position of A within the structured type that contains it._
* _The value of the implicit or explicit <attribute default> of A._
* _The name of the structured type defined by the <user-defined type
definition> that defines A._
Clearly, the current behavior of always returning not nullable for structured
types is wrong. As denoted above, nullability can be specified *only for
columns* of base tables. If the declared type of a column C is a structured
type then nullability can be specified only for the structured type as a whole
and not for the individual attributes. The attributes of a structured type
(which may also be structured types) are always nullable. Attributes of
structured types are accessed using the implicit SQL invoked methods described
below.
*Part II: 11.51*
_8)g)For each <attribute definition> ATD contained in <member list>, let AN be
the <attribute name>_
_contained in ATD and let DT be the <data type> contained in ATD. The following
<original method_
_specification>s are implicit:_
{code:java}
METHOD AN ( )
RETURNS DT
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
RETURNS NULL ON NULL INPUT{code}
_This is the original method specification of the observer function of
attribute AN._
{code:java}
METHOD AN ( ATTR DT )
RETURNS UDTN
SELF AS RESULT
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
CALLED ON NULL INPUT{code}
_This is the original method specification of the mutator function of attribute
AN._
Looking at the definition of the mutator function of attribute AN (CALLED ON
NULL INPUT) it is evident that attributes are nullable.
> Struct types are always not nullable
> ------------------------------------
>
> 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
> Assignee: Julian Hyde
> Priority: Major
>
> 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
(v7.6.3#76005)