Skip to content

Commit

Permalink
Required context in base column
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Apr 20, 2023
1 parent cdbfca5 commit 949a053
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
15 changes: 10 additions & 5 deletions clickhouse_driver/columns/arraycolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ArrayColumn(Column):
py_types = (list, tuple)

def __init__(self, nested_column, **kwargs):
self.size_column = UInt64Column()
self.init_kwargs = kwargs
self.size_column = UInt64Column(**kwargs)
self.nested_column = nested_column
self._write_depth_0_size = True
super(ArrayColumn, self).__init__(**kwargs)
Expand All @@ -37,17 +38,21 @@ def __init__(self, nested_column, **kwargs):
def write_data(self, data, buf):
# Column of Array(T) is stored in "compact" format and passed to server
# wrapped into another Array without size of wrapper array.
self.nested_column = ArrayColumn(self.nested_column)
self.nested_column = ArrayColumn(
self.nested_column, **self.init_kwargs
)
self.nested_column.nullable = self.nullable
self.nullable = False
self._write_depth_0_size = False
self._write(data, buf)

def read_data(self, rows, buf):
self.nested_column = ArrayColumn(self.nested_column)
def read_data(self, n_rows, buf):
self.nested_column = ArrayColumn(
self.nested_column, **self.init_kwargs
)
self.nested_column.nullable = self.nullable
self.nullable = False
return self._read(rows, buf)[0]
return self._read(n_rows, buf)[0]

def _write_sizes(self, value, buf):
nulls_map = []
Expand Down
7 changes: 3 additions & 4 deletions clickhouse_driver/columns/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ def __init__(self, types_check=False, **kwargs):
self.nullable = False
self.types_check_enabled = types_check
self.input_null_as_default = False
if 'context' in kwargs:
settings = kwargs['context'].client_settings
self.input_null_as_default = settings \
.get('input_format_null_as_default', False)
settings = kwargs['context'].client_settings
self.input_null_as_default = settings\
.get('input_format_null_as_default', False)

super(Column, self).__init__()

Expand Down
5 changes: 3 additions & 2 deletions clickhouse_driver/columns/lowcardinalitycolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class LowCardinalityColumn(Column):
serialization_type = has_additional_keys_bit | need_update_dictionary

def __init__(self, nested_column, **kwargs):
self.init_kwargs = kwargs
self.nested_column = nested_column
super(LowCardinalityColumn, self).__init__(**kwargs)

Expand Down Expand Up @@ -89,7 +90,7 @@ def _write_data(self, items, buf):
return

int_type = int(log(len(index), 2) / 8)
int_column = self.int_types[int_type]()
int_column = self.int_types[int_type](**self.init_kwargs)

serialization_type = self.serialization_type | int_type

Expand Down Expand Up @@ -120,7 +121,7 @@ def _read_data(self, n_items, buf, nulls_map=None):

# Lowest byte contains info about key type.
key_type = serialization_type & 0xf
keys_column = self.int_types[key_type]()
keys_column = self.int_types[key_type](**self.init_kwargs)

nullable = self.nested_column.nullable
# Prevent null map reading. Reset nested column nullable flag.
Expand Down
4 changes: 2 additions & 2 deletions clickhouse_driver/columns/mapcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MapColumn(Column):
null_value = {}

def __init__(self, key_column, value_column, **kwargs):
self.offset_column = UInt64Column()
self.offset_column = UInt64Column(**kwargs)
self.key_column = key_column
self.value_column = value_column
super(MapColumn, self).__init__(**kwargs)
Expand Down Expand Up @@ -57,7 +57,7 @@ def write_items(self, items, buf):


def create_map_column(spec, column_by_spec_getter, column_options):
# Match commas outside of parentheses so we don't match the comma in
# Match commas outside of parentheses, so we don't match the comma in
# Decimal types.
key, value = comma_re.split(spec[4:-1])
key_column = column_by_spec_getter(key.strip())
Expand Down
4 changes: 2 additions & 2 deletions clickhouse_driver/columns/numpy/lowcardinalitycolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _write_data(self, items, buf):
c = pd.Categorical(items)

int_type = int(log(len(c.codes), 2) / 8)
int_column = self.int_types[int_type]()
int_column = self.int_types[int_type](**self.init_kwargs)

serialization_type = self.serialization_type | int_type

Expand Down Expand Up @@ -66,7 +66,7 @@ def _read_data(self, n_items, buf, nulls_map=None):

# Lowest byte contains info about key type.
key_type = serialization_type & 0xf
keys_column = self.int_types[key_type]()
keys_column = self.int_types[key_type](**self.init_kwargs)

nullable = self.nested_column.nullable
# Prevent null map reading. Reset nested column nullable flag.
Expand Down

0 comments on commit 949a053

Please sign in to comment.