[FLINK-40424][table][python] Support windowing TVFs in the DataFrame API - #29070
[FLINK-40424][table][python] Support windowing TVFs in the DataFrame API#29070Timm0 wants to merge 1 commit into
Conversation
|
|
||
| def _to_interval_expression(value: Union["datetime.timedelta", Expression]) -> Any: | ||
| if isinstance(value, datetime.timedelta): | ||
| millis = value // datetime.timedelta(milliseconds=1) |
There was a problem hiding this comment.
Do we intentionally drop subsecond part in python?
There was a problem hiding this comment.
Correct me if I'm wrong but Flink supports ms resolution, while Python timedelta supports sub-ms. Therefore we are dropping any sub-ms here. One thing we could do here though is to throw a ValueError for non-zero sub-ms instead of silently dropping. If you think that this would be the right call here, then I'm happy to add a guard.
| final List<Column> columns = new ArrayList<>(inputSchema.getColumns()); | ||
| columns.add(Column.physical("window_start", DataTypes.TIMESTAMP(3).notNull())); | ||
| columns.add(Column.physical("window_end", DataTypes.TIMESTAMP(3).notNull())); | ||
| columns.add(Column.physical("window_time", timeColumnType.notNull())); | ||
| return ResolvedSchema.of(columns); |
There was a problem hiding this comment.
It looks like it might lead to validation error if there are already columns with such names
There was a problem hiding this comment.
You are right, but this is also current behavior. During conversion I have re-used SqlWindowTableFunction.inferRowType() which is the same path as SQL, and I have done some additional testing here and both paths throw a ValidationException in the planner. I can add an additional guard in SqlWindowTableFunction.inferRowType() if we want to have a unified error message.
- Add `tumble`/`hop`/`cumulate`/`session` window methods to the PyFlink `DataFrame` API, with time-column resolution and day-time interval handling - Introduce internal `WindowTableFunctionQueryOperation` - Dispatch it through `QueryOperationVisitor` and `QueryOperationDefaultVisitor` and construct it via `OperationTreeBuilder.windowTableFunction` - Convert the operation to a `LogicalTableFunctionScan` programmatically in `QueryOperationConverter` - Add tests: api-java operation test, planner `WindowTableFunctionRelNodeTest`, `QueryOperation` serialization + semantic programs, and PyFlink unit + IT tests - Expose `createTable`/`getOperationTreeBuilder` on the Table API test steps and refactor `_materialize` into `test_case_utils` for stream test cases - Document the window methods in `dataframe.rst`
What is the purpose of the change
This change adds
tumble,hop,cumulate, andsessionwindow methods to theDataFrameAPI and the internal Table API machinery they need. The window operation is built programmatically as aLogicalTableFunctionScanrather than by generating SQL strings, so the DataFrame layer does not have to track Flink's SQL dialect. No new public Table API is introduced, since all added Table API types are
@Internal.Brief change log
tumble/hop/cumulate/sessionwindow methods to the PyFlinkDataFrameAPI, with time-column resolution and day-time interval handlingWindowTableFunctionQueryOperationQueryOperationVisitorandQueryOperationDefaultVisitorand construct it viaOperationTreeBuilder.windowTableFunctionLogicalTableFunctionScanprogrammatically inQueryOperationConverterWindowTableFunctionRelNodeTest,QueryOperationserialization + semantic programs, and PyFlink unit + IT testscreateTable/getOperationTreeBuilderon the Table API test steps and refactor_materializeintotest_case_utilsfor stream test casesdataframe.rstVerifying this change
WindowTableFunctionRelNodeTestQueryOperationserialization + semantic programsDoes this pull request potentially affect one of the following parts:
@Public(Evolving): yesDocumentation
flink-python/docs/reference/pyflink.dataframe/dataframe.rst+ Python docstringsWas generative AI tooling used to co-author this PR?
Generated-by: Opus 4.8 (1M context)