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

Ruben Q L commented on CALCITE-4999:
------------------------------------

If I an not mistaken, the current Calcite implementation seems more powerful 
(or more flexible) that e.g. the BigQuery one, because the ARRAY subquery 
allows multiple columns.
For instance a single column ARRAY:
{code:sql}
SELECT r.r_name, ARRAY(
  SELECT n.n_name FROM nation n WHERE n.n_regionkey = r.r_regionkey
)
FROM region r ORDER BY r.r_name
{code}
Returns a record type with one field for the ARRAY subquery (which seemed fine 
so far, but it could potentially be a scalar: the point of this discussion).

But it also supports the case of a multi-column ARRAY:
{code:sql}
SELECT r.r_name, ARRAY(
  SELECT n.n_nationkey, n.n_name FROM nation n WHERE n.n_regionkey = 
r.r_regionkey
)
FROM region r ORDER BY r.r_name
{code}
It returns a record type with two fields for the ARRAY subquery (which is 
perfectly fine).

If we changed the first case to return a scalar, wouldn't it be a misalignment 
compared to the second? (not sure, just raising the question)

> `least restrictive` type inference does not work when one operand is scalar 
> and another is row with one field
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4999
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4999
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Dmitry Sysolyatin
>            Assignee: Dmitry Sysolyatin
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> I faced with a issue that the following query:
> {code:java}
> SELECT ARRAY_CONCAT(ARRAY['1', '2'], array(select 'toast.' || x from 
> unnest(ARRAY['1','2']) x)) {code}
> didn't work, because of:
> {code:java}
> java.lang.IllegalArgumentException: Cannot infer return type for 
> ARRAY_CONCAT; operand types: [CHAR(1) ARRAY, RecordType(CHAR(7) EXPR$0) 
> ARRAY]{code}
> `least restrictive` type inference does not work when one operand is scalar 
> and another is row with one field



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to