v28k opened a new pull request, #27329:
URL: https://github.com/apache/datafusion/pull/27329

   ## Which issue does this PR close?
   
   Closes #27328
   
   ## Rationale for this change
   
   Queries such as `VALUES ((SELECT 1), 5)` and `INSERT INTO t VALUES ((SELECT 
1), 5)` fail with `Internal error: ScalarSubqueryExpr evaluated before the 
subquery was executed`. The default VALUES planner evaluates row expressions 
while the physical plan is built, but an uncorrelated scalar subquery produces 
a `ScalarSubqueryExpr` whose value is only populated at runtime by 
`ScalarSubqueryExec`.
   
   ## What changes are included in this PR?
   
   In `physical_planner.rs`, when planning `LogicalPlan::Values`, we check 
whether any row contains an `Expr::ScalarSubquery`. If so, each row is planned 
as a `ProjectionExec` over a `PlaceholderRowExec`, combined across rows with 
`UnionExec::try_new` (or the single projection for a one-row VALUES). This 
defers evaluation to execution time inside `ScalarSubqueryExec`. Standard 
VALUES lists without scalar subqueries continue using the existing optimized 
`MemorySourceConfig::try_new_as_values` path.
   
   ## What is the testing strategy for this PR?
   
   - Added test cases in `subquery.slt` verifying single-row and multi-row 
VALUES with scalar subqueries in different column positions.
   - Ran `cargo test --profile ci -p datafusion-sqllogictest --test 
sqllogictests -- subquery values insert explain`.
   - Passed `cargo fmt` and `cargo clippy`.
   
   ## Are there any user-facing changes?
   
   No API changes. Valid queries containing scalar subqueries within VALUES 
clauses now execute successfully instead of panicking.


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