HonahX commented on code in PR #8622:
URL: https://github.com/apache/iceberg/pull/8622#discussion_r1338218587
##########
python/pyiceberg/manifest.py:
##########
@@ -208,8 +305,11 @@ def __setattr__(self, name: str, value: Any) -> None:
value = FileFormat[value]
super().__setattr__(name, value)
- def __init__(self, *data: Any, **named_data: Any) -> None:
- super().__init__(*data, **{"struct": DATA_FILE_TYPE, **named_data})
+ def __init__(self, format_version: Literal[1, 2] = 1, *data: Any,
**named_data: Any) -> None:
+ super().__init__(
+ *data,
+ **{"struct": DATA_FILE_TYPE if format_version == 1 else
data_file_with_partition(StructType(), 2), **named_data},
Review Comment:
The additional `format_version` is added to handle the v2 case, where the
field `block_size_in_bytes` should be skipped when written to the manifest file
##########
python/tests/test_integration_manifest.py:
##########
@@ -0,0 +1,127 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint:disable=redefined-outer-name
+
+import inspect
+from enum import Enum
+from tempfile import TemporaryDirectory
+from typing import Any
+
+import pytest
+from fastavro import reader
+
+from pyiceberg.catalog import Catalog, load_catalog
+from pyiceberg.io.pyarrow import PyArrowFileIO
+from pyiceberg.manifest import (
+ DataFile,
+ ManifestEntry,
+ write_manifest,
+)
+from pyiceberg.table import Table
+from pyiceberg.utils.lazydict import LazyDict
+
+
+# helper function to serialize our objects to dicts to enable
+# direct comparison with the dicts returned by fastavro
+def todict(obj: Any) -> Any:
+ if isinstance(obj, dict) or isinstance(obj, LazyDict):
+ data = []
+ for k, v in obj.items():
+ data.append({"key": k, "value": v})
+ return data
+ elif isinstance(obj, Enum):
+ return obj.value
+ elif hasattr(obj, "__iter__") and not isinstance(obj, str) and not
isinstance(obj, bytes):
+ return [todict(v) for v in obj]
+ elif hasattr(obj, "__dict__"):
+ return {key: todict(value) for key, value in inspect.getmembers(obj)
if not callable(value) and not key.startswith("_")}
+ else:
+ return obj
+
+
[email protected]()
+def catalog() -> Catalog:
+ return load_catalog(
+ "local",
+ **{
+ "type": "rest",
+ "uri": "http://localhost:8181",
+ "s3.endpoint": "http://localhost:9000",
+ "s3.access-key-id": "admin",
+ "s3.secret-access-key": "password",
+ },
+ )
+
+
[email protected]()
+def table_test_all_types(catalog: Catalog) -> Table:
+ return catalog.load_table("default.test_all_types")
+
+
[email protected]
+def test_write_sample_manifest(table_test_all_types: Table) -> None:
Review Comment:
I will add more integration tests here. The idea here is to use real
manifest file/list as a reference so that we do not need to manually construct
many data structures
##########
python/pyiceberg/manifest.py:
##########
@@ -163,6 +194,70 @@ def __repr__(self) -> str:
)
+@singledispatch
+def partition_field_to_data_file_partition_field(partition_field_type:
IcebergType) -> PrimitiveType:
+ raise TypeError(f"Unsupported partition field type:
{partition_field_type}")
+
+
+@partition_field_to_data_file_partition_field.register(LongType)
+@partition_field_to_data_file_partition_field.register(DateType)
+@partition_field_to_data_file_partition_field.register(TimeType)
+@partition_field_to_data_file_partition_field.register(TimestampType)
+@partition_field_to_data_file_partition_field.register(TimestamptzType)
+def _(partition_field_type: PrimitiveType) -> IntegerType:
+ return IntegerType()
Review Comment:
The `partition_types` got from `PartitionSpec` contains the type of the
field in the table schema. Some of these are different from the actual types in
`data_file.partition`. For example,
```json
{
"name": "partition",
"type": {
"type": "record",
"name": "r102",
"fields": [{
"name": "tpep_pickup_datetime_day",
"type": ["null", {
"type": "int",
"logicalType": "date"
}],
"default": null,
"field-id": 1000
}]
},
"field-id": 102
}
```
Hence, we need some measure to convert these to the right types for Avro
Writer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]