|
54 | 54 | TimestampType, |
55 | 55 | TimestamptzType, |
56 | 56 | TimeType, |
| 57 | + UnknownType, |
57 | 58 | UUIDType, |
58 | 59 | ) |
59 | 60 | from pyiceberg.utils.schema_conversion import AvroSchemaConversion |
@@ -544,3 +545,23 @@ def test_avro_output_file_tell_includes_buffered_records() -> None: |
544 | 545 | out.write_block([manifest_entry(0)]) |
545 | 546 |
|
546 | 547 | assert out.tell() > after_header |
| 548 | + |
| 549 | + |
| 550 | +def test_write_optional_unknown_type() -> None: |
| 551 | + # A partition field whose source column was dropped has the unknown type |
| 552 | + schema = Schema( |
| 553 | + NestedField(field_id=1, name="before", field_type=StringType(), required=False), |
| 554 | + NestedField(field_id=2, name="dropped", field_type=UnknownType(), required=False), |
| 555 | + NestedField(field_id=3, name="after", field_type=LongType(), required=True), |
| 556 | + ) |
| 557 | + |
| 558 | + with TemporaryDirectory() as tmpdir: |
| 559 | + tmp_avro_file = tmpdir + "/unknown.avro" |
| 560 | + with avro.AvroOutputFile[Record](PyArrowFileIO().new_output(tmp_avro_file), schema, "unknown") as out: |
| 561 | + out.write_block([Record("hello", None, 42)]) |
| 562 | + |
| 563 | + with avro.AvroFile[Record](PyArrowFileIO().new_input(tmp_avro_file), schema, {-1: Record}) as avro_reader: |
| 564 | + assert list(avro_reader) == [Record("hello", None, 42)] |
| 565 | + |
| 566 | + with open(tmp_avro_file, "rb") as fo: |
| 567 | + assert list(reader(fo=fo)) == [{"before": "hello", "dropped": None, "after": 42}] |
0 commit comments