-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#5200]Update the type.py for python client.
- Loading branch information
1 parent
608b53c
commit acfe51d
Showing
1 changed file
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |