Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.32.0
-
None
-
None
Description
Wrong SQL code is generated when Filter (or Calc) node contains window expression.
Example can be demonstrated by adding following code to RelToSqlConverterTest.java:
@Test void testWindowedFilter() { final RelBuilder builder = relBuilder(); final RelNode root = builder .scan("DEPT") .filter( builder.lessThan( builder.aggregateCall(SqlStdOperatorTable.MAX, builder.field("DEPTNO")) .over() .partitionBy(builder.field("DNAME")) .toRex(), builder.literal(1) ) ) .build(); final String expectedSql = "?"; assertThat(toSql(root), isLinux(expectedSql)); }
Generated SQL code will look like:
SELECT * FROM \"scott\".\"DEPT\" WHERE (MAX(\"DEPTNO\") OVER (PARTITION BY \"DNAME\" RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)) < 1
This is incorrect - window expressions are not allowed in WHERE clause by SQL standard and Calcite itself would produce following error message if this SQL code would be passed as input:
Windowed aggregate expression is illegal in WHERE clause
Attachments
Issue Links
- is related to
-
CALCITE-5523 RelToSql converter generates GROUP BY clause with window expression
- Open