Commit 67f6a3f
committed
[SPARK-55043][SQL] Fix time travel with subquery containing table references
### What changes were proposed in this pull request?
This PR fixes an issue where `TIMESTAMP AS OF (subquery)` fails when the subquery references a table.
Before this fix, queries like:
```sql
SELECT * FROM t TIMESTAMP AS OF (SELECT MIN(ts) FROM t)
```
would fail with:
```
assertion failed: No plan for SubqueryAlias testcat.t
```
The fix changes `EvalSubqueriesForTimeTravel` to wrap the scalar subquery in a `Project` over `OneRowRelation` and execute it through the normal query execution path (`sessionState.executePlan`), which properly handles table references including V2 tables.
### Why are the changes needed?
The `EvalSubqueriesForTimeTravel` analyzer rule was directly calling `QueryExecution.prepareExecutedPlan` on the subquery's inner plan, which failed to properly plan V2 table relations.
### Does this PR introduce _any_ user-facing change?
Yes. Users can now use subqueries with table references in `TIMESTAMP AS OF` expressions.
### How was this patch tested?
Added a new test case in `DataSourceV2SQLSuite` that verifies time travel with a subquery containing a table reference.
### Was this patch authored or co-authored using generative AI tooling?
Yes.
Closes #53811 from cloud-fan/udf.
Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent 70a3ab5 commit 67f6a3f
File tree
2 files changed
+23
-24
lines changed- sql/core/src
- main/scala/org/apache/spark/sql/catalyst/analysis
- test/scala/org/apache/spark/sql/connector
2 files changed
+23
-24
lines changedLines changed: 10 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | 48 | | |
Lines changed: 13 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3241 | 3241 | | |
3242 | 3242 | | |
3243 | 3243 | | |
| 3244 | + | |
| 3245 | + | |
3244 | 3246 | | |
3245 | 3247 | | |
3246 | | - | |
3247 | | - | |
| 3248 | + | |
| 3249 | + | |
3248 | 3250 | | |
3249 | 3251 | | |
3250 | 3252 | | |
| 3253 | + | |
3251 | 3254 | | |
3252 | 3255 | | |
3253 | 3256 | | |
| |||
3282 | 3285 | | |
3283 | 3286 | | |
3284 | 3287 | | |
| 3288 | + | |
| 3289 | + | |
| 3290 | + | |
3285 | 3291 | | |
3286 | 3292 | | |
3287 | 3293 | | |
| |||
3307 | 3313 | | |
3308 | 3314 | | |
3309 | 3315 | | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
3310 | 3321 | | |
3311 | 3322 | | |
3312 | 3323 | | |
| |||
0 commit comments