You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "fpetkovski (via GitHub)" <gi...@apache.org> on 2026/05/19 10:32:23 UTC

[PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

fpetkovski opened a new pull request, #22360:
URL: https://github.com/apache/datafusion/pull/22360

   ## 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/datafusion/issues/22200.
   
   ## 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.  
   -->
   
   As described in the linked issue, parsing the arrow schema from parquet metadata can be expensive for point lookups, relative to the rest of the query execution pipeline. If the user knows the arrow schema of the file, they should be able to specify it explicitly.
   
   ## 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.
   -->
   
   * Add a `arrow_schema: SchemaRef` field to `PartitionedFile` 
   * Use the `arrow_schema` field in the parquet opener to bypass schema inference from the `ARROW:schema` metadata field.
   
   ## Are these changes tested?
   
   Added unit tests for both matching and mismatching schemas.
   
   <!--
   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?
   
   There are no breaking changes, the new field is optional and is set to None by default.
   
   <!--
   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.
   -->
   


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

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

   Sounds good @fpetkovski  -- thank you


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

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

   Thank you @kosiew for the review


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

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

   Thanks @alamb I addressed both of your comments. I am happy to follow up with an example, need to get familiar with the patterns that are used there first.


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #22360:
URL: https://github.com/apache/datafusion/pull/22360#issuecomment-4573076003

   <!-- semver-check-comment -->
   Thank you for opening this pull request!
   
   Reviewer note: [cargo-semver-checks](https://github.com/obi1kenobi/cargo-semver-checks) reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).
   
   <details>
   <summary>Details</summary>
   
   ```
        Cloning apache/main
       Building datafusion-catalog-listing v53.1.0 (current)
          Built [  42.234s] (current)
        Parsing datafusion-catalog-listing v53.1.0 (current)
         Parsed [   0.014s] (current)
       Building datafusion-catalog-listing v53.1.0 (baseline)
          Built [  41.159s] (baseline)
        Parsing datafusion-catalog-listing v53.1.0 (baseline)
         Parsed [   0.012s] (baseline)
       Checking datafusion-catalog-listing v53.1.0 -> v53.1.0 (no change; assume patch)
        Checked [   0.089s] 222 checks: 222 pass, 30 skip
        Summary no semver update required
       Finished [ 104.510s] datafusion-catalog-listing
       Building datafusion-datasource v53.1.0 (current)
          Built [  34.876s] (current)
        Parsing datafusion-datasource v53.1.0 (current)
         Parsed [   0.030s] (current)
       Building datafusion-datasource v53.1.0 (baseline)
          Built [  35.099s] (baseline)
        Parsing datafusion-datasource v53.1.0 (baseline)
         Parsed [   0.031s] (baseline)
       Checking datafusion-datasource v53.1.0 -> v53.1.0 (no change; assume patch)
        Checked [   0.235s] 222 checks: 221 pass, 1 fail, 0 warn, 30 skip
   
   --- failure constructible_struct_adds_field: externally-constructible struct adds field ---
   
   Description:
   A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
           ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
          impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/constructible_struct_adds_field.ron
   
   Failed in:
     field PartitionedFile.arrow_schema in /home/runner/work/datafusion/datafusion/datafusion/datasource/src/mod.rs:176
   
        Summary semver requires new major version: 1 major and 0 minor checks failed
       Finished [  71.833s] datafusion-datasource
       Building datafusion-datasource-parquet v53.1.0 (current)
          Built [  41.041s] (current)
        Parsing datafusion-datasource-parquet v53.1.0 (current)
         Parsed [   0.028s] (current)
       Building datafusion-datasource-parquet v53.1.0 (baseline)
          Built [  41.495s] (baseline)
        Parsing datafusion-datasource-parquet v53.1.0 (baseline)
         Parsed [   0.030s] (baseline)
       Checking datafusion-datasource-parquet v53.1.0 -> v53.1.0 (no change; assume patch)
        Checked [   0.161s] 222 checks: 222 pass, 30 skip
        Summary no semver update required
       Finished [  84.444s] datafusion-datasource-parquet
       Building datafusion-proto v53.1.0 (current)
          Built [  55.980s] (current)
        Parsing datafusion-proto v53.1.0 (current)
         Parsed [   0.018s] (current)
       Building datafusion-proto v53.1.0 (baseline)
          Built [  55.779s] (baseline)
        Parsing datafusion-proto v53.1.0 (baseline)
         Parsed [   0.019s] (baseline)
       Checking datafusion-proto v53.1.0 -> v53.1.0 (no change; assume patch)
        Checked [   0.251s] 222 checks: 222 pass, 30 skip
        Summary no semver update required
       Finished [ 113.604s] datafusion-proto
       Building datafusion-proto-models v53.1.0 (current)
          Built [  23.366s] (current)
        Parsing datafusion-proto-models v53.1.0 (current)
         Parsed [   0.138s] (current)
       Building datafusion-proto-models v53.1.0 (baseline)
          Built [  23.407s] (baseline)
        Parsing datafusion-proto-models v53.1.0 (baseline)
         Parsed [   0.121s] (baseline)
       Checking datafusion-proto-models v53.1.0 -> v53.1.0 (no change; assume patch)
        Checked [   1.610s] 222 checks: 221 pass, 1 fail, 0 warn, 30 skip
   
   --- failure constructible_struct_adds_field: externally-constructible struct adds field ---
   
   Description:
   A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
           ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
          impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/constructible_struct_adds_field.ron
   
   Failed in:
     field PartitionedFile.arrow_schema in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2138
     field PartitionedFile.arrow_schema in /home/runner/work/datafusion/datafusion/datafusion/proto-models/src/generated/prost.rs:2138
   
        Summary semver requires new major version: 1 major and 0 minor checks failed
       Finished [  49.953s] datafusion-proto-models
   ```
   
   </details>


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

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


##########
datafusion/datasource-parquet/src/opener/mod.rs:
##########
@@ -713,8 +713,14 @@ impl PreparedParquetOpen {
         // unnecessary I/O. We decide later if it is needed to evaluate the
         // pruning predicates. Thus default to not requesting it from the
         // underlying reader.
-        let options =
-            ArrowReaderOptions::new().with_page_index_policy(PageIndexPolicy::Skip);
+        let options = {
+            let mut options =
+                ArrowReaderOptions::new().with_page_index_policy(PageIndexPolicy::Skip);
+            if let Some(schema) = self.partitioned_file.arrow_schema.as_ref() {
+                options = options.with_schema(schema.to_owned());

Review Comment:
   I also think the `to_owned()` call is a non standard way of cloning a schema
   
   ```rust
                   options = options.with_schema(schema.to_owned());
   ```
   
   I think the more standard / explicit way is
   
   ```rust
               options = options.with_schema(Arc::clone(schema));
   ```
   



##########
datafusion/datasource-parquet/src/opener/mod.rs:
##########
@@ -713,8 +713,14 @@ impl PreparedParquetOpen {
         // unnecessary I/O. We decide later if it is needed to evaluate the
         // pruning predicates. Thus default to not requesting it from the
         // underlying reader.
-        let options =
-            ArrowReaderOptions::new().with_page_index_policy(PageIndexPolicy::Skip);
+        let options = {
+            let mut options =
+                ArrowReaderOptions::new().with_page_index_policy(PageIndexPolicy::Skip);
+            if let Some(schema) = self.partitioned_file.arrow_schema.as_ref() {
+                options = options.with_schema(schema.to_owned());
+            }
+            options
+        };

Review Comment:
   I think this could be collapsed / simplified:
   
   ```suggestion
           let mut options = ArrowReaderOptions::new().with_page_index_policy(PageIndexPolicy::Skip);
           if let Some(schema) = self.partitioned_file.arrow_schema.as_ref() {
               options = options.with_schema(schema.to_owned());
           }
   ```



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #22360:
URL: https://github.com/apache/datafusion/pull/22360#discussion_r3303215096


##########
datafusion/datasource/src/mod.rs:
##########
@@ -163,12 +164,15 @@ pub struct PartitionedFile {
     /// The estimated size of the parquet metadata, in bytes
     pub metadata_size_hint: Option<usize>,
     pub table_reference: Option<TableReference>,
+    /// A user-provided arrow schema for the file.
+    pub arrow_schema: Option<SchemaRef>,

Review Comment:
   I think this needs a follow-up before merge. `PartitionedFile::arrow_schema` introduces a new user-provided scan contract, but physical plan proto serialization currently appears to drop it. `datafusion/proto/src/physical_plan/to_proto.rs` builds `protobuf::PartitionedFile` without this field, and `datafusion/proto/proto/datafusion.proto` does not seem to have a schema field for it.
   
   As a result, a Parquet scan that is serialized and deserialized would lose the explicit schema and fall back to parsing `ARROW:schema`, so the main guarantee from this change would not hold end to end.
   
   Could you please add this field to the proto model and conversions, plus a roundtrip test showing that `PartitionedFile::with_arrow_schema(...)` survives physical plan or `PartitionedFile` proto serialization?



##########
datafusion/datasource/src/mod.rs:
##########
@@ -163,12 +164,15 @@ pub struct PartitionedFile {
     /// The estimated size of the parquet metadata, in bytes
     pub metadata_size_hint: Option<usize>,
     pub table_reference: Option<TableReference>,
+    /// A user-provided arrow schema for the file.

Review Comment:
   Small doc suggestion: it would be helpful to make the public contract a bit more precise here. My read is that this is the physical Arrow file schema used by the Parquet opener, it should describe file columns rather than partition columns, and it is currently ignored by non-Parquet sources.
   
   Calling that out explicitly should help avoid users passing a table schema that includes partitions, or expecting CSV and JSON readers to honor this 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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

Posted by "fpetkovski (via GitHub)" <gi...@apache.org>.
fpetkovski commented on code in PR #22360:
URL: https://github.com/apache/datafusion/pull/22360#discussion_r3303629412


##########
datafusion/datasource/src/mod.rs:
##########
@@ -163,12 +164,15 @@ pub struct PartitionedFile {
     /// The estimated size of the parquet metadata, in bytes
     pub metadata_size_hint: Option<usize>,
     pub table_reference: Option<TableReference>,
+    /// A user-provided arrow schema for the file.
+    pub arrow_schema: Option<SchemaRef>,

Review Comment:
   Thanks, I updated the protos to serialize and deserialize the file arrow schema as well. There is a proto test now which verifies the round trip.



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

Posted by "fpetkovski (via GitHub)" <gi...@apache.org>.
fpetkovski commented on code in PR #22360:
URL: https://github.com/apache/datafusion/pull/22360#discussion_r3303627118


##########
datafusion/datasource/src/mod.rs:
##########
@@ -163,12 +164,15 @@ pub struct PartitionedFile {
     /// The estimated size of the parquet metadata, in bytes
     pub metadata_size_hint: Option<usize>,
     pub table_reference: Option<TableReference>,
+    /// A user-provided arrow schema for the file.

Review Comment:
   Thanks for the suggestion, I updated the docs to clarify how this field is used by various openers.



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Allow specifying an arrow schema for PartitionedFile [datafusion]

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


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org