pjmore commented on a change in pull request #2000:
URL: https://github.com/apache/arrow-datafusion/pull/2000#discussion_r829570286



##########
File path: datafusion/src/physical_plan/file_format/parquet.rs
##########
@@ -236,32 +237,56 @@ impl ExecutionPlan for ParquetExec {
 
         let adapter = SchemaAdapter::new(self.base_config.file_schema.clone());
 
-        let join_handle = task::spawn_blocking(move || {
-            if let Err(e) = read_partition(
-                object_store.as_ref(),
-                adapter,
-                partition_index,
-                &partition,
-                metrics,
-                &projection,
-                &pruning_predicate,
-                batch_size,
-                response_tx.clone(),
-                limit,
-                partition_col_proj,
-            ) {
-                println!(
+        let join_handle = if projection.is_empty() {
+            task::spawn_blocking(move || {
+                if let Err(e) = read_partition_no_file_columns(
+                    object_store.as_ref(),
+                    &partition,
+                    batch_size,
+                    response_tx.clone(),

Review comment:
       From your example above note that the TableScan projects 4 columns and 
not 3. This means that datafusion is reading 4 columns from the table which is 
more than the number of partition columns.  
   ```
   Projection: #t.year, #t.month, #t.day                                        
                                                                                
                                             
      Filter: #t.id > Int64(0)                                                  
                                                                                
                                              
        TableScan: t projection=Some([0, 11, 12, 13]), filters=[#t.id > 
Int64(0)]
   ```
   
   This is because datafusion knows that it needs to read the id column from 
the source to evaluate the query even if it doesn't exist in the final results. 
0 is the id column while 11,12, and 13 are the virtual partition columns. This 
will never hit the code path that I've added since I check if the file 
projection is empty. This is calculated from the snippet below.
   ```
   let projection = match self.base_config.file_column_projection_indices() {
       Some(proj) => proj,
       None => (0..self.base_config.file_schema.fields().len()).collect(),
   };
   ```
   This projection for the example provided will be ```[0]``` and so will be 
executed using the existing code path. The additional code that I've added will 
only be executed for the example table provided above if the query only refers 
to the partition columns year, month, or day. If I modify the test in 
path_partition.rs to use this query ``` SELECT distinct year,month,day FROM t 
where id > 0 ``` and add some print statements inside the if statement that 
decides which function to use, the output is:
   ```
   Non-empty projection. using read_partition
   ```
   
   And if I revert the query back to  ``` SELECT distinct year,month,day FROM t 
``` the output is:
   ```
   Empty projection. using read_partition_no_file_columns
   ```
   




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


Reply via email to