-
Notifications
You must be signed in to change notification settings - Fork 77
[DataLoader] Add pyiceberg ArrivalOrder support via upstream PR #491
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
7 commits
Select commit
Hold shift + click to select a range
7062a57
[DataLoader] Add pyiceberg ArrivalOrder support via upstream PR
cbb330 9047297
Pin pyiceberg source to SHA instead of branch
cbb330 155da8e
Use PEP 508 direct reference for pyiceberg instead of uv.sources
cbb330 f079ab0
[DataLoader] Add batch_size parameter for intra-file streaming
cbb330 cdf6ea7
Clean up test helpers: rename and split factory functions
cbb330 ecee293
Clarify batch_size docstring with PyArrow Scanner detail
cbb330 827f1d9
Address review feedback on batch_size tests and docstring
cbb330 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
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
137 changes: 137 additions & 0 deletions
137
integrations/python/dataloader/tests/test_arrival_order.py
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 |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| """Tests verifying the ArrivalOrder API from pyiceberg PR #3046 is available and functional. | ||
|
|
||
| These tests confirm that the openhouse dataloader can access the new ScanOrder class hierarchy | ||
| added upstream (apache/iceberg-python#3046) and that ArrowScan.to_record_batches accepts the | ||
| order parameter. | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| import pyarrow as pa | ||
| import pyarrow.parquet as pq | ||
| import pytest | ||
| from pyiceberg.expressions import AlwaysTrue | ||
| from pyiceberg.io import load_file_io | ||
| from pyiceberg.io.pyarrow import ArrowScan | ||
| from pyiceberg.manifest import DataFile, FileFormat | ||
| from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC | ||
| from pyiceberg.schema import Schema | ||
| from pyiceberg.table import ArrivalOrder, FileScanTask, ScanOrder, TaskOrder | ||
| from pyiceberg.table.metadata import new_table_metadata | ||
| from pyiceberg.table.sorting import UNSORTED_SORT_ORDER | ||
| from pyiceberg.types import LongType, NestedField, StringType | ||
|
|
||
| _SCHEMA = Schema( | ||
| NestedField(field_id=1, name="id", field_type=LongType(), required=False), | ||
| NestedField(field_id=2, name="name", field_type=StringType(), required=False), | ||
| ) | ||
|
|
||
|
|
||
| def _write_parquet(tmp_path: object, table: pa.Table) -> str: | ||
| """Write a parquet file with Iceberg field IDs and return its path.""" | ||
| file_path = str(tmp_path / "test.parquet") # type: ignore[operator] | ||
| fields = [field.with_metadata({b"PARQUET:field_id": str(i + 1).encode()}) for i, field in enumerate(table.schema)] | ||
| pq.write_table(table.cast(pa.schema(fields)), file_path) | ||
| return file_path | ||
|
|
||
|
|
||
| def _make_arrow_scan(tmp_path: object, file_path: str) -> ArrowScan: | ||
| metadata = new_table_metadata( | ||
| schema=_SCHEMA, | ||
| partition_spec=UNPARTITIONED_PARTITION_SPEC, | ||
| sort_order=UNSORTED_SORT_ORDER, | ||
| location=str(tmp_path), | ||
| properties={}, | ||
| ) | ||
| return ArrowScan( | ||
| table_metadata=metadata, | ||
| io=load_file_io(properties={}, location=file_path), | ||
| projected_schema=_SCHEMA, | ||
| row_filter=AlwaysTrue(), | ||
| ) | ||
|
|
||
|
|
||
| def _make_file_scan_task(file_path: str, table: pa.Table) -> FileScanTask: | ||
| data_file = DataFile.from_args( | ||
| file_path=file_path, | ||
| file_format=FileFormat.PARQUET, | ||
| record_count=table.num_rows, | ||
| file_size_in_bytes=os.path.getsize(file_path), | ||
| ) | ||
| data_file._spec_id = 0 | ||
| return FileScanTask(data_file=data_file) | ||
|
|
||
|
|
||
| def _sample_table() -> pa.Table: | ||
| return pa.table( | ||
| { | ||
| "id": pa.array([1, 2, 3], type=pa.int64()), | ||
| "name": pa.array(["alice", "bob", "charlie"], type=pa.string()), | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| class TestScanOrderImports: | ||
| """Verify the ScanOrder class hierarchy is importable from pyiceberg.table.""" | ||
|
|
||
| def test_scan_order_base_class_exists(self) -> None: | ||
| assert ScanOrder is not None | ||
|
|
||
| def test_task_order_is_scan_order(self) -> None: | ||
| assert issubclass(TaskOrder, ScanOrder) | ||
|
|
||
| def test_arrival_order_is_scan_order(self) -> None: | ||
| assert issubclass(ArrivalOrder, ScanOrder) | ||
|
|
||
| def test_arrival_order_default_params(self) -> None: | ||
| ao = ArrivalOrder() | ||
| assert ao.concurrent_streams == 8 | ||
| assert ao.batch_size is None | ||
| assert ao.max_buffered_batches == 16 | ||
|
|
||
| def test_arrival_order_custom_params(self) -> None: | ||
| ao = ArrivalOrder(concurrent_streams=4, batch_size=32768, max_buffered_batches=8) | ||
| assert ao.concurrent_streams == 4 | ||
| assert ao.batch_size == 32768 | ||
| assert ao.max_buffered_batches == 8 | ||
|
|
||
| def test_arrival_order_rejects_invalid_concurrent_streams(self) -> None: | ||
| with pytest.raises(ValueError, match="concurrent_streams"): | ||
| ArrivalOrder(concurrent_streams=0) | ||
|
|
||
| def test_arrival_order_rejects_invalid_max_buffered_batches(self) -> None: | ||
| with pytest.raises(ValueError, match="max_buffered_batches"): | ||
| ArrivalOrder(max_buffered_batches=0) | ||
|
|
||
|
|
||
| class TestToRecordBatchesOrder: | ||
|
cbb330 marked this conversation as resolved.
|
||
| """Verify ArrowScan.to_record_batches accepts the order parameter and returns correct data.""" | ||
|
|
||
| def test_default_order_returns_all_rows(self, tmp_path: object) -> None: | ||
| """Default (TaskOrder) still works — backward compatible.""" | ||
| table = _sample_table() | ||
| file_path = _write_parquet(tmp_path, table) | ||
| arrow_scan = _make_arrow_scan(tmp_path, file_path) | ||
| task = _make_file_scan_task(file_path, table) | ||
| batches = list(arrow_scan.to_record_batches([task])) | ||
| result = pa.Table.from_batches(batches).sort_by("id") | ||
| assert result.column("id").to_pylist() == [1, 2, 3] | ||
|
|
||
| def test_explicit_task_order_returns_all_rows(self, tmp_path: object) -> None: | ||
| table = _sample_table() | ||
| file_path = _write_parquet(tmp_path, table) | ||
| arrow_scan = _make_arrow_scan(tmp_path, file_path) | ||
| task = _make_file_scan_task(file_path, table) | ||
| batches = list(arrow_scan.to_record_batches([task], order=TaskOrder())) | ||
| result = pa.Table.from_batches(batches).sort_by("id") | ||
| assert result.column("id").to_pylist() == [1, 2, 3] | ||
|
|
||
| def test_arrival_order_returns_all_rows(self, tmp_path: object) -> None: | ||
| table = _sample_table() | ||
| file_path = _write_parquet(tmp_path, table) | ||
| arrow_scan = _make_arrow_scan(tmp_path, file_path) | ||
| task = _make_file_scan_task(file_path, table) | ||
| batches = list(arrow_scan.to_record_batches([task], order=ArrivalOrder(concurrent_streams=2))) | ||
| result = pa.Table.from_batches(batches).sort_by("id") | ||
| assert result.column("id").to_pylist() == [1, 2, 3] | ||
| assert result.column("name").to_pylist() == ["alice", "bob", "charlie"] | ||
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.
Uh oh!
There was an error while loading. Please reload this page.