-
Notifications
You must be signed in to change notification settings - Fork 441
fix: Use binary(16) for UUID type to ensure Spark compatibility #2881
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
ndrluis
wants to merge
4
commits into
apache:main
Choose a base branch
from
ndrluis:uuid-fix
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.
+71
−8
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d84868d
fix: Use binary(16) for UUID type to ensure Spark compatibility
ndrluis a7bdfca
add TODO comment for PyArrow UUID filtering workaround
ndrluis d6dd092
Merge branch 'main' into uuid-fix
Fokko 1751f0c
Use session_catalog fixture in UUID write test
ndrluis 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
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 |
|---|---|---|
|
|
@@ -1500,7 +1500,7 @@ def test_table_write_schema_with_valid_upcast( | |
| pa.field("list", pa.list_(pa.int64()), nullable=False), | ||
| pa.field("map", pa.map_(pa.string(), pa.int64()), nullable=False), | ||
| pa.field("double", pa.float64(), nullable=True), # can support upcasting float to double | ||
| pa.field("uuid", pa.uuid(), nullable=True), | ||
| pa.field("uuid", pa.binary(16), nullable=True), | ||
| ) | ||
| ) | ||
| ) | ||
|
|
@@ -2138,7 +2138,7 @@ def test_uuid_partitioning(session_catalog: Catalog, spark: SparkSession, transf | |
| tbl.append(arr_table) | ||
|
|
||
| lhs = [r[0] for r in spark.table(identifier).collect()] | ||
| rhs = [str(u.as_py()) for u in tbl.scan().to_arrow()["uuid"].combine_chunks()] | ||
| rhs = [str(uuid.UUID(bytes=u.as_py())) for u in tbl.scan().to_arrow()["uuid"].combine_chunks()] | ||
| assert lhs == rhs | ||
|
|
||
|
|
||
|
|
@@ -2530,3 +2530,63 @@ def test_v3_write_and_read_row_lineage(spark: SparkSession, session_catalog: Cat | |
| assert tbl.metadata.next_row_id == initial_next_row_id + len(test_data), ( | ||
| "Expected next_row_id to be incremented by the number of added rows" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| def test_write_uuid_in_pyiceberg_and_scan(session_catalog: Catalog, spark: SparkSession) -> None: | ||
| """Test UUID compatibility between PyIceberg and Spark. | ||
|
|
||
| UUIDs must be written as binary(16) for Spark compatibility since Java Arrow | ||
| metadata differs from Python Arrow metadata for UUID types. | ||
| """ | ||
| identifier = "default.test_write_uuid_in_pyiceberg_and_scan" | ||
|
|
||
| catalog = load_catalog("default", type="in-memory") | ||
|
||
| catalog.create_namespace("ns") | ||
|
|
||
| schema = Schema(NestedField(field_id=1, name="uuid_col", field_type=UUIDType(), required=False)) | ||
|
|
||
| test_data_with_null = { | ||
| "uuid_col": [ | ||
| uuid.UUID("00000000-0000-0000-0000-000000000000").bytes, | ||
| None, | ||
| uuid.UUID("11111111-1111-1111-1111-111111111111").bytes, | ||
| ] | ||
| } | ||
|
|
||
| try: | ||
| session_catalog.drop_table(identifier=identifier) | ||
| except NoSuchTableError: | ||
| pass | ||
|
|
||
| table = _create_table(session_catalog, identifier, {"format-version": "2"}, schema=schema) | ||
|
|
||
| arrow_table = pa.table(test_data_with_null, schema=schema.as_arrow()) | ||
|
|
||
| # Write with pyarrow | ||
| table.append(arrow_table) | ||
|
|
||
| # Write with pyspark | ||
| spark.sql( | ||
| f""" | ||
| INSERT INTO {identifier} VALUES ("22222222-2222-2222-2222-222222222222") | ||
| """ | ||
| ) | ||
| df = spark.table(identifier) | ||
|
|
||
| table.refresh() | ||
|
|
||
| assert df.count() == 4 | ||
| assert len(table.scan().to_arrow()) == 4 | ||
|
|
||
| result = df.where("uuid_col = '00000000-0000-0000-0000-000000000000'") | ||
| assert result.count() == 1 | ||
kevinjqliu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| result = df.where("uuid_col = '22222222-2222-2222-2222-222222222222'") | ||
| assert result.count() == 1 | ||
|
|
||
| result = table.scan(row_filter=EqualTo("uuid_col", uuid.UUID("00000000-0000-0000-0000-000000000000").bytes)).to_arrow() | ||
| assert len(result) == 1 | ||
|
|
||
| result = table.scan(row_filter=EqualTo("uuid_col", uuid.UUID("22222222-2222-2222-2222-222222222222").bytes)).to_arrow() | ||
| assert len(result) == 1 | ||
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.