[CALCITE-7595] Support FILTER clause with window functions#5019
Conversation
mihaibudiu
left a comment
There was a problem hiding this comment.
Where is the documentation about the new grammar and its semantics?
|
|
||
| !ok | ||
|
|
||
| # [CALCITE-6442] Support FILTER clause with window functions |
There was a problem hiding this comment.
Please add here the following:
- next 4 tests are related to this issue
- results were validated on Postgres
There was a problem hiding this comment.
The execution results differ from PostgreSQL.
@xuzifu666
https://onecompiler.com/postgresql/44smkpfxb
There was a problem hiding this comment.
This data source should be different. I used the standard Scott data source for the test set, and it passed the syntax verification. I'll investigate the Calcite data source later. @iwanttobepowerful
| NotJsonImplementor.of( | ||
| new MethodImplementor(BuiltInMethod.IS_JSON_SCALAR.method, | ||
| NullPolicy.NONE, false))); | ||
| define(FILTER, new FilterImplementor()); |
There was a problem hiding this comment.
I don't understand where this is used. Can you please explain?
There was a problem hiding this comment.
The FILTER operator implements conditional aggregation in SQL, such as:
SUM(salary) FILTER (WHERE department = 'Sales') COUNT(*) FILTER (WHERE age > 30)
Processing Pipeline:
- SQL Parsing →
FILTER (WHERE condition)parsed asSqlKind.FILTERnode - Validation → Checks aggregate-FILTER compatibility (we reject
COUNT(DISTINCT) + FILTERin window functions) - SQL-to-Relational Conversion → FILTER condition extracted and stored
- Code Generation → Registers FilterImplementor to translate FILTER into executable code
I had added a comment about it.
There was a problem hiding this comment.
How come this does not affect other aggregates that have filters and only applies to window aggregates?
There was a problem hiding this comment.
In my view restriction is in SqlOverOperator.validateCall(), which is only called for window functions (the OVER operator).
if (hasFilter && aggCall.getKind() == SqlKind.COUNT
&& aggCall.getFunctionQuantifier() != null) {
throw validator.newValidationError(aggCall, RESOURCE.overNonAggregate());
}
- Normal aggregates bypass SqlOverOperator entirely—they're validated by their own operator (e.g., SqlCountAggFunction)
- Window aggregates MUST go through SqlOverOperator because they have the OVER clause
- Our restriction is injected into the SqlOverOperator validation, so it naturally only affects window functions
mihaibudiu
left a comment
There was a problem hiding this comment.
I have approved, but I still have a question
|
Interesting, can you add a comment in the RexImplTable about this? |
OK, I had added comments about it. |
|
Do you happy with these changes? If OK, I would squash the commits~ @mihaibudiu |
|
I have approved |
|



jira: https://issues.apache.org/jira/browse/CALCITE-7595