You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/20 15:53:01 UTC

[GitHub] [arrow-datafusion] thinkharderdev opened a new pull request, #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

thinkharderdev opened a new pull request, #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946

   # 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 #.
   
    # 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.  
   -->
   
   Add a configurable size hint to `ParquetFormat` to allow fetching metadata without multiple seeks. This is not set by default. If it is configured, the `ParquetFileReader` will read `metadata_size_hint` bytes from the end of the parquet file and then fetch additional data only if the metadata is more than `metadata_size_hint` 
   
   # 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.
   -->
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   Both `ParquetFormat` and `ParquetExec` can not take an optional `metadata_size_hint`. 
   
   <!--
   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@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946#issuecomment-1190618421

   I have filed https://github.com/apache/arrow-datafusion/issues/2947 to track the CI failure


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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946#discussion_r925976720


##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -567,6 +575,90 @@ mod tests {
         Ok(())
     }
 
+    #[derive(Debug)]
+    struct RequestCountingObjectStore {

Review Comment:
   ❤️ 



##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -577,46 +669,74 @@ mod tests {
         let batch1 = RecordBatch::try_from_iter(vec![("c1", c1.clone())]).unwrap();
         let batch2 = RecordBatch::try_from_iter(vec![("c2", c2)]).unwrap();
 
-        let store = Arc::new(LocalFileSystem::new()) as _;
+        let store = Arc::new(RequestCountingObjectStore::new(Arc::new(
+            LocalFileSystem::new(),
+        )));
         let (meta, _files) = store_parquet(vec![batch1, batch2]).await?;
 
         // Use a size hint larger than the parquet footer but smaller than the actual metadata, requiring a second fetch
         // for the remaining metadata
-        let format = ParquetFormat::default().with_metadata_size_hint(9);
-        let schema = format.infer_schema(&store, &meta).await.unwrap();
-
-        fetch_parquet_metadata(store.as_ref(), &meta[0], Some(9))
+        fetch_parquet_metadata(store.as_ref() as &dyn ObjectStore, &meta[0], Some(9))
             .await
             .expect("error reading metadata with hint");
 
+        assert_eq!(store.request_count(), 2);
+
+        let format = ParquetFormat::default().with_metadata_size_hint(9);
+        let schema = format.infer_schema(&store.upcast(), &meta).await.unwrap();
+
         let stats =
-            fetch_statistics(store.as_ref(), schema.clone(), &meta[0], Some(9)).await?;
+            fetch_statistics(store.upcast().as_ref(), schema.clone(), &meta[0], Some(9))
+                .await?;
 
         assert_eq!(stats.num_rows, Some(3));
         let c1_stats = &stats.column_statistics.as_ref().expect("missing c1 stats")[0];
         let c2_stats = &stats.column_statistics.as_ref().expect("missing c2 stats")[1];
         assert_eq!(c1_stats.null_count, Some(1));
         assert_eq!(c2_stats.null_count, Some(3));
 
+        let store = Arc::new(RequestCountingObjectStore::new(Arc::new(
+            LocalFileSystem::new(),
+        )));
+
         // Use the file size as the hint so we can get the full metadata from the first fetch
         let size_hint = meta[0].size;
-        let format = ParquetFormat::default().with_metadata_size_hint(size_hint);
-        let schema = format.infer_schema(&store, &meta).await.unwrap();
 
-        fetch_parquet_metadata(store.as_ref(), &meta[0], Some(size_hint))
+        fetch_parquet_metadata(store.upcast().as_ref(), &meta[0], Some(size_hint))
             .await
             .expect("error reading metadata with hint");
 
-        let stats =
-            fetch_statistics(store.as_ref(), schema.clone(), &meta[0], Some(size_hint))
-                .await?;
+        assert_eq!(store.request_count(), 1);

Review Comment:
   ```suggestion
           // ensure the requests were coalesced into a single request
           assert_eq!(store.request_count(), 1);
   ```



##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -577,46 +669,74 @@ mod tests {
         let batch1 = RecordBatch::try_from_iter(vec![("c1", c1.clone())]).unwrap();
         let batch2 = RecordBatch::try_from_iter(vec![("c2", c2)]).unwrap();
 
-        let store = Arc::new(LocalFileSystem::new()) as _;
+        let store = Arc::new(RequestCountingObjectStore::new(Arc::new(
+            LocalFileSystem::new(),
+        )));
         let (meta, _files) = store_parquet(vec![batch1, batch2]).await?;
 
         // Use a size hint larger than the parquet footer but smaller than the actual metadata, requiring a second fetch
         // for the remaining metadata
-        let format = ParquetFormat::default().with_metadata_size_hint(9);
-        let schema = format.infer_schema(&store, &meta).await.unwrap();
-
-        fetch_parquet_metadata(store.as_ref(), &meta[0], Some(9))
+        fetch_parquet_metadata(store.as_ref() as &dyn ObjectStore, &meta[0], Some(9))
             .await
             .expect("error reading metadata with hint");
 
+        assert_eq!(store.request_count(), 2);
+
+        let format = ParquetFormat::default().with_metadata_size_hint(9);
+        let schema = format.infer_schema(&store.upcast(), &meta).await.unwrap();
+
         let stats =
-            fetch_statistics(store.as_ref(), schema.clone(), &meta[0], Some(9)).await?;
+            fetch_statistics(store.upcast().as_ref(), schema.clone(), &meta[0], Some(9))
+                .await?;
 
         assert_eq!(stats.num_rows, Some(3));
         let c1_stats = &stats.column_statistics.as_ref().expect("missing c1 stats")[0];
         let c2_stats = &stats.column_statistics.as_ref().expect("missing c2 stats")[1];
         assert_eq!(c1_stats.null_count, Some(1));
         assert_eq!(c2_stats.null_count, Some(3));
 
+        let store = Arc::new(RequestCountingObjectStore::new(Arc::new(
+            LocalFileSystem::new(),
+        )));
+
         // Use the file size as the hint so we can get the full metadata from the first fetch
         let size_hint = meta[0].size;
-        let format = ParquetFormat::default().with_metadata_size_hint(size_hint);
-        let schema = format.infer_schema(&store, &meta).await.unwrap();
 
-        fetch_parquet_metadata(store.as_ref(), &meta[0], Some(size_hint))
+        fetch_parquet_metadata(store.upcast().as_ref(), &meta[0], Some(size_hint))
             .await
             .expect("error reading metadata with hint");
 
-        let stats =
-            fetch_statistics(store.as_ref(), schema.clone(), &meta[0], Some(size_hint))
-                .await?;
+        assert_eq!(store.request_count(), 1);

Review Comment:
   👍 



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


[GitHub] [arrow-datafusion] thinkharderdev commented on pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
thinkharderdev commented on PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946#issuecomment-1190573123

   Build failure seems to be infra related: `note: /usr/bin/ld: final link failed: No space left on device`


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


[GitHub] [arrow-datafusion] alamb merged pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
alamb merged PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946


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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946#discussion_r925942388


##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -316,17 +352,34 @@ pub(crate) async fn fetch_parquet_metadata(
         )));
     }
 
-    let metadata_start = meta.size - length - 8;
-    let metadata = store
-        .get_range(&meta.location, metadata_start..footer_start)
-        .await?;
+    if length > suffix_len - 8 {

Review Comment:
   ```suggestion
       // Did not fetch the entire file metadata in the initial read, need to make a second request
       if length > suffix_len - 8 {
   ```
   



##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -509,6 +564,59 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn fetch_metadata_with_size_hint() -> Result<()> {
+        let c1: ArrayRef =
+            Arc::new(StringArray::from(vec![Some("Foo"), None, Some("bar")]));
+
+        let c2: ArrayRef = Arc::new(Int64Array::from(vec![Some(1), Some(2), None]));
+
+        let batch1 = RecordBatch::try_from_iter(vec![("c1", c1.clone())]).unwrap();
+        let batch2 = RecordBatch::try_from_iter(vec![("c2", c2)]).unwrap();
+
+        let store = Arc::new(LocalFileSystem::new()) as _;
+        let (meta, _files) = store_parquet(vec![batch1, batch2]).await?;
+
+        // Use a size hint larger than the parquet footer but smaller than the actual metadata, requiring a second fetch
+        // for the remaining metadata
+        let format = ParquetFormat::default().with_metadata_size_hint(9);
+        let schema = format.infer_schema(&store, &meta).await.unwrap();
+
+        fetch_parquet_metadata(store.as_ref(), &meta[0], Some(9))
+            .await
+            .expect("error reading metadata with hint");
+
+        let stats =
+            fetch_statistics(store.as_ref(), schema.clone(), &meta[0], Some(9)).await?;
+
+        assert_eq!(stats.num_rows, Some(3));
+        let c1_stats = &stats.column_statistics.as_ref().expect("missing c1 stats")[0];
+        let c2_stats = &stats.column_statistics.as_ref().expect("missing c2 stats")[1];
+        assert_eq!(c1_stats.null_count, Some(1));
+        assert_eq!(c2_stats.null_count, Some(3));
+
+        // Use the file size as the hint so we can get the full metadata from the first fetch

Review Comment:
   I wonder if there is any way to test that there was a single request made to the object store as well 🤔 



##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -298,13 +327,20 @@ pub(crate) async fn fetch_parquet_metadata(
         )));
     }
 
-    let footer_start = meta.size - 8;
+    let footer_start = if let Some(size_hint) = size_hint {

Review Comment:
   ```suggestion
       // If a size hint is provided, read more than the minimum size 
       // to try and avoid a second fetch.
       let footer_start = if let Some(size_hint) = size_hint {
   ```



##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -298,13 +327,20 @@ pub(crate) async fn fetch_parquet_metadata(
         )));
     }
 
-    let footer_start = meta.size - 8;
+    let footer_start = if let Some(size_hint) = size_hint {
+        meta.size - size_hint

Review Comment:
   What happens if size_hit is larger than the file size?
   
   Maybe we could used `saturating_sub` here instead: https://doc.rust-lang.org/std/primitive.usize.html#method.saturating_sub



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


[GitHub] [arrow-datafusion] ursabot commented on pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946#issuecomment-1191321220

   Benchmark runs are scheduled for baseline = b49093c7428057ec157d14b0808b171804177a49 and contender = 834924f274d9e04444030b8eb3e07e1035fcd3cf. 834924f274d9e04444030b8eb3e07e1035fcd3cf is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/5c50ce90fcc8497ebc4fe96b7145654e...759c36e1ccc04f0e89d75fed449ff70b/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/694f4b10ed9d48bdaa0257e1ec398099...da5e27ff50234491bd91b3c5ad86a879/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/8ff564b908444793b539bda09e48247a...0bc2a9eff3d84be39809543f2130e854/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/33258172a423469ea670bcc02702c411...355b3fb630204a61a7b3ff422c65c011/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


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


[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946#issuecomment-1190751918

   # [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2946?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#2946](https://codecov.io/gh/apache/arrow-datafusion/pull/2946?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d027f16) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/b49093c7428057ec157d14b0808b171804177a49?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b49093c) will **decrease** coverage by `0.00%`.
   > The diff coverage is `83.19%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #2946      +/-   ##
   ==========================================
   - Coverage   85.43%   85.42%   -0.01%     
   ==========================================
     Files         275      275              
     Lines       49739    49839     +100     
   ==========================================
   + Hits        42495    42576      +81     
   - Misses       7244     7263      +19     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/2946?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...afusion/core/src/datasource/file\_format/parquet.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2946/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9kYXRhc291cmNlL2ZpbGVfZm9ybWF0L3BhcnF1ZXQucnM=) | `85.02% <80.95%> (-1.52%)` | :arrow_down: |
   | [...afusion/core/src/physical\_optimizer/repartition.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2946/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9vcHRpbWl6ZXIvcmVwYXJ0aXRpb24ucnM=) | `100.00% <100.00%> (ø)` | |
   | [...sion/core/src/physical\_plan/file\_format/parquet.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2946/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9wbGFuL2ZpbGVfZm9ybWF0L3BhcnF1ZXQucnM=) | `95.00% <100.00%> (+0.08%)` | :arrow_up: |
   | [datafusion/expr/src/logical\_plan/plan.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2946/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy9sb2dpY2FsX3BsYW4vcGxhbi5ycw==) | `77.14% <0.00%> (-0.18%)` | :arrow_down: |
   | [datafusion/core/src/physical\_plan/metrics/value.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2946/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9wbGFuL21ldHJpY3MvdmFsdWUucnM=) | `86.93% <0.00%> (+0.50%)` | :arrow_up: |
   
   


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


[GitHub] [arrow-datafusion] alamb commented on pull request #2946: Add metadata_size_hint for optimistic fetching of parquet metadata

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2946:
URL: https://github.com/apache/arrow-datafusion/pull/2946#issuecomment-1190667986

   I think if you rebase from master to pick up https://github.com/apache/arrow-datafusion/pull/2948 your CI should pass cleanly


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