[SPARK-53809][SQL]Add canonicalization for DSv2 scan #52529
Draft
+20
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR proposes to add doCanonicalize function for dsv2 Scan interface. The reason is that filters pushed to the scan (e.g., via SupportsRuntimeV2Filtering) may come in different orders after QO rewrite, while the scans are identical in fact.
As a result, DataSourceV2ScanRelation and BatchScanExec, who have a scan field, also need to add canonicalization accordingly.
Why are the changes needed?
Query optimization rules such as MergeScalarSubqueries check if two plans are identical by comparing their canonicalized form. For DSv2, the comparison goes down to DataSourceV2ScanRelation in the hierarchy, which currently lacks of canonicalize function.
Does this PR introduce any user-facing change?
No
How was this patch tested?
todo
Was this patch authored or co-authored using generative AI tooling?
No