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.
127 lines
3.5 KiB
Python
127 lines
3.5 KiB
Python
from datetime import date
|
|
|
|
from tests.testcase import BaseTestCase
|
|
from datastore_driver import errors
|
|
|
|
ErrorCodes = errors.ErrorCodes
|
|
|
|
|
|
class SparseTestCase(BaseTestCase):
|
|
required_server_version = (22, 1)
|
|
|
|
create_table_template = (
|
|
'CREATE TABLE test ({}) '
|
|
'ENGINE = MergeTree '
|
|
'ORDER BY tuple() '
|
|
'SETTINGS ratio_of_defaults_for_sparse_serialization = 0.5'
|
|
)
|
|
|
|
def test_int_all_defaults(self):
|
|
columns = 'a Int32'
|
|
|
|
data = [(0, ), (0, ), (0, )]
|
|
with self.create_table(columns):
|
|
self.client.execute(
|
|
'INSERT INTO test (a) VALUES', data
|
|
)
|
|
|
|
query = 'SELECT * FROM test'
|
|
inserted = self.emit_cli(query)
|
|
self.assertEqual(inserted, '0\n0\n0\n')
|
|
|
|
inserted = self.client.execute(query)
|
|
self.assertEqual(inserted, data)
|
|
|
|
data = [(0,)]
|
|
with self.create_table(columns):
|
|
self.client.execute(
|
|
'INSERT INTO test (a) VALUES', data
|
|
)
|
|
|
|
query = 'SELECT * FROM test'
|
|
inserted = self.emit_cli(query)
|
|
self.assertEqual(inserted, '0\n')
|
|
|
|
inserted = self.client.execute(query)
|
|
self.assertEqual(inserted, data)
|
|
|
|
def test_int_borders_cases(self):
|
|
columns = 'a Int32'
|
|
|
|
data = [(1, ), (0, ), (0, ), (1, ), (0, ), (0, ), (1, )]
|
|
with self.create_table(columns):
|
|
self.client.execute(
|
|
'INSERT INTO test (a) VALUES', data
|
|
)
|
|
|
|
query = 'SELECT * FROM test'
|
|
inserted = self.emit_cli(query)
|
|
self.assertEqual(inserted, '1\n0\n0\n1\n0\n0\n1\n')
|
|
|
|
inserted = self.client.execute(query)
|
|
self.assertEqual(inserted, data)
|
|
|
|
def test_int_default_last(self):
|
|
columns = 'a Int32'
|
|
|
|
data = [(1, ), (0, ), (0, )]
|
|
with self.create_table(columns):
|
|
self.client.execute(
|
|
'INSERT INTO test (a) VALUES', data
|
|
)
|
|
|
|
query = 'SELECT * FROM test'
|
|
inserted = self.emit_cli(query)
|
|
self.assertEqual(inserted, '1\n0\n0\n')
|
|
|
|
inserted = self.client.execute(query)
|
|
self.assertEqual(inserted, data)
|
|
|
|
def test_sparse_tuples(self):
|
|
columns = 'a Int32, b Tuple(Int32, Tuple(Int32, Int32))'
|
|
|
|
data = [
|
|
(1, (1, (1, 0))),
|
|
(0, (0, (0, 0))),
|
|
(0, (0, (0, 0)))
|
|
]
|
|
with self.create_table(columns):
|
|
self.client.execute(
|
|
'INSERT INTO test VALUES', data
|
|
)
|
|
|
|
query = 'SELECT * FROM test'
|
|
inserted = self.emit_cli(query)
|
|
self.assertEqual(
|
|
inserted,
|
|
'1\t(1,(1,0))\n'
|
|
'0\t(0,(0,0))\n'
|
|
'0\t(0,(0,0))\n'
|
|
)
|
|
|
|
inserted = self.client.execute(query)
|
|
self.assertEqual(inserted, data)
|
|
|
|
def test_sparse_dates(self):
|
|
columns = 'a Date32'
|
|
|
|
data = [
|
|
(date(1970, 1, 1), ),
|
|
(date(1970, 1, 1), ),
|
|
]
|
|
with self.create_table(columns):
|
|
self.client.execute(
|
|
'INSERT INTO test VALUES', data
|
|
)
|
|
|
|
query = 'SELECT * FROM test'
|
|
inserted = self.emit_cli(query)
|
|
self.assertEqual(
|
|
inserted,
|
|
'1970-01-01\n'
|
|
'1970-01-01\n'
|
|
)
|
|
|
|
inserted = self.client.execute(query)
|
|
self.assertEqual(inserted, data)
|