You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Guillaume Massé (Jira)" <ji...@apache.org> on 2023/05/18 16:47:00 UTC

[jira] [Comment Edited] (CALCITE-5701) Add NAMED_STRUCT function (enabled in Spark library)

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

Guillaume Massé edited comment on CALCITE-5701 at 5/18/23 4:46 PM:
-------------------------------------------------------------------

Spark test types at runtime:

[https://github.com/apache/spark/blob/c8e85eab3fca0e4e5f4bdf9d1d6d1702ecf3fd07/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala#L457-L482]

 
{code:java}
 
 spark.sql("""select named_struct(concat("a", "b"), 1) as ns""")
res2: org.apache.spark.sql.DataFrame = [ns: struct<ab: int>]
{code}
 

They accept constant folding String. I think we should simplify by only accepting String literal for now.


was (Author: masseguillaume):
Spark test types at runtime:

[https://github.com/apache/spark/blob/c8e85eab3fca0e4e5f4bdf9d1d6d1702ecf3fd07/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala#L457-L482]

 
{code:java}
 
 spark.sql("""select named_struct(concat_ws("a", "b", ""), 1)""")
res2: org.apache.spark.sql.DataFrame = [named_struct(concat_ws(a, b, ), 1): struct<ba: int>]
{code}
 

They accept constant folding String. I think we should simplify by only accepting String literal for now.

> 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
>
> [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)