peter-toth commented on PR #59522: URL: https://github.com/apache/spark/pull/59522#issuecomment-6795866178
@ulysses-you @rekbun, I agree that marking the scan and packing its inputs in `inputRDD` is not the nicest place for this, even if V1 does the same with `spark.sql.files.*`. I see the problem differently, though. It is not many small partitions with distinct keys. It is many small splits, often of the same key: - Before 4.2, `BatchScanExec` grouped the splits of a key, and now `GroupPartitionsExec` does it where a consumer needs the keyed layout. - That grouping also happened to give sensible task sizes when nothing used the `KeyedPartitioning`. - Without a consumer, every `InputPartition` is a task now, keyed or not. So what's missing is packing splits by size, the way Iceberg packs its file scan tasks to a target size. That applies to unkeyed scans too. Coalescing across keys, with the layout kept, is a different feature. It only matters where a consumer reads the layout, and there GPE already groups by key. For the mechanism, what about a separate operator instead of a mode of the scan? - A rule right after `EnsureRequirements` puts it below each shuffle, wrapping the exchange's child, the way GPE wraps the child of the operator it serves. - The operators between the node and the scan keep the scan's own partitioning and ordering, and the exchange never reads its child's layout. So nothing has to be proven about the rest of the plan. - It decides the groups at execution, with a coalescer like GPE's. It uses the sizes of the scan's input partitions after runtime filtering, and reports `UnknownPartitioning(0)`. - `BatchScanExec` can then go back to what it is on master: no packing field, no partitioning or ordering override and no packing metrics. The metrics move to the node. - This works where the exchange's child reads one scan through narrow operators. - The cost is that the operators between the node and the scan run once per original split. A partial aggregate, for example, then emits its partial rows per split rather than per merged task, so with many small splits of the same key it shuffles more than packing inside the scan does. - A plan root without an exchange, such as a write, would be a separate case, with the `CacheManager` exception from the last round. Longer term, I could imagine a partitioning that carries an optional key and an optional size per partition. A planner-inserted operator could then group by key, by size or both, to satisfy a requirement or reach a target size. It could also merge keys where that is allowed. That would also give the distribution-preserving coalescing you describe, but I'd keep it out of this PR. -- 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]
