Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revise the type system #2

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clickhouse_driver/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _pure_mutate_dicts_to_rows(
columns_with_cwt = []
for name, type_ in columns_with_types:
cwt = None
if type_.startswith('Nested'):
if type_.startswith('nested'):
cwt = nestedcolumn.get_columns_with_types(type_)
columns_with_cwt.append((name, cwt))

Expand Down
4 changes: 2 additions & 2 deletions clickhouse_driver/columns/datecolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class DateColumn(FormatColumn):
ch_type = 'Date'
ch_type = 'date'
py_types = (date, )
format = 'H'

Expand Down Expand Up @@ -55,7 +55,7 @@ def after_read_items(self, items, nulls_map=None):


class Date32Column(DateColumn):
ch_type = 'Date32'
ch_type = 'date32'
format = 'i'

min_value = epoch_start_date32
Expand Down
7 changes: 4 additions & 3 deletions clickhouse_driver/columns/datetimecolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class DateTimeColumn(FormatColumn):
ch_type = 'DateTime'
ch_type = 'datetime'
py_types = (datetime, int)
format = 'I'

Expand Down Expand Up @@ -85,7 +85,7 @@ def before_write_items(self, items, nulls_map=None):


class DateTime64Column(DateTimeColumn):
ch_type = 'DateTime64'
ch_type = 'datetime64'
format = 'q'

max_scale = 6
Expand Down Expand Up @@ -170,7 +170,7 @@ def before_write_items(self, items, nulls_map=None):


def create_datetime_column(spec, column_options):
if spec.startswith('DateTime64'):
if spec.startswith('datetime64'):
cls = DateTime64Column
spec = spec[11:-1]
params = spec.split(',', 1)
Expand All @@ -193,6 +193,7 @@ def create_datetime_column(spec, column_options):
else:
if not context.settings.get('use_client_time_zone', False):
local_timezone = get_localzone_name_compat()

if local_timezone != context.server_info.timezone:
tz_name = context.server_info.timezone

Expand Down
10 changes: 6 additions & 4 deletions clickhouse_driver/columns/decimalcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
class DecimalColumn(FormatColumn):
py_types = (Decimal, float, int)
max_precision = None
int_size = None

def __init__(self, precision, scale, types_check=False, **kwargs):
self.precision = precision
self.scale = scale
super(DecimalColumn, self).__init__(**kwargs)

if types_check:
def check_item(value):
parts = str(value).split('.')
int_part = parts[0]
max_signed_int = (1 << (8 * self.int_size - 1)) - 1

if len(int_part) > precision:
def check_item(value):
if value < -max_signed_int or value > max_signed_int:
raise ColumnTypeMismatchException(value)

self.check_item = check_item
Expand Down Expand Up @@ -80,11 +80,13 @@ def _read_data(self, n_items, buf, nulls_map=None):
class Decimal32Column(DecimalColumn):
format = 'i'
max_precision = 9
int_size = 4


class Decimal64Column(DecimalColumn):
format = 'q'
max_precision = 18
int_size = 8


class Decimal128Column(DecimalColumn, Int128Column):
Expand Down
6 changes: 3 additions & 3 deletions clickhouse_driver/columns/enumcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ def after_read_items(self, items, nulls_map=None):


class Enum8Column(EnumColumn):
ch_type = 'Enum8'
ch_type = 'enum8'
format = 'b'
int_size = 1


class Enum16Column(EnumColumn):
ch_type = 'Enum16'
ch_type = 'enum16'
format = 'h'
int_size = 2


def create_enum_column(spec, column_options):
if spec.startswith('Enum8'):
if spec.startswith('enum8'):
params = spec[6:-1]
cls = Enum8Column
else:
Expand Down
4 changes: 2 additions & 2 deletions clickhouse_driver/columns/floatcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FloatColumn(FormatColumn):


class Float32Column(FloatColumn):
ch_type = 'Float32'
ch_type = 'float32'
format = 'f'

def __init__(self, types_check=False, **kwargs):
Expand All @@ -30,5 +30,5 @@ def before_write_items(items, nulls_map=None):


class Float64Column(FloatColumn):
ch_type = 'Float64'
ch_type = 'float64'
format = 'd'
24 changes: 12 additions & 12 deletions clickhouse_driver/columns/intcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,49 @@ def check_item(value):


class Int8Column(IntColumn):
ch_type = 'Int8'
ch_type = 'int8'
format = 'b'
int_size = 1


class Int16Column(IntColumn):
ch_type = 'Int16'
ch_type = 'int16'
format = 'h'
int_size = 2


class Int32Column(IntColumn):
ch_type = 'Int32'
ch_type = 'int32'
format = 'i'
int_size = 4


class Int64Column(IntColumn):
ch_type = 'Int64'
ch_type = 'int64'
format = 'q'
int_size = 8


class UInt8Column(UIntColumn):
ch_type = 'UInt8'
ch_type = 'uint8'
format = 'B'
int_size = 1


class UInt16Column(UIntColumn):
ch_type = 'UInt16'
ch_type = 'uint16'
format = 'H'
int_size = 2


class UInt32Column(UIntColumn):
ch_type = 'UInt32'
ch_type = 'uint32'
format = 'I'
int_size = 4


class UInt64Column(UIntColumn):
ch_type = 'UInt64'
ch_type = 'uint64'
format = 'Q'
int_size = 8

Expand Down Expand Up @@ -122,7 +122,7 @@ def read_items(self, n_items, buf):


class Int128Column(LargeIntColumn):
ch_type = 'Int128'
ch_type = 'int128'
int_size = 16
factor = 2

Expand All @@ -131,7 +131,7 @@ class Int128Column(LargeIntColumn):


class UInt128Column(LargeIntColumn):
ch_type = 'UInt128'
ch_type = 'uint128'
int_size = 16
factor = 2

Expand All @@ -140,7 +140,7 @@ class UInt128Column(LargeIntColumn):


class Int256Column(LargeIntColumn):
ch_type = 'Int256'
ch_type = 'int256'
int_size = 32
factor = 4

Expand All @@ -149,7 +149,7 @@ class Int256Column(LargeIntColumn):


class UInt256Column(LargeIntColumn):
ch_type = 'UInt256'
ch_type = 'uint256'
int_size = 32
factor = 4

Expand Down
14 changes: 7 additions & 7 deletions clickhouse_driver/columns/intervalcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ class IntervalColumn(Int64Column):


class IntervalDayColumn(IntervalColumn):
ch_type = 'IntervalDay'
ch_type = 'interval_day'


class IntervalWeekColumn(IntervalColumn):
ch_type = 'IntervalWeek'
ch_type = 'interval_week'


class IntervalMonthColumn(IntervalColumn):
ch_type = 'IntervalMonth'
ch_type = 'interval_month'


class IntervalYearColumn(IntervalColumn):
ch_type = 'IntervalYear'
ch_type = 'interval_year'


class IntervalHourColumn(IntervalColumn):
ch_type = 'IntervalHour'
ch_type = 'interval_hour'


class IntervalMinuteColumn(IntervalColumn):
ch_type = 'IntervalMinute'
ch_type = 'interval_minute'


class IntervalSecondColumn(IntervalColumn):
ch_type = 'IntervalSecond'
ch_type = 'interval_second'
4 changes: 2 additions & 2 deletions clickhouse_driver/columns/ipcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class IPv4Column(UInt32Column):
ch_type = "IPv4"
ch_type = "ipv4"
py_types = (str, IPv4Address, int)

def __init__(self, types_check=False, **kwargs):
Expand Down Expand Up @@ -65,7 +65,7 @@ def before_write_items(self, items, nulls_map=None):


class IPv6Column(ByteFixedString):
ch_type = "IPv6"
ch_type = "ipv6"
py_types = (str, IPv6Address, bytes)

def __init__(self, types_check=False, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_driver/columns/nothingcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class NothingColumn(FormatColumn):
ch_type = 'Nothing'
ch_type = 'nothing'
format = 'B'

@property
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_driver/columns/nullcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# TODO: Drop Null column support in future.
# Compatibility with old servers.
class NullColumn(FormatColumn):
ch_type = 'Null'
ch_type = 'NULL'
format = 'B'

@property
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_driver/columns/numpy/datecolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class NumpyDateColumn(NumpyColumn):
dtype = np.dtype(np.uint16)
ch_type = 'Date'
ch_type = 'date'

null_value = np.datetime64(0, 'Y')

Expand Down
2 changes: 1 addition & 1 deletion clickhouse_driver/columns/numpy/datetimecolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def write_items(self, items, buf):


def create_numpy_datetime_column(spec, column_options):
if spec.startswith('DateTime64'):
if spec.startswith('datetime64'):
cls = NumpyDateTime64Column
spec = spec[11:-1]
params = spec.split(',', 1)
Expand Down
4 changes: 2 additions & 2 deletions clickhouse_driver/columns/numpy/floatcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class NumpyFloat32Column(NumpyColumn):
dtype = np.dtype(np.float32)
ch_type = 'Float32'
ch_type = 'float32'
normalize_null_value = False

def _get_nulls_map(self, items):
Expand All @@ -17,7 +17,7 @@ def _get_nulls_map(self, items):

class NumpyFloat64Column(NumpyColumn):
dtype = np.dtype(np.float64)
ch_type = 'Float64'
ch_type = 'float64'
normalize_null_value = False

def _get_nulls_map(self, items):
Expand Down
16 changes: 8 additions & 8 deletions clickhouse_driver/columns/numpy/intcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@

class NumpyInt8Column(NumpyColumn):
dtype = np.dtype(np.int8)
ch_type = 'Int8'
ch_type = 'int8'


class NumpyUInt8Column(NumpyColumn):
dtype = np.dtype(np.uint8)
ch_type = 'UInt8'
ch_type = 'uint8'


class NumpyInt16Column(NumpyColumn):
dtype = np.dtype(np.int16)
ch_type = 'Int16'
ch_type = 'int16'


class NumpyUInt16Column(NumpyColumn):
dtype = np.dtype(np.uint16)
ch_type = 'UInt16'
ch_type = 'uint16'


class NumpyInt32Column(NumpyColumn):
dtype = np.dtype(np.int32)
ch_type = 'Int32'
ch_type = 'int32'


class NumpyUInt32Column(NumpyColumn):
dtype = np.dtype(np.uint32)
ch_type = 'UInt32'
ch_type = 'uint32'


class NumpyInt64Column(NumpyColumn):
dtype = np.dtype(np.int64)
ch_type = 'Int64'
ch_type = 'int64'


class NumpyUInt64Column(NumpyColumn):
dtype = np.dtype(np.uint64)
ch_type = 'UInt64'
ch_type = 'uint64'
Loading