Steven Talbot created CALCITE-3440:
--------------------------------------
Summary: RelToSqlConverter does not properly alias ambiguous ORDER
BY
Key: CALCITE-3440
URL: https://issues.apache.org/jira/browse/CALCITE-3440
Project: Calcite
Issue Type: Bug
Reporter: Steven Talbot
Best illustrated by a test that will fail if you put it in RelToSqlConverterTest
{code:java}
@Test public void testSelectQueryWithAmbiguousOrderByClause() {
String query = "select \"product_id\" as \"p\", \"net_weight\" as
\"product_id\" from \"product\" order by 1";
final String expected = "SELECT \"product_id\" AS \"p\", \"net_weight\" AS
\"product_id\"\n"
+ "FROM \"foodmart\".\"product\"\n"
+ "ORDER BY \"product\".\"product_id\"";
sql(query).ok(expected);
}{code}
Kind of a strange case, but basically you select a column, alias it, and order
by it. And then you select something else and alias it as that column.
RelToSqlConverter will ORDER BY just the column, unaliased ("product_id"),
which, at least on HyperSQL and MySQL where I tested, ends up ordering by the
aliased expression ("net_weight" as "product_id") vs the column (either
"product"."product_id" or "p" would work in this case).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)