Fokko commented on code in PR #4767:
URL: https://github.com/apache/iceberg/pull/4767#discussion_r873968719
##########
python/src/iceberg/types.py:
##########
@@ -209,25 +192,24 @@ class StructType(IcebergType):
'struct<1: required_field: optional string, 2: optional_field:
optional int>'
"""
- _instances: Dict[Tuple[NestedField, ...], "StructType"] = {}
+ fields: List[NestedField] = field()
+
+ _instances: ClassVar[Dict[Tuple[NestedField, ...], "StructType"]] = {}
- def __new__(cls, *fields: NestedField):
+ def __new__(cls, *fields: NestedField, **kwargs):
+ if "fields" in kwargs:
+ fields = kwargs["fields"]
cls._instances[fields] = cls._instances.get(fields) or
object.__new__(cls)
return cls._instances[fields]
- def __init__(self, *fields: NestedField):
- if not self._initialized:
- super().__init__(
- f"struct<{', '.join(map(str, fields))}>",
- f"StructType{repr(fields)}",
- )
- self._fields = fields
-
- @property
- def fields(self) -> Tuple[NestedField, ...]:
- return self._fields
+ def __init__(self, *fields: NestedField, **kwargs):
+ if "fields" in kwargs:
+ fields = kwargs["fields"]
+ object.__setattr__(self, "fields", fields)
Review Comment:
This logic allows you to both pass in the fields through args and kwargs:
```python
StructField(
NestedField(field_id=1, name='optional_field', field_type=IntegerType(),
is_optional=True),
NestedField(field_id=2, name='required_field',
field_type=FixedType(length=5), is_optional=False),
)
or
StructField(
fields=(
NestedField(field_id=1, name='optional_field',
field_type=IntegerType(), is_optional=True),
NestedField(field_id=2, name='required_field',
field_type=FixedType(length=5), is_optional=False),
)
)
```
This was a change required as explained in
https://github.com/apache/iceberg/pull/4767#discussion_r873959425
--
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]