v28k opened a new issue, #27328:
URL: https://github.com/apache/datafusion/issues/27328

   ### Describe the bug
   
   A VALUES clause whose rows contain an uncorrelated scalar subquery fails 
during physical planning with an internal error:
   
   Internal error: ScalarSubqueryExpr evaluated before the subquery was 
executed. This issue was likely caused by a bug in DataFusion's code.
   
   
   `LogicalPlan::Values` is processed by 
`MemorySourceConfig::try_new_as_values`, which attempts to evaluate every row 
expression while the physical plan is built. Under physical scalar subquery 
execution, an uncorrelated scalar subquery is represented as a 
`ScalarSubqueryExpr`, which expects execution-time evaluation inside 
`ScalarSubqueryExec`. Because the subquery has not yet run at planning time, 
evaluation fails with an internal error.
   
   ### To Reproduce
   
   VALUES ((SELECT 1), 5);
   SELECT * FROM (VALUES ((SELECT min(x) FROM (VALUES (1), (2)) AS v(x)), 5)) 
AS t(a, b);
   CREATE TABLE v (a BIGINT, b BIGINT);
   INSERT INTO v VALUES ((SELECT 1), 5);
   
   ### Expected behavior
   
   The first two SELECT queries should return `(1, 5)`. The INSERT statement 
should insert one row `(1, 5)` into table `v`.
   
   ### Additional context
   
   Reproduced on `main` at commit bc86321 (57.0.0-dev) and with 
datafusion-python 55.0.0. Found using an automated grammar-based SQL fuzzer.
   
   ### Willingness to contribute
   
   I plan to contribute a fix for this bug independently


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