Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"DateTime": DateTimeType,
"Tuple": TupleType,
"Array": ArrayType,
"Nullable": NullableType,
"Nothing": NothingType,
"UUID": UUIDType,
"LowCardinality": LowCardinalityType,
"Decimal": DecimalType,
"Decimal32": DecimalType,
"Decimal64": DecimalType,
"Decimal128": DecimalType,
}
PY_TYPES_MAPPING = {
int: IntType.unconvert,
float: FloatType.unconvert,
str: StrType.unconvert,
dt.date: DateType.unconvert,
dt.datetime: DateTimeType.unconvert,
tuple: TupleType.unconvert,
list: ArrayType.unconvert,
type(None): NullableType.unconvert,
UUID: UUIDType.unconvert,
Decimal: DecimalType.unconvert,
}
def what_py_type(name: str, container: bool = False) -> BaseType:
""" Returns needed type class from clickhouse type name """
name = name.strip()
try:
return CH_TYPES_MAPPING[name.split("(")[0]](name, container=container)
@staticmethod
def unconvert(value: Decimal) -> bytes:
return str(value).encode()
CH_TYPES_MAPPING = {
"UInt8": IntType,
"UInt16": IntType,
"UInt32": IntType,
"UInt64": IntType,
"Int8": IntType,
"Int16": IntType,
"Int32": IntType,
"Int64": IntType,
"Float32": FloatType,
"Float64": FloatType,
"String": StrType,
"FixedString": StrType,
"Enum8": StrType,
"Enum16": StrType,
"Date": DateType,
"DateTime": DateTimeType,
"Tuple": TupleType,
"Array": ArrayType,
"Nullable": NullableType,
"Nothing": NothingType,
"UUID": UUIDType,
"LowCardinality": LowCardinalityType,
"Decimal": DecimalType,
"Decimal32": DecimalType,
"Decimal64": DecimalType,