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

Yu Xu edited comment on CALCITE-6344 at 7/1/26 6:10 AM:
--------------------------------------------------------

I take it. root cause is: 
In SqlImplementor.java, the FIELD_ACCESS case handled a ROW/ITEM referenced 
expression by doing toSql(...).toString() and wrapping the result in new 
SqlIdentifier(expr.toString(), POS). 
This collapsed an entire ITEM expression (e.g. `books`[0]) into a single 
identifier name. At unparse time the target dialect quoted that whole string as 
one token and escaped the inner quote chars, producing the malformed  
```books[0]`` (ANSI) instead of"books"[0].


was (Author: JIRAUSER307770):
I take it.

> RelToSqlConverter invalid quotation for arrays and item operator(ansi dialect)
> ------------------------------------------------------------------------------
>
>                 Key: CALCITE-6344
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6344
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Anton Kovalevsky
>            Assignee: Yu Xu
>            Priority: Major
>
>  
> The context:
>  * Ansi Dialect
>  * having array of objects
>  * get an object by id and get property
> "books"[0]."title" turns into ```books``[0]`.`title`
> I added test case to  RelToSqlConverterTest to show what I met:
> {code:java}
> @Test
> void testSqlItemOperator2() {
>   new Sql(CalciteAssert.SchemaSpec.BOOKSTORE,
>       "SELECT MAP['title', \"books\"[0].\"title\"] from 
> \"bookstore\".\"authors\"",
>       AnsiSqlDialect.DEFAULT, SqlParser.Config.DEFAULT, ImmutableSet.of(),
>       UnaryOperator.identity(), null, ImmutableList.of())
>       .withSql("SELECT \"books\"[0].\"title\" from \"bookstore\".\"authors\"")
>       .schema(CalciteAssert.SchemaSpec.BOOKSTORE)
>       .ok("SELECT `books`[0].`title` FROM `bookstore`.`authors`");
> } {code}
>  
> {noformat}
> java.lang.AssertionError: 
> Expected: is "SELECT `books`[0].`title` FROM `bookstore`.`authors`"
>      but: was "SELECT ```books``[0]`.`title`\nFROM 
> `bookstore`.`authors`"{noformat}
>  
>  
>  



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

Reply via email to