-
Notifications
You must be signed in to change notification settings - Fork 581
feat: add Parquet content-defined chunking writer support #3889
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
kszucs
wants to merge
2
commits into
apache:main
Choose a base branch
from
kszucs:feat/parquet-cdc-writer-support
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.
+150
−9
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,6 +393,13 @@ def to_input_file(self) -> PyArrowFile: | |
| return self | ||
|
|
||
|
|
||
| def _require_pyarrow_version(min_version: str, feature: str) -> None: | ||
| from packaging import version | ||
|
|
||
| if version.parse(pyarrow.__version__) < version.parse(min_version): | ||
| raise ImportError(f"pyarrow version >= {min_version} required for {feature}, but found version {pyarrow.__version__}.") | ||
|
|
||
|
|
||
| class PyArrowFileIO(FileIO): | ||
| fs_by_scheme: Callable[[str, str | None], FileSystem] | ||
|
|
||
|
|
@@ -535,14 +542,7 @@ def _initialize_s3_fs(self, netloc: str | None) -> FileSystem: | |
|
|
||
| def _initialize_azure_fs(self) -> FileSystem: | ||
| # https://arrow.apache.org/docs/python/generated/pyarrow.fs.AzureFileSystem.html | ||
| from packaging import version | ||
|
|
||
| MIN_PYARROW_VERSION_SUPPORTING_AZURE_FS = "20.0.0" | ||
| if version.parse(pyarrow.__version__) < version.parse(MIN_PYARROW_VERSION_SUPPORTING_AZURE_FS): | ||
| raise ImportError( | ||
| f"pyarrow version >= {MIN_PYARROW_VERSION_SUPPORTING_AZURE_FS} required for AzureFileSystem support, " | ||
| f"but found version {pyarrow.__version__}." | ||
| ) | ||
| _require_pyarrow_version("20.0.0", "AzureFileSystem support") | ||
|
Collaborator
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. I love this. |
||
|
|
||
| from pyarrow.fs import AzureFileSystem | ||
|
|
||
|
|
@@ -2939,7 +2939,7 @@ def _get_parquet_writer_kwargs(table_properties: Properties) -> dict[str, Any]: | |
| if compression_codec == ICEBERG_UNCOMPRESSED_CODEC: | ||
| compression_codec = PYARROW_UNCOMPRESSED_CODEC | ||
|
|
||
| return { | ||
| parquet_writer_kwargs: dict[str, Any] = { | ||
| "compression": compression_codec, | ||
| "compression_level": compression_level, | ||
| "data_page_size": property_as_int( | ||
|
|
@@ -2959,6 +2959,35 @@ def _get_parquet_writer_kwargs(table_properties: Properties) -> dict[str, Any]: | |
| ), | ||
| } | ||
|
|
||
| # Unlike the unsupported options warned about above, a CDC request must not be dropped: | ||
| # writing without the requested chunk boundaries silently defeats the point, so raise instead. | ||
| if property_as_bool( | ||
| properties=table_properties, | ||
| property_name=TableProperties.PARQUET_CDC_ENABLED, | ||
| default=TableProperties.PARQUET_CDC_ENABLED_DEFAULT, | ||
| ): | ||
| _require_pyarrow_version("21.0.0", "Parquet content-defined chunking") | ||
| # PyArrow validates these values itself (e.g. max-chunk-size > min-chunk-size). | ||
| parquet_writer_kwargs["use_content_defined_chunking"] = { | ||
| "min_chunk_size": property_as_int( | ||
| properties=table_properties, | ||
| property_name=TableProperties.PARQUET_CDC_MIN_CHUNK_SIZE, | ||
| default=TableProperties.PARQUET_CDC_MIN_CHUNK_SIZE_DEFAULT, | ||
| ), | ||
| "max_chunk_size": property_as_int( | ||
| properties=table_properties, | ||
| property_name=TableProperties.PARQUET_CDC_MAX_CHUNK_SIZE, | ||
| default=TableProperties.PARQUET_CDC_MAX_CHUNK_SIZE_DEFAULT, | ||
| ), | ||
| "norm_level": property_as_int( | ||
| properties=table_properties, | ||
| property_name=TableProperties.PARQUET_CDC_NORM_LEVEL, | ||
| default=TableProperties.PARQUET_CDC_NORM_LEVEL_DEFAULT, | ||
| ), | ||
| } | ||
|
|
||
| return parquet_writer_kwargs | ||
|
|
||
|
|
||
| def _dataframe_to_data_files( | ||
| table_metadata: TableMetadata, | ||
|
|
||
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
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.
Idea (this is out-of-scope): What if we had a
require_pyarrow_with_versionmethod that checks if pyarrow exists and optionally checks the version?We do pyarrow checks across the codebase.