Files
zeekay 999d38466d rename: this fork is ours — datastore_connect
Imports read `datastore_connect`, distribution `datastore-connect`, so nothing has to
import another product's name to talk to Hanzo Datastore.

Cut from upstream 0.8.17 — 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.
2026-07-26 11:01:30 -07:00

35 lines
1.7 KiB
Python

from pathlib import Path
from typing import Callable
from datastore_connect.driver import Client
def test_raw_insert(test_client: Client, table_context: Callable):
with table_context('test_raw_insert', ["`weir'd` String", 'value String']):
csv = 'value1\nvalue2'
test_client.raw_insert('test_raw_insert', ['"weir\'d"'], csv.encode(), fmt='CSV')
result = test_client.query('SELECT * FROM test_raw_insert')
assert result.result_set[1][0] == 'value2'
test_client.command('TRUNCATE TABLE test_raw_insert')
tsv = 'weird1\tvalue__`2\nweird2\tvalue77'
test_client.raw_insert('test_raw_insert', ["`weir'd`", 'value'], tsv, fmt='TSV')
result = test_client.query('SELECT * FROM test_raw_insert')
assert result.result_set[0][1] == 'value__`2'
assert result.result_set[1][1] == 'value77'
def test_raw_insert_compression(test_client: Client, table_context: Callable):
data_file = f'{Path(__file__).parent}/movies.csv.gz'
with open(data_file, mode='rb') as movies_file:
data = movies_file.read()
with table_context('test_gzip_movies', ['movie String', 'year UInt16', 'rating Decimal32(3)']):
test_client.raw_insert('test_gzip_movies', None, data, fmt='CSV', compression='gzip',
settings={'input_format_allow_errors_ratio': .2,
'input_format_allow_errors_num': 5}
)
res = test_client.query(
'SELECT count() as count, sum(rating) as rating, max(year) as year FROM test_gzip_movies').first_item
assert res['count'] == 248
assert res['year'] == 2022