Open denisov-vlad opened 1 week ago
That example works for me. What ClickHouse and clickhouse_connect versions are you using?
@genzgd
clickhouse-connect==0.8.3 clickhouse/clickhouse-server:24.9.2.42-alpine
Here's my exact code, on ClickHouse version 24.9.2.42 (latest docker image):
import datetime
from clickhouse_connect import get_client
from clickhouse_connect.datatypes.registry import get_from_name
create_table = '''
CREATE TABLE IF NOT EXISTS snowplow_json
(
`app_id` LowCardinality(String),
`page` String DEFAULT '',
`event_type` Enum8('pv' = 1, 'pp' = 2, 'ue' = 3, 'se' = 4, 'tr' = 5, 'ti' = 6, 's' = 7),
`session_id` UUID,
`device_id` UUID,
`time` DateTime64(3, 'UTC'),
`page_data` JSON
)
ENGINE = MergeTree
PARTITION BY (toYYYYMM(time), event_type)
ORDER BY (app_id, toDate(time), event_type, page, device_id, cityHash64(device_id), session_id, time)
SAMPLE BY cityHash64(device_id)
SETTINGS index_granularity = 8192'''
client = get_client(settings={'allow_experimental_json_type': 1})
client.command(create_table)
data = ['example', 'http://127.0.0.1:8000/demo/', 'pp', '94e0566f-5a03-4179-93c9-3acf28af95c6',
'b53c099a-45aa-4006-ae35-5716bcbecddc', datetime.datetime(2024, 10, 8, 9, 33, 48, 751039),
{'id': 'qwe123', 'type': 'main', 'section': None}]
names = ['app_id', 'page', 'event_type', 'session_id', 'device_id', 'time', 'page_data']
types = [get_from_name('String'),
get_from_name('String'),
get_from_name("Enum8('pv' = 1, 'pp' = 2, 'ue' = 3, 'se' = 4, 'tr' = 5, 'ti' = 6, 's' = 7)"),
get_from_name('UUID'),
get_from_name('UUID'),
get_from_name("DateTime64(3, 'UTC')"),
get_from_name('JSON')]
client.insert(
'snowplow_json',
data=[data],
column_names=names,
column_types=types,
)
SELECT *
FROM snowplow_json
FORMAT Vertical
Query id: c9389b42-5fb9-4101-9304-c6d91395449e
Row 1:
──────
app_id: example
page: http://127.0.0.1:8000/demo/
event_type: pp
session_id: 94e0566f-5a03-4179-93c9-3acf28af95c6
device_id: b53c099a-45aa-4006-ae35-5716bcbecddc
time: 2024-10-08 15:33:48.751
page_data: {"id":"qwe123","type":"main"}
What OS is your alpine container running on? I can't think of any other differences.
@genzgd I've found the reason. It doesn't work with async_insert=1
parameter and works without it.
Wow, thanks. That's a major problem. I'll open an issue in the main ClickHouse project.
New ClickHouse server issue here: https://github.com/ClickHouse/ClickHouse/issues/70490
Hello!
I'm facing with an insert issue with JSON column. Could you clarify how to correctly insert it please?
Here is the error string from ClickHouse:
I have a table
I'm trying to insert data there:
JSON column type is defined as: