Fokko commented on code in PR #4767:
URL: https://github.com/apache/iceberg/pull/4767#discussion_r873912290
##########
python/src/iceberg/types.py:
##########
@@ -148,56 +159,28 @@ def __new__(
cls._instances[key] = cls._instances.get(key) or object.__new__(cls)
return cls._instances[key]
- def __init__(
- self,
- field_id: int,
- name: str,
- field_type: IcebergType,
- is_optional: bool = True,
- doc: Optional[str] = None,
- ):
- if not self._initialized:
- docString = "" if doc is None else f", doc={repr(doc)}"
- super().__init__(
- (
- f"{field_id}: {name}: {'optional' if is_optional else
'required'} {field_type}" ""
- if doc is None
- else f" ({doc})"
- ),
- f"NestedField(field_id={field_id}, name={repr(name)},
field_type={repr(field_type)}, is_optional={is_optional}"
- f"{docString})",
- )
- self._is_optional = is_optional
- self._id = field_id
- self._name = name
- self._type = field_type
- self._doc = doc
-
- @property
- def is_optional(self) -> bool:
- return self._is_optional
-
@property
def is_required(self) -> bool:
- return not self._is_optional
-
- @property
- def field_id(self) -> int:
- return self._id
-
- @property
- def name(self) -> str:
- return self._name
-
- @property
- def doc(self) -> Optional[str]:
- return self._doc
-
+ return not self.is_optional
+
+ def __post_init__(self):
Review Comment:
Hey @danielcweeks Thanks for pointing this out. I agree that lazily
initializing the string is much better. In terms of caching, I've added the
`cached_property` to the StructType:
https://github.com/apache/iceberg/pull/4767/commits/5ac86f44e8b81d2e7285f85207c1731c9860ddec#diff-7882bc96112705abb40e28d8f45ef911e1a3d43dd62c4987f020dc8738ee7407R216-R218
I don't think we should cache literals, but only the dynamically generated
ones. WDYT?
--
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]