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

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

I got a MVP working: 
[https://github.com/MasseGuillaume/calcite/commit/5b6614e36aacc5bf4e2cff247a8b317392a868b3]

I will add more test for error cases later this week. The crux was fixing 
`buildQuery2`, it converts the query into an expression that we cannot evaluate 
statically:
{code:java}
named_struct('k1', 1, 'k2', 2);

becomes

SELECT named_struct(p0, p1, p2, p3) FROM (VALUES ('k1', 1, 'k2', 2)) AS t(p0, 
p1, p2, p3)} {code}
This is why I add to the exception that percentile_cont, percentile_disc and 
convert follows. I'm wondering, If I would need to implement constant folding, 
how would I do it? If it's not to hard, I would be happy to include into this 
PR.
{code:java}
named_struct('k' || '1', 1) => named_struct('k1', 1) {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
>
> [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