You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "NGA-TRAN (via GitHub)" <gi...@apache.org> on 2023/10/20 17:41:57 UTC

[PR] feat: make data type of FileScanConfig.table_partition_cols a vector of Fields [arrow-datafusion]

NGA-TRAN opened a new pull request, #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890

   
   
   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes https://github.com/apache/arrow-datafusion/issues/7875
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   Currently, `FileScanConfig.table_partition_cols` has data type `Vec<(String, DataType)>` to store only columns name and its data type. A column can include many more information such as `nullable` and extra meta data. Thus, when we convert table_partition_cols to Fields [here](https://github.com/apache/arrow-datafusion/blob/1dd887cdff518ede1d1de457f4b20c22a9c7228f/datafusion/core/src/datasource/physical_plan/file_scan_config.rs#L138), all other information of a field will either empty or default.
   
   We want the data type of table_partition_cols a vector of Fields in the first place so when we need to store a Field, we won't lose any information.
   
   FYI: IOx needs this requirement.
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Replace data type of `FileScanConfig.table_partition_cols` from  `Vec<(String, DataType)>` to Vec<Field>`
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label
   -->
   
   The API to create `FileScanConfig` needs a vector of Fields for `table_partition_cols`. Most of the places it is an empty vector means it is not used.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: make data type of FileScanConfig.table_partition_cols a vector of Fields [arrow-datafusion]

Posted by "NGA-TRAN (via GitHub)" <gi...@apache.org>.
NGA-TRAN commented on code in PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890#discussion_r1367328822


##########
datafusion/core/src/datasource/physical_plan/file_scan_config.rs:
##########
@@ -135,8 +135,7 @@ impl FileScanConfig {
                 table_cols_stats.push(self.statistics.column_statistics[idx].clone())
             } else {
                 let partition_idx = idx - self.file_schema.fields().len();
-                let (name, dtype) = &self.table_partition_cols[partition_idx];
-                table_fields.push(Field::new(name, dtype.to_owned(), false));
+                table_fields.push(self.table_partition_cols[partition_idx].to_owned());

Review Comment:
   And this where we convert `table_partition_cols` to `Field`



##########
datafusion/core/src/datasource/physical_plan/file_scan_config.rs:
##########
@@ -101,7 +101,7 @@ pub struct FileScanConfig {
     /// all records after filtering are returned.
     pub limit: Option<usize>,
     /// The partitioning columns
-    pub table_partition_cols: Vec<(String, DataType)>,
+    pub table_partition_cols: Vec<Field>,

Review Comment:
   Here is the key change



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: make data type of FileScanConfig.table_partition_cols a vector of Fields [arrow-datafusion]

Posted by "NGA-TRAN (via GitHub)" <gi...@apache.org>.
NGA-TRAN commented on PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890#issuecomment-1773144755

   @alamb and @crepererum 
   Can you help review this? I do not have permission to set the label to `api-change`


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change `FileScanConfig.table_partition_cols` from `(String, DataType)` to `Field`s [arrow-datafusion]

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890#issuecomment-1774144983

   Thanks @NGA-TRAN 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: make data type of FileScanConfig.table_partition_cols a vector of Fields [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890#discussion_r1367442510


##########
datafusion/core/src/datasource/physical_plan/avro.rs:
##########
@@ -420,7 +420,11 @@ mod tests {
             statistics: Statistics::new_unknown(&file_schema),
             file_schema,
             limit: None,
-            table_partition_cols: vec![("date".to_owned(), DataType::Utf8)],
+            table_partition_cols: vec![Field::new(
+                "date".to_owned(),

Review Comment:
   ```suggestion
                   "date",
   ```



##########
datafusion/core/src/datasource/physical_plan/csv.rs:
##########
@@ -871,7 +871,8 @@ mod tests {
         let mut config = partitioned_csv_config(file_schema, file_groups)?;
 
         // Add partition columns
-        config.table_partition_cols = vec![("date".to_owned(), DataType::Utf8)];
+        config.table_partition_cols =
+            vec![Field::new("date".to_owned(), DataType::Utf8, false)];

Review Comment:
   ```suggestion
               vec![Field::new("date", DataType::Utf8, false)];
   ```



##########
datafusion/core/src/datasource/physical_plan/file_scan_config.rs:
##########
@@ -527,6 +526,38 @@ mod tests {
         assert_eq!(col_indices, None);
     }
 
+    #[test]
+    fn physical_plan_config_no_projection_tab_cols_as_field() {
+        let file_schema = aggr_test_schema();
+
+        // make a table_partition_col as a field
+        let table_partition_col = Field::new(
+            "date".to_owned(),

Review Comment:
   You don't have to call `to_owned()` here -- `Field::new` will do it for you
   
   ```suggestion
               "date",
   ```



##########
datafusion/core/src/datasource/physical_plan/file_scan_config.rs:
##########
@@ -748,6 +779,25 @@ mod tests {
         projection: Option<Vec<usize>>,
         statistics: Statistics,
         table_partition_cols: Vec<(String, DataType)>,
+    ) -> FileScanConfig {
+        let table_partition_cols = table_partition_cols
+            .iter()
+            .map(|(name, dtype)| Field::new(name, dtype.clone(), false))
+            .collect::<Vec<_>>();
+
+        config_for_proj_with_field_tab_part(
+            file_schema,
+            projection,
+            statistics,
+            table_partition_cols,
+        )
+    }
+
+    fn config_for_proj_with_field_tab_part(

Review Comment:
   I find this name confusing given the three letter abbreviations and I don't think this is common elsewhere in the DataFusion codebase. 
   
   How about something like
   
   ```suggestion
       fn config_for_projection_with_partition_fields(
   ```
   
   Or maybe instead you could change `config_for_projection` to take `table_partition_cols: Vec<Field>,` and make a function like
   
   ```rust
   /// Convert all 
   fn partition_cols(  table_partition_cols: Vec<(&str, DataType)>) -> Vec<Field> {
            table_partition_cols
               .iter()
               .map(|(name, dtype)| Field::new(name, dtype.clone(), false))
               .collect::<Vec<_>>()
   }
   ```
   
   
   And then convert the call sites of `config_for_projection` to be `config_for_projection(.., partition_cols(..))`
   



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change `FileScanConfig.table_partition_cols` from `(String, DataType)` to `Field`s [arrow-datafusion]

Posted by "NGA-TRAN (via GitHub)" <gi...@apache.org>.
NGA-TRAN commented on PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890#issuecomment-1773368141

   I have addressed all the comments. Thanks @alamb 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change `FileScanConfig.table_partition_cols` from `(String, DataType)` to `Field`s [arrow-datafusion]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890#discussion_r1367731053


##########
datafusion/core/src/datasource/physical_plan/file_scan_config.rs:
##########
@@ -101,7 +101,7 @@ pub struct FileScanConfig {
     /// all records after filtering are returned.
     pub limit: Option<usize>,
     /// The partitioning columns
-    pub table_partition_cols: Vec<(String, DataType)>,
+    pub table_partition_cols: Vec<Field>,

Review Comment:
   You probably want to use FieldRef not Field



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change `FileScanConfig.table_partition_cols` from `(String, DataType)` to `Field`s [arrow-datafusion]

Posted by "NGA-TRAN (via GitHub)" <gi...@apache.org>.
NGA-TRAN commented on code in PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890#discussion_r1367465199


##########
datafusion/core/src/datasource/physical_plan/file_scan_config.rs:
##########
@@ -748,6 +779,25 @@ mod tests {
         projection: Option<Vec<usize>>,
         statistics: Statistics,
         table_partition_cols: Vec<(String, DataType)>,
+    ) -> FileScanConfig {
+        let table_partition_cols = table_partition_cols
+            .iter()
+            .map(|(name, dtype)| Field::new(name, dtype.clone(), false))
+            .collect::<Vec<_>>();
+
+        config_for_proj_with_field_tab_part(
+            file_schema,
+            projection,
+            statistics,
+            table_partition_cols,
+        )
+    }
+
+    fn config_for_proj_with_field_tab_part(

Review Comment:
   I implemented your second suggestion @alamb . Thanks



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change `FileScanConfig.table_partition_cols` from `(String, DataType)` to `Field`s [arrow-datafusion]

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan merged PR #7890:
URL: https://github.com/apache/arrow-datafusion/pull/7890


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org