-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(parquet): write single file if option is set #17009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hknlof
wants to merge
6
commits into
apache:main
Choose a base branch
from
hknlof:fix/write-single-parquet
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+121
−3
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8d03a44
fix(parquet): write single file if option is set
hknlof 64d7a22
chore: clippy improvements
hknlof 651cfb8
fix: remove magic strings
hknlof 22a46d8
Merge branch 'main' into fix/write-single-parquet
Jefffrey 365069c
Merge branch 'apache:main' into fix/write-single-parquet
hknlof 4f9c24e
fix(parquet): improvements to test and removal of obsolete tests
hknlof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,7 @@ mod tests { | |
| }; | ||
| use datafusion_execution::config::SessionConfig; | ||
|
|
||
| use datafusion_expr::Partitioning; | ||
| use tempfile::{tempdir, TempDir}; | ||
|
|
||
| #[tokio::test] | ||
|
|
@@ -216,6 +217,98 @@ mod tests { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn write_multiple_file_parquet_no_extensions() -> Result<()> { | ||
| let ctx = SessionContext::new(); | ||
| let df = ctx.read_batch(RecordBatch::try_new( | ||
| Arc::new(Schema::new(vec![ | ||
| Field::new("purchase_id", DataType::Int32, false), | ||
| Field::new("price", DataType::Float32, false), | ||
| Field::new("quantity", DataType::Int32, false), | ||
| ])), | ||
| vec![ | ||
| Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])), | ||
| Arc::new(Float32Array::from(vec![1.12, 3.40, 2.33, 9.10, 6.66])), | ||
| Arc::new(Int32Array::from(vec![1, 3, 2, 4, 3])), | ||
| ], | ||
| )?)?; | ||
|
|
||
| let partitioned_df = df.repartition(Partitioning::RoundRobinBatch(2))?; | ||
| let tmp_dir = tempdir()?; | ||
| let path = tmp_dir | ||
| .path() | ||
| .join("no_ext_parquet") | ||
| .to_str() | ||
| .unwrap() | ||
| .to_string(); | ||
|
|
||
| let options = DataFrameWriteOptions::new(); | ||
|
|
||
| partitioned_df.write_parquet(&path, options, None).await?; | ||
|
|
||
| let test_path = std::path::Path::new(&path); | ||
| assert!( | ||
| test_path.is_dir(), | ||
| "No extension and default DataFrameWriteOptons should have yielded a dir." | ||
| ); | ||
|
|
||
| let mut count = 0; | ||
| if let Ok(dir) = test_path.read_dir() { | ||
| for result in dir { | ||
| if let Ok(entry) = result { | ||
| if entry.file_type()?.is_file() { | ||
| count += 1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TODO: depending on file size this actually emits > 1 | ||
| assert_eq!( | ||
| count, 1, | ||
| "No extension and default DataFrameWriteOptons should have yielded a dir." | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn write_single_file_parquet_no_extensions() -> Result<()> { | ||
| let ctx = SessionContext::new(); | ||
| let df = ctx.read_batch(RecordBatch::try_new( | ||
| Arc::new(Schema::new(vec![ | ||
| Field::new("purchase_id", DataType::Int32, false), | ||
| Field::new("price", DataType::Float32, false), | ||
| Field::new("quantity", DataType::Int32, false), | ||
| ])), | ||
| vec![ | ||
| Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])), | ||
| Arc::new(Float32Array::from(vec![1.12, 3.40, 2.33, 9.10, 6.66])), | ||
| Arc::new(Int32Array::from(vec![1, 3, 2, 4, 3])), | ||
| ], | ||
| )?)?; | ||
| let partitioned_df = df.repartition(Partitioning::RoundRobinBatch(2))?; | ||
| let tmp_dir = tempdir()?; | ||
| let path = tmp_dir | ||
| .path() | ||
| .join("no_ext_parquet") | ||
| .to_str() | ||
| .unwrap() | ||
| .to_string(); | ||
|
|
||
| let options = DataFrameWriteOptions::new().with_single_file_output(true); | ||
|
|
||
| partitioned_df.write_parquet(&path, options, None).await?; | ||
|
|
||
| let test_path = std::path::Path::new(&path); | ||
| assert!( | ||
| test_path.is_file(), | ||
| "No extension and DataFrameWriteOptons::with_single_file_output(true) should have yielded a single file." | ||
| ); | ||
|
Comment on lines
+303
to
+307
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here we would need to check that only one file is written, not just a file is written |
||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn read_from_different_file_extension() -> Result<()> { | ||
| let ctx = SessionContext::new(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would need to also check there are indeed multiple parquet files