Implement ParquetFormatModel and update write_file to use the format API#3381
Open
nssalian wants to merge 1 commit into
Open
Implement ParquetFormatModel and update write_file to use the format API#3381nssalian wants to merge 1 commit into
nssalian wants to merge 1 commit into
Conversation
Contributor
Author
|
@kevinjqliu @Fokko @geruh PTAL when you can |
| # For projection visitor, we don't know the file format, so default to Parquet | ||
| # This is used for schema conversion during reads, not writes | ||
| metadata[PYARROW_PARQUET_FIELD_ID_KEY] = str(field.field_id) | ||
| if self._file_format == FileFormat.ORC: |
Contributor
There was a problem hiding this comment.
Ideally, we'd have a FileFormat API method called add_metadata_for_field (not opinionated on name).
Part of the hope for the FileFormat API was to avoid these kind of switch statements based on the format.
|
|
||
|
|
||
| @pytest.fixture | ||
| def simple_table() -> pa.Table: |
Contributor
There was a problem hiding this comment.
We've got a few tables in tests/conftest.py. Any reason not to use those?
|
|
||
| def test_statistics_record_count(format_model: FileFormatModel, table_schema_simple: Schema, tmp_path: Path) -> None: | ||
| """close() returns DataFileStatistics with correct record count.""" | ||
| table = pa.table( |
Contributor
There was a problem hiding this comment.
Why recreate a different table here?
| include_field_ids: bool = False, | ||
| projected_missing_fields: dict[int, Any] = EMPTY_DICT, | ||
| allow_timestamp_tz_mismatch: bool = False, | ||
| file_format: FileFormat = FileFormat.PARQUET, |
Contributor
There was a problem hiding this comment.
I'm not wild about making PARQUET the default value (I don't think we should have default values...), but that's a light opinion.
| include_field_ids: bool = False, | ||
| projected_missing_fields: dict[int, Any] = EMPTY_DICT, | ||
| allow_timestamp_tz_mismatch: bool = False, | ||
| file_format: FileFormat = FileFormat.PARQUET, |
Contributor
There was a problem hiding this comment.
Same thing, not wild about the default value.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Continued work on #3100
PR Description
Follow-up to #3119. Implements
ParquetFormatWriterandParquetFormatModel, registers Parquet in theFileFormatFactory, and rewriteswrite_fileto dispatch through the factory using thewrite.format.defaulttable property. Future formats can be added in a similar way.Rationale for this change
The
write.format.defaulttable property was never read - the write path was hardcoded to Parquet. This PR makes the property functional. Also threadsfile_formatthrough_to_requested_schema/ArrowProjectionVisitor/_construct_fieldso field ID metadata keys are correct per format (PARQUET:field_idfor Parquet,iceberg.idplusiceberg.requiredfor ORC), preparing the write path for ORC support without changing default behavior.Are these changes tested?
tests/io/test_format_writers.pyadds parametrized tests modeled after Java'sBaseFormatModelTestscovering round-trip, statistics, null handling, context manager caching, close idempotency, close-without-write, and ORC vs Parquet field ID dispatch.tests/io/test_pyarrow.pyaddstest_write_file_parquet_round_tripandtest_write_file_dispatches_on_write_format_defaultexercising the fullwrite_filepath.Are there any user-facing changes?
No. Default behavior is unchanged. Setting
write.format.defaultto an unregistered format now raises aValueError.