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

Mihai Budiu commented on CALCITE-7658:
--------------------------------------

The type inferred for ARRAY() is UNKNOWN ARRAY. There are several places where 
the UNKNOWN type is handled inconsistently in the compiler. For example, the 
type checker allows casts from UNKNOWN to INT, but not from UNKNOWN to INT 
ARRAY.

UNKNOWN should fundamentally be treated like an unbound type variable which can 
be unified with other types. For example, concatenating ARRAY() with ARRAY(1) 
should infer the type INT ARRAY for the first array, by unifying UNKNOWN ARRAY 
with INT ARRAY and "assigning" the value "INT" to "UNKNOWN" type variable in 
this place. There are no type variables in Calcite, but we can think of this 
behavior as the "spec" that UNKNOWN has to implement. (Introducing a concrete 
representation for type variables would be major surgery.)

The fix will involve improving the handling of the UNKNOWN type in several 
places.

leastRestrictive() can be thought as a form of unification, where UNKNOWN does 
not constrain the final result.

(Note that UNKNOWN can be NULLABLE, so it does carry some constraints).

> Type checker rejects CAST(ARRAY() AS ROW(x INT) ARRAY)
> ------------------------------------------------------
>
>                 Key: CALCITE-7658
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7658
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.42.0
>            Reporter: Mihai Budiu
>            Assignee: Mihai Budiu
>            Priority: Minor
>
> The typechecker accepts casts of empty arrays to other array types, such as 
> INT ARRAY, but rejects casts to ARRAYs whose elements are ROW-typed.



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

Reply via email to