spark
spark copied to clipboard
[SPARK-46741][SQL] Cache Table with CTE won't work
What changes were proposed in this pull request?
Cache Table with CTE won't work, there are two reasons
- In the current code CTE in CacheTableAsSelect will be inlined
- CTERelation Ref and Def didn't handle the CTEId doCanonicalize issue
Cause the current case can't be matched.
Why are the changes needed?
Fix bug
Does this PR introduce any user-facing change?
Yea, Cache table with CTE can work after this pr
How was this patch tested?
Added UT
Was this patch authored or co-authored using generative AI tooling?
No
ping @cloud-fan
How about current? @cloud-fan
ping @cloud-fan @yaooqinn
@cloud-fan Changed follow the discussion
ping @cloud-fan
ping @cloud-fan @HyukjinKwon @dongjoon-hyun @viirya
what was behaviour before? Would be great to show the result before/after
what was behaviour before? Would be great to show the result before/after
For the query in cache.sql
EXPLAIN EXTENDED SELECT * FROM cache_nested_cte_table
before this pr, cached table cache_nested_cte_table
won't match, will execute again, after this pr, it can match the InMemoryRelation