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

Julian Hyde commented on CALCITE-5701:
--------------------------------------

I know there are limitations with {{{}ROW{}}}. But that doesn't mean that 
{{named_struct}} should create something that looks like {{MAP}} (whose fields 
are only known at run time). I think it should create a {{{}STRUCT{}}}, which 
is similar to {{ROW}} except that its fields are named. 

(Related cases CALCITE-4436 and CALCITE-4354 seem to be using java reflection. 
But I don't think we should continue to push in that direction.)

Other dialects of SQL have better support for {{{}STRUCT{}}}. For example, 
GoogleSQL (BigQuery) has {{SELECT AS STRUCT}} (see CALCITE-2251), and [struct 
literals|https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#struct_literals]
 (e.g. {{{}STRUCT(1 AS foo, 'abc' AS bar){}}}). I would like to add that to 
Calcite, implemented by a {{java.util.List}} whose length/fields are fixed at 
compile time.

> 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