cloud-fan opened a new pull request, #53811:
URL: https://github.com/apache/spark/pull/53811

   ### 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.


-- 
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]

Reply via email to