Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-6691] QUALIFY on project references wrong columns
The bug was that we were translating the QUALIFY expression after the SELECT clause, and the mapping was wrong if columns had moved around of it the expressions were non-trivial. The fix is to convert the QUALIFY expression at the same time as the HAVING expression. Also add support for a QUALIFY clause in a query with a GROUP BY. In this case, the QUALIFY expression may reference aggregate functions. Previously such queries would give a ClassCastException (trying to convert a LogicalAggregate to a LogicalProject). If a QUALIFY expression references or duplicates an expression in the SELECT clause, we no longer detect and deduplicate that. This has made one or two plans more verbose. Potentially we would add back deduplication. Or just let Calc do common subexpression elimination later in the planning process, as it always has done. Also refactor SqlToRelConverter. Previously we were creating some `SqlNodeList` wrappers only to use their `accept(SqlVisitor)` method; now we leave them as `List<SqlNode>` and call new method `SqlVisitor.visitAll(List<SqlNode>)`. Close #4061
- Loading branch information