Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.32.0
-
None
Description
For SQL dialects (MySQL, Hive, MsSQL) that do not support "GROUP BY ROLLUP(...)" syntax, but do support "GROUP BY ... WITH ROLLUP" syntax instead, wrong code is generated by RelToSqlConverter in the following situation:
- There is an Aggregate node with ROLLUP grouping
- It has a parent Sort node with an order of fields different from the order of fields in ROLLUP Aggregation
This can be demonstrated by the following test, that would fail if added to RelToSqlConverterTest class:
@Test void testSelectQueryWithGroupByRollupOrderByReversed() { final String query = "select \"product_class_id\", \"brand_name\"\n" + "from \"product\"\n" + "group by rollup(\"product_class_id\", \"brand_name\")\n" + "order by 2, 1"; final String expectedMysql = "SELECT `product_class_id`, `brand_name`\n" + "FROM `foodmart`.`product`\n" + "GROUP BY `product_class_id`, `brand_name` WITH ROLLUP"; sql(query) .withMysql().ok(expectedMysql); }
As the result we get the following SQL code:
SELECT `product_class_id`, `brand_name FROM `foodmart`.`product GROUP BY `brand_name`, `product_class_id` WITH ROLLUP
It can be observed that order of fields of aggregation was changed to match the order of fields in ORDER clause, thus changing the semantics of the ROLLUP clause itself.
Attachments
Issue Links
- links to