|
137 | 137 | TimestampType, |
138 | 138 | TimestamptzType, |
139 | 139 | TimeType, |
| 140 | + UUIDType, |
140 | 141 | ) |
141 | 142 | from tests.catalog.test_base import InMemoryCatalog |
142 | 143 | from tests.conftest import UNIFIED_AWS_SESSION_PROPERTIES |
@@ -3471,6 +3472,49 @@ def test_determine_partitions_with_view_types(transform: Transform[Any, Any]) -> |
3471 | 3472 | assert sorted(written.to_pylist(), key=str) == sorted(rows, key=str) |
3472 | 3473 |
|
3473 | 3474 |
|
| 3475 | +def test_determine_partitions_with_uuid_column() -> None: |
| 3476 | + schema = Schema( |
| 3477 | + NestedField(id=1, name="id", field_type=LongType(), required=False), |
| 3478 | + NestedField(id=2, name="uuid", field_type=UUIDType(), required=False), |
| 3479 | + ) |
| 3480 | + spec = PartitionSpec(PartitionField(source_id=2, field_id=1000, transform=IdentityTransform(), name="uuid")) |
| 3481 | + arrow_table = pa.table( |
| 3482 | + { |
| 3483 | + "id": pa.array([1, 2, 3, 4], type=pa.int64()), |
| 3484 | + "uuid": pa.array([uuid.UUID(int=1).bytes, uuid.UUID(int=2).bytes, uuid.UUID(int=1).bytes, None], type=pa.uuid()), |
| 3485 | + } |
| 3486 | + ) |
| 3487 | + |
| 3488 | + partitions = list(_determine_partitions(spec, schema, arrow_table)) |
| 3489 | + |
| 3490 | + # The partition values are the 16 bytes of each UUID |
| 3491 | + rows_by_partition = {p.partition_key.partition[0]: sorted(p.arrow_table_partition["id"].to_pylist()) for p in partitions} |
| 3492 | + assert rows_by_partition == {uuid.UUID(int=1).bytes: [1, 3], uuid.UUID(int=2).bytes: [2], None: [4]} |
| 3493 | + # The written data keeps the uuid type |
| 3494 | + assert all(p.arrow_table_partition.schema.field("uuid").type == pa.uuid() for p in partitions) |
| 3495 | + |
| 3496 | + |
| 3497 | +def test_append_uuid_to_table_partitioned_on_uuid(catalog: InMemoryCatalog) -> None: |
| 3498 | + schema = Schema( |
| 3499 | + NestedField(id=1, name="id", field_type=LongType(), required=False), |
| 3500 | + NestedField(id=2, name="uuid", field_type=UUIDType(), required=False), |
| 3501 | + ) |
| 3502 | + spec = PartitionSpec(PartitionField(source_id=2, field_id=1000, transform=IdentityTransform(), name="uuid")) |
| 3503 | + catalog.create_namespace("default") |
| 3504 | + table = catalog.create_table("default.test_append_uuid_partitioned", schema=schema, partition_spec=spec) |
| 3505 | + |
| 3506 | + arrow_table = pa.table( |
| 3507 | + { |
| 3508 | + "id": pa.array([1, 2, 3], type=pa.int64()), |
| 3509 | + "uuid": pa.array([uuid.UUID(int=1).bytes, uuid.UUID(int=2).bytes, None], type=pa.uuid()), |
| 3510 | + } |
| 3511 | + ) |
| 3512 | + table.append(arrow_table) |
| 3513 | + |
| 3514 | + assert sorted(table.scan().to_arrow().to_pylist(), key=lambda row: row["id"]) == arrow_table.to_pylist() |
| 3515 | + assert {task.file.partition[0] for task in table.scan().plan_files()} == {uuid.UUID(int=1), uuid.UUID(int=2), None} |
| 3516 | + |
| 3517 | + |
3474 | 3518 | def test_append_view_types_to_partitioned_table(catalog: InMemoryCatalog) -> None: |
3475 | 3519 | schema = Schema( |
3476 | 3520 | NestedField(id=1, name="id", field_type=LongType(), required=False), |
|
0 commit comments