raghavyadav01 commented on code in PR #27329:
URL: https://github.com/apache/datafusion/pull/27329#discussion_r4593944903


##########
datafusion/core/src/physical_planner.rs:
##########
@@ -847,6 +847,40 @@ impl DefaultPhysicalPlanner {
                     plan
                 }
             }
+            // A values list is evaluated while it is planned, before the 
scalar
+            // subqueries have run, so rows with a scalar subquery are 
projected
+            // from a placeholder row at execution time instead.
+            LogicalPlan::Values(Values { values, schema })
+                if values.iter().flatten().any(contains_scalar_subquery) =>
+            {
+                let placeholder: Arc<dyn ExecutionPlan> =
+                    
Arc::new(PlaceholderRowExec::new(Arc::new(Schema::empty())));
+                let rows = values
+                    .iter()
+                    .map(|row| {
+                        let exprs = row
+                            .iter()
+                            .zip(schema.fields())
+                            .map(|(expr, field)| {
+                                Ok(ProjectionExpr {
+                                    expr: create_physical_expr(
+                                        expr,
+                                        schema,
+                                        execution_props,
+                                        planning_ctx,
+                                    )?,
+                                    alias: field.name().clone(),
+                                })
+                            })
+                            .collect::<Result<Vec<_>>>()?;
+                        Ok(Arc::new(ProjectionExec::try_new(
+                            exprs,
+                            Arc::clone(&placeholder),
+                        )?) as Arc<dyn ExecutionPlan>)
+                    })
+                    .collect::<Result<Vec<_>>>()?;
+                UnionExec::try_new(rows)?

Review Comment:
   Since each row becomes its own partition here, does VALUES lose its order? 
On this branch `VALUES ((SELECT min(v) FROM sq_values)), (20), (30), (40)` came 
back shuffled for me, while main keeps the order. Would it work to keep the 
rows in one partition and evaluate the expressions at execute time instead?



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