HyukjinKwon commented on PR #59943: URL: https://github.com/apache/spark/pull/59943#issuecomment-6617984914
Thank you, @HeartSaVioR and @zikangh. I reworked it so that the optimizer decides the columns, rather than a pass of its own over the analyzed plan (29864de): - As @zikangh explained, the stream of a source is created from its scan and has to exist before any micro-batch is planned, so the scan is still built when the query starts. But the query is now optimized once at that point, by the optimizer of its micro-batches and with their configuration, which a restarted query takes from the offset log as its micro-batches do. Each scan reads the columns that the planner takes from that optimized plan for its relation: the projections and the filters over each occurrence of the relation, matched with `PhysicalOperation` as `DataSourceV2Strategy` does. `StreamingV2ScanPushDown` tracks no lineage of its own: `ColumnPruning` and the other rules decide. - The plan of the query does not change. The relation keeps all its columns, so each micro-batch is optimized exactly as before, and the optimizer keeps deciding the columns of every operator and their order, including the stateful ones. Only the scan node of the physical plan outputs the columns that the scan reads, under the projection that the optimizer put over the relation. If a micro-batch read a column that the scan does not read, the planner would fail with an internal error that names the conf, rather than read the wrong column. - The query is only optimized for a source whose scan builder supports a pushdown, so queries over Kafka, rate, memory or Python data sources do not pay for it. The same optimized plan also gives the filters, which addresses the TODO that the commit message of 2adc69aca3d mentions (cf39791). Each scan gets the deterministic filters without subqueries that all the occurrences of its relation apply, through `PushDownUtils.pushFilters` as batch scans do. Spark still evaluates all of them after the scan, and a filter on the current time is not pushed, since the query is optimized with the current time of its micro-batches. Aggregates, limits and the other operations that batch scans can apply span all the micro-batches, so they are not pushed. Each pushdown has its own internal conf. On the tests: since the optimizer decides, the new tests cover queries whose analyzed plans reference more than the optimized ones. These include a column added and dropped, chained projections, several aliases, expressions and functions, structs and their fields, `SELECT *`, `from_json`, `get_json_object`, `parse_json` with `variant_get`, time windows, unions of reads, and a query that reads no column, each checked against the same query in batch. There are also restarts of a stream-stream join and an aggregation across the two values of the conf, over a connector that returns the pruned columns in another order. A pushdown inside the optimizer of each micro-batch, as for batch scans, would need the stream to be independent of the scan, which would change the API. This keeps the API, and the scan still gets what the optimized plan reads. -- 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]
