-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for list of strings in sort_by and dictionary encoding in parquet writer #421
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1cc4ead
Initial plan
Copilot ca54e77
Add support for list of strings in sort_by parameter
Copilot 26fbade
Add use_dictionary parameter for parquet dictionary encoding
Copilot e85e0b5
Bump version from 0.6.27 to 0.6.29
joocer 989983b
Merge branch 'main' into copilot/fix-21057b26-b99a-47df-8604-20910c37…
joocer 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import io | ||
| import json | ||
| import threading | ||
| from typing import Optional | ||
| from typing import List, Optional, Union | ||
|
|
||
| import orjson | ||
| import orso | ||
|
|
@@ -32,13 +32,15 @@ def __init__( | |
| format: str = "parquet", | ||
| schema: Optional[RelationSchema] = None, | ||
| parquet_row_group_size: int = 5000, | ||
| sort_by: Optional[str] = None, | ||
| sort_by: Optional[Union[str, List]] = None, | ||
| use_dictionary: Optional[Union[bool, List[str]]] = None, | ||
| **kwargs, | ||
| ): | ||
| self.format = format | ||
| self.maximum_blob_size = blob_size | ||
| self.parquet_row_group_size = parquet_row_group_size | ||
| self.sort_by = sort_by | ||
| self.use_dictionary = use_dictionary | ||
|
|
||
| if format not in SUPPORTED_FORMATS_ALGORITHMS: | ||
| raise ValueError( | ||
|
|
@@ -166,12 +168,18 @@ def commit(self): | |
|
|
||
| # sort the table if sort_by is specified | ||
| if self.sort_by: | ||
| pytable = pytable.sort_by(self.sort_by) | ||
| # Convert list of strings to PyArrow format | ||
| sort_spec = self.sort_by | ||
| if isinstance(self.sort_by, list) and all(isinstance(item, str) for item in self.sort_by): | ||
|
||
| # Convert list of strings to list of tuples with default ascending order | ||
| sort_spec = [(col, "ascending") for col in self.sort_by] | ||
| pytable = pytable.sort_by(sort_spec) | ||
|
|
||
| tempfile = io.BytesIO() | ||
| pyarrow.parquet.write_table( | ||
| pytable, where=tempfile, row_group_size=self.parquet_row_group_size | ||
| ) | ||
| write_kwargs = {"row_group_size": self.parquet_row_group_size} | ||
| if self.use_dictionary is not None: | ||
| write_kwargs["use_dictionary"] = self.use_dictionary | ||
| pyarrow.parquet.write_table(pytable, where=tempfile, **write_kwargs) | ||
|
|
||
| tempfile.seek(0) | ||
| write_buffer = tempfile.read() | ||
|
|
||
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Store the version here so: | ||
| # 1) we don't load dependencies by storing it in __init__.py | ||
| # 2) we can import it in setup.py for the same reason | ||
| __version__ = "0.6.28" | ||
| __version__ = "0.6.29" | ||
|
|
||
| # nodoc - don't add to the documentation wiki |
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.
The type hint
Listis too generic. It should beList[Union[str, Tuple[str, str]]]to clearly indicate it accepts either a list of column names or a list of tuples with column name and sort direction.