You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "korowa (via GitHub)" <gi...@apache.org> on 2023/01/25 13:04:18 UTC
[GitHub] [arrow-datafusion] korowa opened a new pull request, #5057: Parquet parallel scan
korowa opened a new pull request, #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057
# 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 #137.
# 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.
-->
Improved performance for reading single parquet file / parquet files in quantity less than number of cores / parquet files having significant variation in size in multicore runtime
# 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.
-->
1) `parallel_file_scan` execution setting - by default false, when true - file scan operations parallelized for Parquet files
2) `FormatScanMetadata` - container for format-specific metadata required for planning/optimizing scans. It seemed to be reasonable to calculate file ranges along with statistics, and avoid additional metadata fetch. Returned by `FileFormat` method `fetch_format_scan_metadata` (replacement for `infer_stats`)
3) `FormatScanMetadataCache` - replacement for `StatisticsCache` - appeared for the same reason `FormatScanMetadata` was introduced. Listing options are not available from outside, and there are no methods for their modification, so simply caching metadata object retrieved from `fetch_format_scan_metadata` method seems to be safe.
4) `split_files` - now performed over tuples of (`PartitionedFile`, `FileRanges`) and handle them as a basic unit for Scan
# 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)?
-->
Tests for `fetch_format_scan_metadata` and `split_files` added.
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
New configuration setting `parallel_file_scan`
<!--
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] korowa commented on a diff in pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1088846541
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -686,24 +729,6 @@ mod tests {
Ok(())
}
Review Comment:
By accident, now it's back
--
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] korowa commented on pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1407412469
> I would like to explore turning this feature on by default (perhaps we can have a separate ticket to track that)
I don't mind enabling parallelism by default and it seems to be the fastest way to deliver this feature, but (I'm not sure, just a suggestion) maybe better time for this will be in 1 (or 2) releases after the setting itself will be released?
--
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] korowa commented on pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1411613642
> So `PartitionedFile ` range is not used for fetch bytes from objectStore, finally we use rowgroup start, offset to fetch bytest ? am i right?
Yeah, I can't find any places where range is used, except for row_group pruning
--
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 #5057: Parquet parallel scan
Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1409212667
Benchmark runs are scheduled for baseline = 74b05fa0879f4c1aecf9917d86c70db7680920d7 and contender = 67b1da8a71397185a49a6418af3e1cfe9329f6c5. 67b1da8a71397185a49a6418af3e1cfe9329f6c5 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/d103f18a5af84e9fa0326841e18caa99...84bafda948b64e47b80ab599089a0940/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/1e0153f0178340fb87d5909f0ba55784...36959ad729e74d29928ff77b104a870c/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/dbad4459a33e4648bdc44033eb142b3b...06bcd719db4d4726ad811a0b00760ccf/)
[Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/1ad4a287693a4dab9b71bea8731fac86...b61d4b93671048b38191e7ac1f8e0977/)
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] korowa commented on pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1410398875
@mingmwang here is the [exact place](https://github.com/apache/arrow-datafusion/blob/125a8580c19c78c99fbbe3a6afe373de2538b205/datafusion/core/src/physical_plan/file_format/parquet/row_groups.rs#L57) where DF decides to read/not too read RowGroup depending on range.
--
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] tustvold commented on a diff in pull request #5057: Parquet parallel scan
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1088827017
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -686,24 +729,6 @@ mod tests {
Ok(())
}
Review Comment:
Why has this been removed?
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -846,6 +871,182 @@ mod tests {
Ok(())
}
+ #[test]
Review Comment:
Love the test coverage
##########
datafusion/core/src/physical_plan/file_format/parquet.rs:
##########
@@ -232,6 +241,74 @@ impl ParquetExec {
self.enable_page_index
.unwrap_or(config_options.execution.parquet.enable_page_index)
}
+
+ /// Redistribute files across partitions according to their size
+ pub fn get_repartitioned(&self, target_partitions: usize) -> Self {
+ // Perform redistribution only in case all files should be read from beginning to end
+ let has_ranges = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .any(|f| f.range.is_some());
+ if has_ranges {
+ return self.clone();
+ }
+
+ let total_size = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .map(|f| f.object_meta.size as i64)
+ .sum::<i64>();
+ let target_partition_size =
Review Comment:
I think we should probably have a minimum file range, anything less than 10MB is unlikely to yield additional parallelism, as row groups shouldn't be this small, and adding more partitions is not necessarily free.
We could make this configurable
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1089724193
##########
datafusion/common/src/config.rs:
##########
@@ -261,10 +261,17 @@ config_namespace! {
/// in parallel using the provided `target_partitions` level"
pub repartition_aggregations: bool, default = true
+ /// Minimum total files size in bytes to perform file scan repartitioning.
+ pub repartition_file_min_size: usize, default = 10 * 1024 * 1024
+
/// Should DataFusion repartition data using the join keys to execute joins in parallel
/// using the provided `target_partitions` level"
pub repartition_joins: bool, default = true
+ /// When set to true, file groups will be repartitioned to achieve maximum parallelism.
+ /// Currently supported only for Parquet format
Review Comment:
```suggestion
/// When set to true, file groups will be repartitioned to achieve maximum parallelism.
/// Currently supported only for Parquet format in which case
/// multiple row groups from the same file may be read concurrently. If false then each
/// row group is read serially, though different files may be read in parallel.
```
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -846,6 +897,182 @@ mod tests {
Ok(())
}
+ #[test]
+ fn parallelization_single_partition() -> Result<()> {
+ let plan = aggregate(parquet_exec());
+
+ let expected = [
+ "AggregateExec: mode=Final, gby=[], aggr=[]",
+ "CoalescePartitionsExec",
+ "AggregateExec: mode=Partial, gby=[], aggr=[]",
+ "ParquetExec: limit=None, partitions={2 groups: [[x:0..50], [x:50..100]]}, projection=[c1]",
+ ];
+
+ assert_optimized!(expected, plan, 2, true, 10);
+ Ok(())
+ }
+
+ #[test]
+ fn parallelization_two_partitions() -> Result<()> {
+ let plan = aggregate(parquet_exec_two_partitions());
+
+ let expected = [
+ "AggregateExec: mode=Final, gby=[], aggr=[]",
+ "CoalescePartitionsExec",
+ "AggregateExec: mode=Partial, gby=[], aggr=[]",
+ // Plan already has two partitions
+ "ParquetExec: limit=None, partitions={2 groups: [[x], [y]]}, projection=[c1]",
+ ];
+
+ assert_optimized!(expected, plan, 2, true, 10);
+ Ok(())
+ }
Review Comment:
I suggest one more case that shows a plan bring repartitioned even if it has multiple files
For example, `parquet_exec_two_partitions` with `target_partitions = 4`
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -448,10 +493,16 @@ mod tests {
/// Runs the repartition optimizer and asserts the plan against the expected
macro_rules! assert_optimized {
($EXPECTED_LINES: expr, $PLAN: expr) => {
+ assert_optimized!($EXPECTED_LINES, $PLAN, 10, false, 1024);
+ };
+
+ ($EXPECTED_LINES: expr, $PLAN: expr, $TAGRET_PARTITIONS: expr, $REPARTITION_FILE_SCANS: expr, $REPARTITION_FILE_MIN_SIZE: expr) => {
let expected_lines: Vec<&str> = $EXPECTED_LINES.iter().map(|s| *s).collect();
let mut config = ConfigOptions::new();
- config.execution.target_partitions = 10;
+ config.execution.target_partitions = $TAGRET_PARTITIONS;
Review Comment:
```suggestion
config.execution.target_partitions = $TARGET_PARTITIONS;
```
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -448,10 +493,16 @@ mod tests {
/// Runs the repartition optimizer and asserts the plan against the expected
macro_rules! assert_optimized {
($EXPECTED_LINES: expr, $PLAN: expr) => {
+ assert_optimized!($EXPECTED_LINES, $PLAN, 10, false, 1024);
+ };
+
+ ($EXPECTED_LINES: expr, $PLAN: expr, $TAGRET_PARTITIONS: expr, $REPARTITION_FILE_SCANS: expr, $REPARTITION_FILE_MIN_SIZE: expr) => {
Review Comment:
```suggestion
($EXPECTED_LINES: expr, $PLAN: expr, $TARGET_PARTITIONS: expr, $REPARTITION_FILE_SCANS: expr, $REPARTITION_FILE_MIN_SIZE: expr) => {
```
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1407063479
I plan to review this carefully either later today or tomorrow. Very exciting @korowa -- 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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] korowa commented on pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1407400414
I have only these in my notes
```
// Single partition
./target/release/examples/clickbench 4.10s user 0.59s system 113% cpu 4.142 total
./target/release/examples/clickbench 4.14s user 0.56s system 136% cpu 3.451 total
./target/release/examples/clickbench 4.13s user 0.55s system 135% cpu 3.446 total
./target/release/examples/clickbench 4.29s user 0.55s system 134% cpu 3.603 total
// Multiple partition
./target/release/examples/clickbench 5.32s user 0.96s system 288% cpu 2.174 total
./target/release/examples/clickbench 5.14s user 0.89s system 392% cpu 1.534 total
./target/release/examples/clickbench 5.24s user 0.92s system 405% cpu 1.517 total
./target/release/examples/clickbench 5.14s user 0.91s system 399% cpu 1.516 total
./target/release/examples/clickbench 5.23s user 0.92s system 405% cpu 1.518 total
```
which doesn't look like "official" benchmark at all. These are results for [this query from clickbench](https://github.com/ClickHouse/ClickBench/blob/main/datafusion/queries.sql#L26) over 14GB parquet file on 2.6 GHz 6-Core Intel Core i7
--
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] tustvold commented on pull request #5057: Parquet parallel scan
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1404027622
Only had time to take a brief look at this PR, and so I'm likely missing something but please bear with me :smile:
This PR modifies `ListingTable` to pair together `PartitionedFile` with `Vec<Option<FileRange>>`, this makes this approach specific to `ListingTable` and also adds parallelism control to a part of the system that doesn't really have context on how much parallelism is needed, nor what invariants such as sort orders may need to be upheld.
I have two suggestions that may be stupid:
* Make this a physical optimizer rule that looks at operators containing `FileScanConfig` and adds more partitions based on the `target_partitions` property
* Rather than adding a new `FileRanges` property, instead using the existing `range: Option<FileRange>` already present on `PartitionedFile`, the same file with disjoint ranges can then appear in multiple partitions
--
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] korowa commented on a diff in pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1089232836
##########
datafusion/core/src/physical_plan/file_format/parquet.rs:
##########
@@ -232,6 +241,74 @@ impl ParquetExec {
self.enable_page_index
.unwrap_or(config_options.execution.parquet.enable_page_index)
}
+
+ /// Redistribute files across partitions according to their size
+ pub fn get_repartitioned(&self, target_partitions: usize) -> Self {
+ // Perform redistribution only in case all files should be read from beginning to end
+ let has_ranges = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .any(|f| f.range.is_some());
+ if has_ranges {
+ return self.clone();
+ }
+
+ let total_size = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .map(|f| f.object_meta.size as i64)
+ .sum::<i64>();
+ let target_partition_size =
Review Comment:
After some thoughts, I see that it could be just more user-friendly -- cause this setting will care about preventing unnecessary file splits without any additional parameters tweaking efforts.
I've also moved both of these new settings from `execution` to `optimizer` section.
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1089766053
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -928,6 +928,22 @@ mod tests {
Ok(())
}
+ #[test]
+ fn parallelization_two_partitions_into_four() -> Result<()> {
+ let plan = aggregate(parquet_exec_two_partitions());
+
+ let expected = [
+ "AggregateExec: mode=Final, gby=[], aggr=[]",
+ "CoalescePartitionsExec",
+ "AggregateExec: mode=Partial, gby=[], aggr=[]",
+ // Multiple source files splitted across partitions
+ "ParquetExec: limit=None, partitions={4 groups: [[x:0..75], [x:75..100, y:0..50], [y:50..125], [y:125..200]]}, projection=[c1]",
Review Comment:
that is quite clever that the partitions have different parts of the same file 👍
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057
--
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] korowa commented on pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1404084910
@tustvold , thank you for the comments!
Initially my intention was to handle scan planning as early as possible, so `ListingTable` looked like proper place for this - it actually holds parallelism settings in `options` attribute, and fetches required metadata.
But, yeah, now I see that physical optimizer, and especially its `repartitioning` rule is much better suited for repatitioning ParquetExec 🤔 .
I guess I'll convert this PR to draft and come up a bit later with updated version of this optimizer rule.
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1409202911
Thanks again @korowa ❤️
--
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] korowa commented on pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1406289008
I've reworked this PR by utilizing `repartition` rule, and updated the description -- it looks way more simple now, and, what's more important, it takes into account any plan-related restrictions for ParquetExec.
@tustvold, thank you for the tip about using physical optimizer!
--
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] korowa commented on a diff in pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1089232836
##########
datafusion/core/src/physical_plan/file_format/parquet.rs:
##########
@@ -232,6 +241,74 @@ impl ParquetExec {
self.enable_page_index
.unwrap_or(config_options.execution.parquet.enable_page_index)
}
+
+ /// Redistribute files across partitions according to their size
+ pub fn get_repartitioned(&self, target_partitions: usize) -> Self {
+ // Perform redistribution only in case all files should be read from beginning to end
+ let has_ranges = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .any(|f| f.range.is_some());
+ if has_ranges {
+ return self.clone();
+ }
+
+ let total_size = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .map(|f| f.object_meta.size as i64)
+ .sum::<i64>();
+ let target_partition_size =
Review Comment:
After some thoughts, I see that it could be just more user-friendly -- cause this setting will care about preventing unnecessary file splits without any additional settings tweaking efforts.
I've also moved both of these new settings from `execution` to `optimizer` section.
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1410219394
I filed https://github.com/apache/arrow-datafusion/issues/5125 to track turning this on by default
--
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] Ted-Jiang commented on pull request #5057: Parquet parallel scan
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1411432296
Thanks for all kindly reply ! ❤️
> here is the [exact place](https://github.com/apache/arrow-datafusion/blob/125a8580c19c78c99fbbe3a6afe373de2538b205/datafusion/core/src/physical_plan/file_format/parquet/row_groups.rs#L57) where DF decides to read/not to read RowGroup depending on range. So it actually isn't required to split files on ranges with boundaries same as RowGroups boundaries.
So `PartitionedFile ` range is not used for fetch bytes from objectStore, finally we use rowgroup start, offset to fetch bytest ? am i right?
--
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] Ted-Jiang commented on pull request #5057: Parquet parallel scan
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1411734803
> > So `PartitionedFile ` range is not used for fetch bytes from objectStore, finally we use rowgroup start, offset to fetch bytest ? am i right?
>
> Yeah, I can't find any places where range is used, except for row_group pruning
Thanks again for everyone ✌️
--
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] korowa commented on a diff in pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1087046084
##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -539,6 +542,44 @@ async fn fetch_statistics(
Ok(statistics)
}
+async fn fetch_format_scan_metadata(
+ store: &dyn ObjectStore,
+ table_schema: SchemaRef,
+ file: &ObjectMeta,
+ metadata_size_hint: Option<usize>,
+ collect_statistics: bool,
+ collect_file_ranges: bool,
+) -> Result<FormatScanMetadata> {
+ let mut format_scan_metadata = FormatScanMetadata::default();
+
+ if !collect_statistics && !collect_file_ranges {
+ return Ok(format_scan_metadata);
+ }
+
+ let parquet_metadata =
+ fetch_parquet_metadata(store, file, metadata_size_hint).await?;
+
+ if collect_statistics {
+ format_scan_metadata = format_scan_metadata.with_statistics(
+ extract_statistics_from_metadata(&parquet_metadata, table_schema)?,
+ );
+ };
+
+ if collect_file_ranges {
+ let file_ranges = parquet_metadata
Review Comment:
True, cutting file on N even parts will allow to read only row groups having their start offset inside corresponding ranges without any duplicate reads or skipped row groups - so, splitting could be much easier without using metadata (except for ObjectMetadata for the size)
--
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] korowa commented on a diff in pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1088883601
##########
datafusion/core/src/physical_plan/file_format/parquet.rs:
##########
@@ -232,6 +241,74 @@ impl ParquetExec {
self.enable_page_index
.unwrap_or(config_options.execution.parquet.enable_page_index)
}
+
+ /// Redistribute files across partitions according to their size
+ pub fn get_repartitioned(&self, target_partitions: usize) -> Self {
+ // Perform redistribution only in case all files should be read from beginning to end
+ let has_ranges = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .any(|f| f.range.is_some());
+ if has_ranges {
+ return self.clone();
+ }
+
+ let total_size = self
+ .base_config()
+ .file_groups
+ .iter()
+ .flatten()
+ .map(|f| f.object_meta.size as i64)
+ .sum::<i64>();
+ let target_partition_size =
Review Comment:
Sounds reasonable, but it seems to me that same thing can be done via both `target_partitions` & `parallel_file_scan` if we know file layout prior to running query - is this setting supposed to be kind of fuse for running queries over random files (i.e. neither the number of files nor their size is known)?
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1410222842
I believe what happens is that the file is divided into byte ranges and then the row groups whose data falls within those ranges are scanned. It would be good to double check this undertanding though
https://github.com/apache/arrow-datafusion/blob/master/datafusion/core/src/datasource/listing/mod.rs#L52-L63
--
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] tustvold commented on pull request #5057: Parquet parallel scan
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1410221426
> How could we make sure the file is dived into row group?
Without the parquet file metadata we can't reliably, but it isn't important to correctness that we do so. Not needing the metadata significantly simplifies the planning and avoids potentially costly round trips to object store whilst planning. FWIW I believe this is a similar approach as taken by Spark.
--
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] korowa commented on a diff in pull request #5057: Parquet parallel scan
Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1089748183
##########
datafusion/core/src/physical_optimizer/repartition.rs:
##########
@@ -846,6 +897,182 @@ mod tests {
Ok(())
}
+ #[test]
+ fn parallelization_single_partition() -> Result<()> {
+ let plan = aggregate(parquet_exec());
+
+ let expected = [
+ "AggregateExec: mode=Final, gby=[], aggr=[]",
+ "CoalescePartitionsExec",
+ "AggregateExec: mode=Partial, gby=[], aggr=[]",
+ "ParquetExec: limit=None, partitions={2 groups: [[x:0..50], [x:50..100]]}, projection=[c1]",
+ ];
+
+ assert_optimized!(expected, plan, 2, true, 10);
+ Ok(())
+ }
+
+ #[test]
+ fn parallelization_two_partitions() -> Result<()> {
+ let plan = aggregate(parquet_exec_two_partitions());
+
+ let expected = [
+ "AggregateExec: mode=Final, gby=[], aggr=[]",
+ "CoalescePartitionsExec",
+ "AggregateExec: mode=Partial, gby=[], aggr=[]",
+ // Plan already has two partitions
+ "ParquetExec: limit=None, partitions={2 groups: [[x], [y]]}, projection=[c1]",
+ ];
+
+ assert_optimized!(expected, plan, 2, true, 10);
+ Ok(())
+ }
Review Comment:
Good one, done.
--
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] tustvold commented on pull request #5057: Parquet parallel scan
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1410224514
> whose data falls within those ranges are scanned
More specifically it is the row groups with a midpoint that falls into the range, this means that so long as the ranges are disjoint there is no risk of reading the same row group twice
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1407398447
My measurements suggest this setting can improve the performance with single large parquet files significantly (over 2x in my measurement). 👨🍳 👌 -- very nice
I tested this out by making a 9G parquet file from https://github.com/tustvold/access-log-gen/
Then using datafusion-cli:
```sql
❯ select avg(request_bytes), avg(response_bytes), avg(response_status), host from '/Users/alamb/Software/access-log-gen/logs.9G.parquet' group by host;
...
927 rows in set. Query took 2.313 seconds.
```
And then I enabled this setting:
```sql
❯ set datafusion.optimizer.repartition_file_scans = true;
0 rows in set. Query took 0.000 seconds.
❯ select avg(request_bytes), avg(response_bytes), avg(response_status), host from '/Users/alamb/Software/access-log-gen/logs.9G.parquet' group by host;
927 rows in set. Query took 0.962 seconds.
```
😮
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1407431513
> As it works for now - yes, use case is mostly "relatively large files less than number of target_partitions" -- I guess it could be improved / reworked later to something like "perform repartitioning even for target_partitions in case there is significant skew in current partitioning"
I think to make this really happen we will need to have more runtime dynamics (aka using a morsel driven sceheduler)
> I don't mind enabling parallelism by default and it seems to be the fastest way to deliver this feature, but (I'm not sure, just a suggestion) maybe better time for this will be in 1 (or 2) releases after the setting itself will be released?
I agree -- let's get this PR merged in (default to off) and then plan to enable it by default in a few weeks (we just need to remember to do so!)
--
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 #5057: Parquet parallel scan
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1407431966
I plan to leave this open for the rest of the weekend so others have a chance to comment if they want, and then merge on Monday
--
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] Ted-Jiang commented on pull request #5057: Parquet parallel scan
Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang commented on PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#issuecomment-1409782193
Thanks @korowa this is really cool! 👍 nice work!
I have a question about `multiple row groups from the same file may be read concurrently`
from the code
```
let target_partition_size =
(total_size as usize + (target_partitions) - 1) / (target_partitions);
```
How could we make sure the file is dived into row group? 🤔
--
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] tustvold commented on a diff in pull request #5057: Parquet parallel scan
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1087016354
##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -539,6 +542,44 @@ async fn fetch_statistics(
Ok(statistics)
}
+async fn fetch_format_scan_metadata(
+ store: &dyn ObjectStore,
+ table_schema: SchemaRef,
+ file: &ObjectMeta,
+ metadata_size_hint: Option<usize>,
+ collect_statistics: bool,
+ collect_file_ranges: bool,
+) -> Result<FormatScanMetadata> {
+ let mut format_scan_metadata = FormatScanMetadata::default();
+
+ if !collect_statistics && !collect_file_ranges {
+ return Ok(format_scan_metadata);
+ }
+
+ let parquet_metadata =
+ fetch_parquet_metadata(store, file, metadata_size_hint).await?;
+
+ if collect_statistics {
+ format_scan_metadata = format_scan_metadata.with_statistics(
+ extract_statistics_from_metadata(&parquet_metadata, table_schema)?,
+ );
+ };
+
+ if collect_file_ranges {
+ let file_ranges = parquet_metadata
Review Comment:
FWIW the way these ranges are applied in parquet is based on if the row group's midpoint lies within the given range, as a result there is no requirement that these ranges exactly delimit boundaries.
For example you could take a parquet file of 2GB and blindly chop it into 4x 512MB slices. This makes the assumption that there are at least 4 row groups and the row groups are similarly sized, in practice this is probably fine. This is what Spark does and avoids needing the file's metadata to do the optimisation.
--
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] tustvold commented on a diff in pull request #5057: Parquet parallel scan
Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #5057:
URL: https://github.com/apache/arrow-datafusion/pull/5057#discussion_r1087016354
##########
datafusion/core/src/datasource/file_format/parquet.rs:
##########
@@ -539,6 +542,44 @@ async fn fetch_statistics(
Ok(statistics)
}
+async fn fetch_format_scan_metadata(
+ store: &dyn ObjectStore,
+ table_schema: SchemaRef,
+ file: &ObjectMeta,
+ metadata_size_hint: Option<usize>,
+ collect_statistics: bool,
+ collect_file_ranges: bool,
+) -> Result<FormatScanMetadata> {
+ let mut format_scan_metadata = FormatScanMetadata::default();
+
+ if !collect_statistics && !collect_file_ranges {
+ return Ok(format_scan_metadata);
+ }
+
+ let parquet_metadata =
+ fetch_parquet_metadata(store, file, metadata_size_hint).await?;
+
+ if collect_statistics {
+ format_scan_metadata = format_scan_metadata.with_statistics(
+ extract_statistics_from_metadata(&parquet_metadata, table_schema)?,
+ );
+ };
+
+ if collect_file_ranges {
+ let file_ranges = parquet_metadata
Review Comment:
FWIW the way these ranges are applied in parquet is based on if the row group's midpoint lies within the given range, as a result there is no requirement that these ranges exactly delimit boundaries.
For example you could take a parquet file of 2GB and blindly chop it into 4x 512MB slices. This makes the assumption that there are at least 4 row groups and the row groups are similarly sized, in practice this is probably fine. This is what Spark does
--
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