hanyuzheng7 opened a new pull request, #30137:
URL: https://github.com/apache/flink/pull/30137

   ## What is the purpose of the change
   
   A group window auxiliary function such as `TUMBLE_START` is only replaced 
with a window property in the SELECT, HAVING or ORDER BY clause of a query that 
groups by the same window. Calcite validates these clauses of an aggregate 
query, e.g. it rejects `TUMBLE_START(ts, INTERVAL '10' SECOND)` with `GROUP BY 
TUMBLE(ts, INTERVAL '1' MINUTE)`. It doesn't check a query that doesn't 
aggregate, or the WHERE and GROUP BY clauses, so there the call fails in code 
generation, in batch and in streaming mode:
   
   ```sql
   SELECT TUMBLE_START(ts, INTERVAL '10' SECOND) FROM T;
   SELECT COUNT(*) FROM T WHERE TUMBLE_START(ts, INTERVAL '1' MINUTE) > 
TIMESTAMP '2020-01-01 00:00:00'
   GROUP BY TUMBLE(ts, INTERVAL '1' MINUTE);
   ```
   ```
   Unsupported call: TUMBLE_START(TIMESTAMP(3), INTERVAL SECOND(3) NOT NULL) If 
you think this function should be supported, you can create an issue and start 
a discussion for it.
   ```
   
   With this change, validation fails with:
   ```
   TUMBLE_START(`T`.`ts`, INTERVAL '10' SECOND) can only be used in the SELECT, 
HAVING or ORDER BY clause of a query that groups by a TUMBLE window with the 
same time attribute and interval.
   ```
   
   A query in which the optimizer removes such a call before code generation, 
e.g. `WHERE TUMBLE_START(ts, INTERVAL '10' SECOND) IS NOT NULL`, used to run 
and now fails validation.
   
   ## Brief change log
   
   After Calcite validated a SELECT, `FlinkCalciteSqlValidator` rejects a group 
window auxiliary function in its WHERE and GROUP BY clauses, and in all of its 
clauses if it doesn't aggregate. Sub-queries are checked when they are 
validated.
   
   ## Verifying this change
   
   Added cases to `FlinkCalciteSqlValidatorTest`: the calls without GROUP BY 
and in the WHERE, ORDER BY, OVER and GROUP BY clauses fail validation, and the 
calls in the SELECT, HAVING and ORDER BY clauses of a group window aggregation, 
also in a sub-query, pass.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? no
     - If yes, how is the feature documented? not applicable
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to