[
https://issues.apache.org/jira/browse/CALCITE-4090?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17144498#comment-17144498
]
Steven Talbot edited comment on CALCITE-4090 at 6/24/20, 11:52 PM:
-------------------------------------------------------------------
There is a related case that is important to have a test for, because I hit it
even after making what seemed like an obvious quick fix for above:
{code:java}
@Test void testDb2DialectSubselectFromUnion() {
String query = "select count(foo), \"units_per_case\" "
+ "from (select \"units_per_case\", \"cases_per_pallet\", \"product_id\",
1 as foo from \"product\" where \"cases_per_pallet\" > 100 "
+ "union all select \"units_per_case\", \"cases_per_pallet\",
\"product_id\", 1 as foo from \"product\" where \"cases_per_pallet\" < 100) "
+ "where \"cases_per_pallet\" > 100\n"
+ "group by \"product_id\", \"units_per_case\" "
+ "order by \"units_per_case\" desc";
final String expected = "SELECT COUNT(*), t3.units_per_case\n" +
"FROM (SELECT product.units_per_case, product.cases_per_pallet,
product.product_id, 1 AS " +
"FOO\n" +
"FROM foodmart.product AS product\n" +
"WHERE product.cases_per_pallet > 100\n" +
"UNION ALL\n" +
"SELECT product0.units_per_case, product0.cases_per_pallet,
product0.product_id, 1 AS " +
"FOO\n" +
"FROM foodmart.product AS product0\n" +
"WHERE product0.cases_per_pallet < 100) AS t3\n" +
"WHERE t3.cases_per_pallet > 100\n" +
"GROUP BY t3.product_id, t3.units_per_case\n" +
"ORDER BY t3.units_per_case DESC";
sql(query).withDb2().ok(expected);
}
{code}
was (Author: swtalbot):
There is a related case that is important to have a test for, because I hit it
even after making what seemed like an obvious quick fix for above:
{code:java}
@Test void testDb2DialectSubselectFromUnion() {
String query = "select count(foo), \"units_per_case\" "
+ "from (select \"units_per_case\", \"cases_per_pallet\", \"product_id\",
1 as foo from \"product\" where \"cases_per_pallet\" > 100 "
+ "union all select \"units_per_case\", \"cases_per_pallet\",
\"product_id\", 1 as foo from \"product\" where \"cases_per_pallet\" < 100) "
+ "where \"cases_per_pallet\" > 100\n"
+ "group by \"product_id\", \"units_per_case\" "
+ "order by \"units_per_case\" desc";
final String expected = "SELECT COUNT(*), t.units_per_case\n" +
"FROM (SELECT product.units_per_case, product.cases_per_pallet,
product.product_id, 1 AS " +
"FOO\n" +
"FROM foodmart.product AS product) AS t\n" +
"WHERE t.cases_per_pallet > 100\n" +
"GROUP BY t.product_id, t.units_per_case\n" +
"ORDER BY t.units_per_case DESC";
sql(query).withDb2().ok(expected);
}
{code}
> DB2 aliasing breaks with a complex select above a subselect
> -----------------------------------------------------------
>
> Key: CALCITE-4090
> URL: https://issues.apache.org/jira/browse/CALCITE-4090
> Project: Calcite
> Issue Type: Bug
> Reporter: Steven Talbot
> Priority: Major
>
> Test in RelToSqlConverterTest:
> {code:java}
> @Test void testDb2DialectSubselect() {
> String query = "select count(foo), \"units_per_case\" "
> + "from (select \"units_per_case\", \"cases_per_pallet\",
> \"product_id\", 1 as foo from \"product\") where \"cases_per_pallet\" > 100 "
> + "group by \"product_id\", \"units_per_case\" "
> + "order by \"units_per_case\" desc";
> final String expected = "SELECT COUNT(*), t.units_per_case\n" +
> "FROM (SELECT product.units_per_case, product.cases_per_pallet,
> product.product_id, 1 AS " +
> "FOO\n" +
> "FROM foodmart.product AS product) AS t\n" +
> "WHERE t.cases_per_pallet > 100\n" +
> "GROUP BY t.product_id, t.units_per_case\n" +
> "ORDER BY t.units_per_case DESC";
> sql(query).withDb2().ok(expected);
> }
> {code}
> The test fails with the "t." alias qualifier in the group by/order by/main
> select actually being "t0.".
> From stepping through the code in the debugger, I believe this is a general
> problem with the way aliases are calculated in situations like this by
> SqlImplementor, but other dialects with hasImplicitTableAlias() do not force
> qualified contexts and therefore do not hit this.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)