HyukjinKwon opened a new pull request, #60129: URL: https://github.com/apache/spark/pull/60129
### What changes were proposed in this pull request? A follow-up to SPARK-60734 (#59943), which pushes the columns that streaming queries read down to the scans of Data Source V2 streaming sources. This PR pushes their filters down too, when the table of the source opts in with the new capability `TableCapability.STREAMING_FILTER_PUSHDOWN` and its scan builder is a `SupportsPushDownFilters`, `SupportsPushDownV2Filters` or `SupportsPushDownCatalystFilters`. It was part of #59943 until the review there suggested to move it to a follow-up (https://github.com/apache/spark/pull/59943#discussion_r4476659703). This PR is based on #59943, whose commits it includes until that PR is merged. - The scan builder gets the filters that the query applies first to all the rows that it reads from the source, from the plan that `StreamingV2ScanPushDown` optimizes when the query starts: the deterministic filters without subqueries or placeholders that all the occurrences of the relation apply, up to the first one that is not pushed down, through `PushDownUtils.pushFilters` as for batch scans. The filters that the optimizer infers from constraints are not inferred there, so that a scan only gets the filters that the query applies to its own source. - `StreamingDataSourceV2ScanRelation.pushedFilters` records the filters that the builder gets in some form (`PushDownUtils.filtersOfScanBuilder`), and the plan of the query applies them to the rows of each occurrence of the relation (`StreamingV2ScanPushDown.withPushedFilters`), so the scan cannot drop a row that the plan keeps. - A Python data source gets no filter for its streaming scans, since its table does not declare the capability. - The internal configuration `spark.sql.streaming.v2FilterPushdown.enabled` (true by default) disables it. This is a draft until these items, from the review of the filters in #59943, are addressed: - With a `SupportsPushDownV2Filters` builder, a pushed filter can run before a filter written before it that the builder does not get, such as `payload RLIKE '^[0-9]+$' AND CAST(payload AS INT) > 0` under ANSI: the pushed filters should end at the first filter that the builder does not get (https://github.com/apache/spark/pull/59943#discussion_r4476491686). - Tests with `SupportsPushDownV2Filters` and `SupportsPushDownCatalystFilters` builders, and of the order in which a micro-batch evaluates the filters (https://github.com/apache/spark/pull/59943#discussion_r4476491716). - `filtersOfScanBuilder` and `pushFilters` should share one check of the filters that a builder gets (https://github.com/apache/spark/pull/59943#discussion_r4476491720). - A value that `forStartup` does not replace becomes a stale filter that drops rows with no error, so the pushed filters could be checked against the plan of the first micro-batch (https://github.com/apache/spark/pull/59943#discussion_r4476659705). - #59943 now replaces every cast of a string to a timestamp with a local time zone with a placeholder when the query starts, so filters such as `ts < '2100-01-01 12:00:00'` or `CAST(s AS TIMESTAMP) < ...` are not pushed down: the casts whose values do not depend on the date could be pushed down again (https://github.com/apache/spark/pull/59943#discussion_r4476491708). ### Why are the changes needed? So that a streaming source that applies the filters of a query reads fewer rows, as batch scans do. ### Does this PR introduce _any_ user-facing change? It adds the table capability `STREAMING_FILTER_PUSHDOWN`. Nothing changes for a table that does not declare it. A source that declares it gets the filters of the streaming query, and may drop the rows that fail them: Spark still evaluates all the filters, so the results do not change, but the progress of the query only counts the rows that the source returns. ### How was this patch tested? The tests of the filters in `StreamingV2ScanPushDownSuite` and `PythonStreamingDataSourceSuite`, moved from #59943. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5) This pull request and its description were written by Isaac. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
