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

Guillaume Massé commented on CALCITE-5701:
------------------------------------------

[~julianhyde] That was my initial implementation. (backing with an `Object[]` 
at runtime). However, if you look at the `item` operator, it needs to have 
runtime information about the fields available:

[https://github.com/apache/calcite/blob/d1a12bb6f4d4f617234dfbc32cb0813c473b0029/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java#L4482.]

 

Also, it's possible in SQL to name fields of a row value constructor, but I 
don't think it's possible to name nested structures:

[https://github.com/apache/calcite/blob/1b11d99e65d03a15ae4b25c47250b6918ce9aa10/core/src/test/resources/sql/struct.iq|https://github.com/apache/calcite/blob/1b11d99e65d03a15ae4b25c47250b6918ce9aa10/core/src/test/resources/sql/struct.iq#L36-L39]
{code:java}
select * from (values (1, row(1)) as v(x, s)) -- ok

select * from (values (1, row(1, 2)) as v(x, row(x, z))) -- invalid{code}
 

 

> Add NAMED_STRUCT function (enabled in Spark library)
> ----------------------------------------------------
>
>                 Key: CALCITE-5701
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5701
>             Project: Calcite
>          Issue Type: New Feature
>          Components: core
>            Reporter: Guillaume Massé
>            Priority: Minor
>              Labels: pull-request-available
>
> [https://spark.apache.org/docs/3.4.0/api/sql/index.html#named_struct]
>  
> {code:java}
> spark.sql("""select named_struct("a", 1, "b", 2)""")
> res4: org.apache.spark.sql.DataFrame = [named_struct(a, 1, b, 2): struct<a: 
> int, b: int>]
> Calcite:
> SELECT named_struct('a', 1, 'b", 2);
> type: row(a int not null, b int not null){code}
>  
> It's also possible to be nested:
> {code:java}
> spark.sql("""select named_struct("a", 1, "b", named_struct("c", 2))""")
> res5: org.apache.spark.sql.DataFrame = [named_struct(a, 1, b, named_struct(c, 
> 2)): struct<a: int, b: struct<c: int>>] {code}
> {code:java}
> Calcite:
> SELECT named_struct('a', 1, 'b', named_struct('c', 2));
> type: row(a int not null, b row(c int not null) not null){code}



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

Reply via email to