adriangb commented on code in PR #27669:
URL: https://github.com/apache/datafusion/pull/27669#discussion_r4675997942


##########
datafusion/physical-optimizer/src/projection_pushdown.rs:
##########
@@ -507,6 +508,59 @@ fn leaf_column_name(index: usize) -> String {
     format!("{LEAF_COLUMN_PREFIX}_{index}")
 }
 
+/// Returns the input of `node` if the split may place the leaf projection
+/// below it.
+///
+/// The split gives `node` an input with different columns, so `node` must not
+/// reference its input's columns and must output them unchanged, or the outer
+/// projection's column indices would point at the wrong columns. The arms are
+/// an allowlist: satisfying that is necessary, not sufficient.

Review Comment:
   An example showing the equivalent of EXPLAIN ANALYZE or something other than 
prose would be helpful.



##########
datafusion/physical-optimizer/src/projection_pushdown.rs:
##########
@@ -507,6 +508,59 @@ fn leaf_column_name(index: usize) -> String {
     format!("{LEAF_COLUMN_PREFIX}_{index}")
 }
 
+/// Returns the input of `node` if the split may place the leaf projection
+/// below it.
+///
+/// The split gives `node` an input with different columns, so `node` must not
+/// reference its input's columns and must output them unchanged, or the outer
+/// projection's column indices would point at the wrong columns. The arms are
+/// an allowlist: satisfying that is necessary, not sufficient.
+fn split_host_child(node: &Arc<dyn ExecutionPlan>) -> Option<&Arc<dyn 
ExecutionPlan>> {
+    if let Some(repartition) = node.downcast_ref::<RepartitionExec>() {
+        // Hash and Range partitioning reference columns by index, which would
+        // have to be remapped against the rewritten child schema. Round robin
+        // carries no column references, and is what `EnsureRequirements`
+        // inserts here.
+        if !matches!(repartition.partitioning(), 
Partitioning::RoundRobinBatch(_)) {
+            return None;
+        }
+        Some(repartition.input())
+    } else if let Some(limit) = node.downcast_ref::<GlobalLimitExec>() {
+        // A source that supports skip pushdown wraps its scan in this for the
+        // skip, which leaves the projection holding the leaf above it.
+        Some(limit.input())
+    } else if let Some(coalesce) = 
node.downcast_ref::<CoalescePartitionsExec>() {
+        // A scan with more than one file group puts this between that limit
+        // and the source.
+        Some(coalesce.input())
+    } else {
+        None
+    }
+}
+
+/// The hosts between a projection and the child the split places the leaf
+/// projection on.

Review Comment:
   This wording was confusing to me. I'm not sure what a `host` is in this 
context. It's terminology introduced by this PR, we should be thoughtful about 
(1) what name to use and (2) define it clearly. Agents will make up names and 
use them as if it was a term everyone knows, when they've literally pulled it 
out of their ~< redacted >~ context.



##########
datafusion/physical-optimizer/src/projection_pushdown.rs:
##########
@@ -507,6 +508,59 @@ fn leaf_column_name(index: usize) -> String {
     format!("{LEAF_COLUMN_PREFIX}_{index}")
 }
 
+/// Returns the input of `node` if the split may place the leaf projection
+/// below it.
+///
+/// The split gives `node` an input with different columns, so `node` must not
+/// reference its input's columns and must output them unchanged, or the outer
+/// projection's column indices would point at the wrong columns. The arms are
+/// an allowlist: satisfying that is necessary, not sufficient.
+fn split_host_child(node: &Arc<dyn ExecutionPlan>) -> Option<&Arc<dyn 
ExecutionPlan>> {
+    if let Some(repartition) = node.downcast_ref::<RepartitionExec>() {
+        // Hash and Range partitioning reference columns by index, which would
+        // have to be remapped against the rewritten child schema. Round robin
+        // carries no column references, and is what `EnsureRequirements`
+        // inserts here.

Review Comment:
   Does this mean that if we have a plan where we end up with:
   
   ```
   Projection: file_row_index(), col
     RepartitionExec(hash)
       DataSourceExec: test.parquet
   ```
   
   We woudln't be able to push `file_row_index()` and thus can't evaluate it / 
it fails at runtime?



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