You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Xurenhe (Jira)" <ji...@apache.org> on 2022/03/15 11:06:00 UTC
[jira] [Created] (CALCITE-5044) OrderBy constant executing RelToSql ambiguously
Xurenhe created CALCITE-5044:
--------------------------------
Summary: OrderBy constant executing RelToSql ambiguously
Key: CALCITE-5044
URL: https://issues.apache.org/jira/browse/CALCITE-5044
Project: Calcite
Issue Type: Improvement
Reporter: Xurenhe
Assignee: Xurenhe
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 = "SELECT *\n"
+ "FROM \"scott\".\"EMP\"\n"
+ "WHERE \"COMM\" IS NULL OR \"COMM\" <> 1";
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?
--
This message was sent by Atlassian Jira
(v8.20.1#820001)