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

yanjing.wang commented on CALCITE-4987:
---------------------------------------

Thanks Julian for your work.
{quote}Are there any dialects that allow ordinal but not alias in the ORDER BY? 
Or vice versa? If so, how does this change affect them?
{quote}
Maybe, but this change rewrites ORDER BY clause in a way that depends on 
dialect's conformance, So even if there's a one, the change will rewrite with 
the corresponding ordinal or alias. The rule is 

1. if the dialect conformance support sort by ordinal, use ORDER BY ordinal.
2. else if the dialect conformance support sort by alias but not ordinal, use 
ORDER BY alias.
3. else use ORDER BY filed. 

 
{quote}Does the SqlDelegatingConformance constructor really need to be public?
{quote}
I'm not sure, I found it can be used in SqlToRelConverterTest and just as a 
delegate, so I think it could be also used in RelToSqlConverterTest.

 
{quote}Does this issue relate to CALCITE-3440?
{quote}
Yes, this change will cover that case.

 
{quote}Can you make sure that the new algorithm is as well documented as the 
old one.
{quote}
It's really my mistake, I will refine it soon.

 

And is this change acceptable for solving ORDER BY clause?

> JDBC adapter generates incorrect query when ORDER BY alias collides with 
> field in SELECT ITEM
> ---------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-4987
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4987
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.29.0
>         Environment: jdk8
>            Reporter: yanjing.wang
>            Assignee: yanjing.wang
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.30.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> I reproduce with the following query.
>  
> {code:java}
> SELECT sum(shelf_width) as shelf_width FROM product ORDER BY shelf_width{code}
> you must have noticed that the shelf_width alias is same with field 
> 'shelf_width' in sum.
> I expected the query hasn't changed when I test in RelToSqlConverterTest. But 
> I get unexpected query is 
> {code:java}
> SELECT sum(shelf_width) as shelf_width FROM product ORDER BY sum(shelf_width) 
>  {code}
>  the unexpected query is not valid in the dialect which support order by 
> alias conformance.
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to