[
https://issues.apache.org/jira/browse/CALCITE-5013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17501547#comment-17501547
]
Julian Hyde commented on CALCITE-5013:
--------------------------------------
There is a discussion on GitHub saying we should retain parentheses for
'clarity'. While I agree that is often good coding style, it is not realistic
when we are doing code generation. Code generation is automated, and driven by
a table of precedence values; manually overriding those rules for mere
aesthetics is foolish.
In code generation, we should include only parentheses that are necessary due
to precedence/association rules. We should not generate "a + (b * c)" because
"a + b * c" means the same thing. We should not generate "A union (B intersect
C)" because intersect has higher precedence and therefore "a union B intersect
C" means the same thing.
If you have a proposal to keep parentheses when (say) precedence levels are
similar we should consider it, but you should make that proposal in a separate
Jira case.
> Unparse SqlSetOperator should be retained parentheses when generating SQL
> for UNION ... LIMIT
> ----------------------------------------------------------------------------------------------
>
> Key: CALCITE-5013
> URL: https://issues.apache.org/jira/browse/CALCITE-5013
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Jiajun Xie
> Priority: Major
>
> - In standard SQL, the operand of union should not have limit or order by.So
> parse will fail in SqlParserTetest#testLimitUnion and
> SqlParserTetest#OrderUnion.
> - When users use parentheses, most engines allow it. See the
> discussion:CALCITE-1892.
> For simple example, parentheses control the scope of the limit
> {code:java}
> select "product_id" from "product"
> union all
> (select "product_id" from "product" limit 10){code}
> unparseBinarySyntax will miss parentheses, this change will affect semantics
> {code:java}
> SELECT \"product_id\" FROM \"foodmart\".\"product\"
> UNION ALL
> SELECT \"product_id\" FROM \"foodmart\".\"product\"
> FETCH NEXT 10 ROWS ONLY -- Affect semantics{code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)