From acfe51d49d001f7c5ef1bd22f56c44610703551d Mon Sep 17 00:00:00 2001 From: YUN SUN Date: Tue, 29 Oct 2024 22:08:15 -0500 Subject: [PATCH] [#5200]Update the type.py for python client. --- clients/client-python/gravitino/api/type.py | 148 ++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 clients/client-python/gravitino/api/type.py diff --git a/clients/client-python/gravitino/api/type.py b/clients/client-python/gravitino/api/type.py new file mode 100644 index 0000000000..c2399aa290 --- /dev/null +++ b/clients/client-python/gravitino/api/type.py @@ -0,0 +1,148 @@ +from abc import ABC, abstractmethod +from enum import Enum + +from enum import Enum + +class Name(Enum): + """ + The root type name of this type, representing all data types supported. + """ + + BOOLEAN = "BOOLEAN" + """ The boolean type. """ + + BYTE = "BYTE" + """ The byte type. """ + + SHORT = "SHORT" + """ The short type. """ + + INTEGER = "INTEGER" + """ The integer type. """ + + LONG = "LONG" + """ The long type. """ + + FLOAT = "FLOAT" + """ The float type. """ + + DOUBLE = "DOUBLE" + """ The double type. """ + + DECIMAL = "DECIMAL" + """ The decimal type. """ + + DATE = "DATE" + """ The date type. """ + + TIME = "TIME" + """ The time type. """ + + TIMESTAMP = "TIMESTAMP" + """ The timestamp type. """ + + INTERVAL_YEAR = "INTERVAL_YEAR" + """ The interval year type. """ + + INTERVAL_DAY = "INTERVAL_DAY" + """ The interval day type. """ + + STRING = "STRING" + """ The string type. """ + + VARCHAR = "VARCHAR" + """ The varchar type. """ + + FIXEDCHAR = "FIXEDCHAR" + """ The char type with fixed length. """ + + UUID = "UUID" + """ The UUID type. """ + + FIXED = "FIXED" + """ The binary type with fixed length. """ + + BINARY = "BINARY" + """ The binary type with variable length. The length is specified in the type itself. """ + + STRUCT = "STRUCT" + """ + The struct type. + A struct type is a complex type that contains a set of named fields, each with a type, + and optionally a comment. + """ + + LIST = "LIST" + """ + The list type. + A list type is a complex type that contains a set of elements, each with the same type. + """ + + MAP = "MAP" + """ + The map type. + A map type is a complex type that contains a set of key-value pairs, each with a key type + and a value type. + """ + + UNION = "UNION" + """ + The union type. + A union type is a complex type that contains a set of types. + """ + + NULL = "NULL" + """ The null type. A null type represents a value that is null. """ + + UNPARSED = "UNPARSED" + """ The unparsed type. An unparsed type represents an unresolvable type. """ + + EXTERNAL = "EXTERNAL" + """ The external type. An external type represents a type that is not supported. """ + +# Define the Type interface (abstract base class) +class Type(ABC): + @abstractmethod + def name(self) -> Name: + """ Returns the generic name of the type. """ + pass + + @abstractmethod + def simpleString(self) -> str: + """ Returns a readable string representation of the type. """ + pass + +# Define base classes +class PrimitiveType(Type, ABC): + """ Base class for all primitive types. """ + pass + +class NumericType(PrimitiveType, ABC): + """ Base class for all numeric types. """ + pass + +class DateTimeType(PrimitiveType, ABC): + """ Base class for all date/time types. """ + pass + +class IntervalType(PrimitiveType, ABC): + """ Base class for all interval types. """ + pass + +class ComplexType(Type, ABC): + """ Base class for all complex types, including struct, list, map, and union. """ + pass + +# Define IntegralType class +class IntegralType(NumericType, ABC): + def __init__(self, signed: bool): + self._signed = signed + + def signed(self) -> bool: + """ Returns True if the integer type is signed, False otherwise. """ + return self._signed + +# Define FractionType class +class FractionType(NumericType, ABC): + """ Base class for all fractional types. """ + pass