You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Xurenhe (Jira)" <ji...@apache.org> on 2022/03/24 12:00:00 UTC

[jira] [Comment Edited] (CALCITE-5044) JDBC adapter generates integer literal in ORDER BY, which some dialects wrongly interpret as a reference to a field

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

Xurenhe edited comment on CALCITE-5044 at 3/24/22, 11:59 AM:
-------------------------------------------------------------

Hi [~julianhyde] 

I have finished the review.

I think we need one test case: numeric constant with direction info in the order-by.
I have integrated more cases into one test method.

Code is updated in my branch: [https://github.com/wojustme/calcite/commit/22d3b6c845152dd5270bad9974d7fa505e63dfe6|https://github.com/wojustme/calcite/commit/22d3b6c845152dd5270bad9974d7fa505e63dfe6.]

please take a time to review it. Thanks.

 


was (Author: wojustme):
Hi [~julianhyde] 

I have finished the review.

I think we need one test case: numeric constant with direction info in the order-by.
I have integrated more cases into one test method.

Code is updated in my branch: [https://github.com/wojustme/calcite/commit/22d3b6c845152dd5270bad9974d7fa505e63dfe6.]

please take a time to review it. Thanks.

 

> JDBC adapter generates integer literal in ORDER BY, which some dialects wrongly interpret as a reference to a field
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-5044
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5044
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Xurenhe
>            Assignee: Xurenhe
>            Priority: Major
>         Attachments: image-2022-03-17-21-45-22-988.png
>
>
> When there is a Sort RelNode that references an integer literal, the JDBC adapter converts this to a SQL ORDER BY clause that contains an integer literal as a sort key. Some dialects (most dialects, in fact) wrongly interpret as a reference to a field.
> There is ambiguous in the rel-to-sql's converter when meeting `order by constant `.
> Here is an example:
> {code:java}
> @Test void testOderByConstant() {
>   final Function<RelBuilder, RelNode> relFn = b -> b
>       .scan("EMP")
>       .project(b.literal(1), b.field(1), b.field(2))
>       .sort(RelCollations.of(ImmutableList.of(
>           new RelFieldCollation(0), new RelFieldCollation(1))))
>       .project(b.field(2), b.field(1))
>       .build();
>   final String expected = "";
>   relFn(relFn).ok(expected);
> } {code}
> Return sql:
> {code:java}
> SELECT "JOB", "ENAME"
> FROM "scott"."EMP"
> ORDER BY 1, "ENAME" {code}
> But, `ORDER BY 1` may mean 'sort by the first column in the select list'  because of SqlConformance#isSortByOrdinal.
> I keep this the same semantics, by apply the rule of `CoreRules#SORT_REMOVE_CONSTANT_KEYS`
> Should the rel_to_sql's converter support it natively?
> *CODE:* https://github.com/wojustme/calcite/blob/6ad04e85875d9202e592a78cca8db807c5bde362/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java#L1601



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