rdblue commented on a change in pull request #4016:
URL: https://github.com/apache/iceberg/pull/4016#discussion_r807048847
##########
File path: python/src/iceberg/types.py
##########
@@ -57,30 +57,65 @@ def __str__(self):
@property
def is_primitive(self) -> bool:
- return self._is_primitive
+ return isinstance(self, PrimitiveType)
+
+
+class PrimitiveType(IcebergType):
+ """Base class for all Iceberg Primitive Types"""
+
+ _instances = {} # type: ignore
+
+ def __new__(cls):
+ cls._instances[cls] = cls._instances.get(cls) or object.__new__(cls)
+ return cls._instances[cls]
+
+
+class FixedType(PrimitiveType):
+ """A fixed data type in Iceberg.
+
+ Example:
+ >>> FixedType(8)
+ FixedType(length=8)
+ >>> FixedType(8)==FixedType(8)
+ True
+ """
+
+ _instances: Dict[int, "FixedType"] = {}
+ def __new__(cls, length: int):
+ cls._instances[length] = cls._instances.get(length) or
object.__new__(cls)
+ return cls._instances[length]
-class FixedType(Type):
def __init__(self, length: int):
- super().__init__(f"fixed[{length}]", f"FixedType(length={length})",
is_primitive=True)
+ super().__init__(f"fixed[{length}]", f"FixedType(length={length})")
self._length = length
@property
def length(self) -> int:
return self._length
- def __eq__(self, other):
- if type(self) is type(other):
- return self.length == other.length
- return False
+class DecimalType(PrimitiveType):
+ """A fixed data type in Iceberg.
+
+ Example:
+ >>> DecimalType(32, 3)
+ DecimalType(precision=32, scale=3)
+ >>> DecimalType(8, 3)==DecimalType(8, 3)
+ True
+ """
+
+ _instances: Dict[Tuple[int, int], "DecimalType"] = {}
+
+ def __new__(cls, precision: int, scale: int):
+ key = precision, scale
+ cls._instances[key] = cls._instances.get(key) or object.__new__(cls)
Review comment:
Okay, I understand. So Python is still going to call `__init__` after
this method on the object that this returns.
--
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]