mirror of
https://github.com/hanzo-ds/driver.git
synced 2026-10-30 20:32:40 +00:00
Imports read `datastore_driver`, distribution `datastore-driver`, so nothing has to import another product's name to talk to Hanzo Datastore. Cut from upstream 0.2.9 — the version this stack already ran — rather than from upstream HEAD, so it is a PURE RENAME with no behaviour change. Forking from HEAD would have dragged versions along with the name (connect alone jumped 0.8.17 -> 1.6.0, a major), which is a different and much riskier change wearing a rename's clothes. X-ClickHouse-* headers are untouched: they are wire protocol the server sends and expects, and a different token shape from the module name.
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
|
|
from .base import Column
|
|
from .util import get_inner_spec, get_inner_columns_with_types
|
|
|
|
|
|
class TupleColumn(Column):
|
|
py_types = (list, tuple)
|
|
|
|
def __init__(self, names, nested_columns, **kwargs):
|
|
self.names = names
|
|
self.nested_columns = nested_columns
|
|
client_settings = kwargs['context'].client_settings
|
|
settings = kwargs['context'].settings
|
|
self.namedtuple_as_json = (
|
|
settings.get('allow_experimental_object_type', False) and
|
|
client_settings.get('namedtuple_as_json', True)
|
|
)
|
|
|
|
super(TupleColumn, self).__init__(**kwargs)
|
|
self.null_value = tuple(x.null_value for x in nested_columns)
|
|
|
|
def write_data(self, items, buf):
|
|
items = self.prepare_items(items)
|
|
items = list(zip(*items))
|
|
|
|
for i, x in enumerate(self.nested_columns):
|
|
x.write_data(list(items[i]), buf)
|
|
|
|
def write_items(self, items, buf):
|
|
return self.write_data(items, buf)
|
|
|
|
def read_data(self, n_items, buf):
|
|
rv = [x.read_data(n_items, buf) for x in self.nested_columns]
|
|
rv = list(zip(*rv))
|
|
|
|
if self.names[0] and self.namedtuple_as_json:
|
|
return [dict(zip(self.names, x)) for x in rv]
|
|
else:
|
|
return rv
|
|
|
|
def read_items(self, n_items, buf):
|
|
return self.read_data(n_items, buf)
|
|
|
|
def read_state_prefix(self, buf):
|
|
super(TupleColumn, self).read_state_prefix(buf)
|
|
|
|
for x in self.nested_columns:
|
|
x.read_state_prefix(buf)
|
|
|
|
def write_state_prefix(self, buf):
|
|
super(TupleColumn, self).write_state_prefix(buf)
|
|
|
|
for x in self.nested_columns:
|
|
x.write_state_prefix(buf)
|
|
|
|
|
|
def create_tuple_column(spec, column_by_spec_getter, column_options):
|
|
inner_spec = get_inner_spec('Tuple', spec)
|
|
columns_with_types = get_inner_columns_with_types(inner_spec)
|
|
names, types = zip(*columns_with_types)
|
|
|
|
return TupleColumn(names, [column_by_spec_getter(x) for x in types],
|
|
**column_options)
|