peter-toth opened a new pull request, #60459: URL: https://github.com/apache/spark/pull/60459
### What changes were proposed in this pull request? Backport of #60447 to branch-4.x, a follow-up of #60123. `BatchScanExec` takes its `Scan` again, as before #60123, and shares its `PlannedScan` the way the SPARK-60752 backports to branch-4.3, branch-4.2, branch-4.1 and branch-4.0 do: - Each node holds a `PlannedScan` in a private field, built from `scan` when the node is created. - `makeCopy` and `clone` hand it over to a copy over the same `Scan`. The rules that rewrite the node do that through `makeCopy`. `clone` needs its own override, because `TreeNode.clone` does not go through `makeCopy`. - Any other new node plans its own, including one the case-class `copy` makes. Nothing in Spark copies an executable `BatchScanExec` with `copy`. - `DataSourceV2Strategy` passes `relation.scan` again. `PlannedScan` is package private and has no extractor. The change is the same as on master. branch-4.x's `BatchScanExec` has 6 fields (no storage filters), so the reverted patterns match 6 fields. ### Why are the changes needed? #60123 replaced the `scan: Scan` parameter of `BatchScanExec` with `plannedScan: PlannedScan`, so that the copies of a node share what it planned. That changed the signature. Code that builds the node, or matches it with `case BatchScanExec(_, scan: MyScan, ...)`, no longer compiles. #60123 had to change eight test suites for that, and extensions that build or match the node would have to change the same way. The sharing does not need a constructor field. The backports keep the signature with a private field that `makeCopy` and `clone` hand over, as `InMemoryRelation` does with its `statsOfPlanToCache`. This PR uses the same code on branch-4.x, as #60447 does on master, so every branch has the same shape. ### Does this PR introduce _any_ user-facing change? No. Queries behave as with #60123. For code that builds or matches `BatchScanExec`, its second parameter is a `Scan` again, as in the released versions. A node that the case-class `copy` makes plans its own `Batch` and partitions again, as before #60123 and on the maintenance branches. That includes the canonical form, which `doCanonicalize` makes with `copy`. #60123 shared the `PlannedScan` there too, as a side effect of sharing it through `copy`. ### How was this patch tested? - The SPARK-60752 test in `SparkPlanSuite` makes the copies before the node plans. It checks that `makeCopy` and `clone` share the node's `Batch` and partitions, and that a `makeCopy` over another `Scan` and a case-class `copy` do not. - The SPARK-60752 tests of #60123 in `KeyGroupedPartitioningSuite` and the runtime filter suites pass unchanged. - The SPARK-60618 test that rebuilds a scan uses `copy` again to plan the replacement partitions. - The suites that matched the scan through `PlannedScan` match the `Scan` again. Also ran `GroupPartitionsExecSuite`, `SameResultSuite`, `SQLAppStatusListenerSuite`, `EnsureRequirementsSuite`, the `DynamicPartitionPruningV2*` suites, `DataSourceV2CatalystRuntimeFilterSuite`, `DataSourceV2SQLSuiteV2Filter`, `FileBasedDataSourceSuite`, `DataSourceV2OptionSuite`, `PruneFileSourcePartitionsSuite`, `OrcV2SchemaPruningSuite`, `AvroRowReaderSuite` and `AvroV2Suite`. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code with Claude Opus 5.5 -- 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]
