alamb commented on a change in pull request #8662:
URL: https://github.com/apache/arrow/pull/8662#discussion_r523410398



##########
File path: rust/datafusion/src/physical_plan/projection.rs
##########
@@ -114,14 +117,33 @@ impl ExecutionPlan for ProjectionExec {
     }
 
     async fn execute(&self, partition: usize) -> 
Result<SendableRecordBatchStream> {
+        let input = if 
self.input.as_any().downcast_ref::<EmptyExec>().is_some() {
+            placeholder_stream(self.schema.clone())?
+        } else {
+            self.input.execute(partition).await?
+        };
+
         Ok(Box::pin(ProjectionStream {
             schema: self.schema.clone(),
             expr: self.expr.iter().map(|x| x.0.clone()).collect(),
-            input: self.input.execute(partition).await?,
+            input,
         }))
     }
 }
 
+// Makes a stream only contains one null element
+fn placeholder_stream(schema: Arc<Schema>) -> 
Result<SendableRecordBatchStream> {

Review comment:
       This is a good approach 👍 

##########
File path: rust/datafusion/src/physical_plan/projection.rs
##########
@@ -114,14 +117,33 @@ impl ExecutionPlan for ProjectionExec {
     }
 
     async fn execute(&self, partition: usize) -> 
Result<SendableRecordBatchStream> {
+        let input = if 
self.input.as_any().downcast_ref::<EmptyExec>().is_some() {

Review comment:
       I like the simplicity of this special case for execution. 
   
   However, I think it might be slightly confusing that `EmptyExec` will 
produce different output depending on where in the plan it is. Thus you can't 
reason about what EmptyExec will produce by itself (you need to know how it is 
used).
   
   I wonder if we could add a field such as  `produce_one_row: bool`  to 
`EmptyExec`  and call `placeholder_stream` in 
`EmptyExec::execute`[here](https://github.com/apache/arrow/blob/master/rust/datafusion/src/physical_plan/empty.rs#L81)
   
   However, this is a stylistic comment and we can always make that improvement 
later on as another PR




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to