我用以下语句创建表:
CREATE TABLE event(
date Date,
src UInt8,
channel UInt8,
deviceTypeId UInt8,
projectId UInt64,
shows UInt32,
clicks UInt32,
spent Float64
) ENGINE = MergeTree(date, (date, src, channel, projectId), 8192);
原始数据如下所示:
{ "date":"2016-03-07T10:00:00+0300","src":2,"channel":18,"deviceTypeId ":101, "projectId":2363610,"shows":1232,"clicks":7,"spent":34.72,"location":"Unknown", ...}
...
使用以下命令加载数据的文件:
cat *.data|sed 's/T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]+0300//'| clickhouse-client --query="INSERT INTO event FORMAT JSONEachRow"
clickhouse-client抛出异常:
Code: 117. DB::Exception: Unknown field found while parsing JSONEachRow format: location: (at row 1)
是否可以跳过表描述中未显示的JSON对象中的字段?
最佳答案
最新的ClickHouse版本(v1.1.54023)支持input_format_skip_unknown_fields
用户选项,该选项可跳过JSONEachRow和TSKV格式的未知字段。
尝试
clickhouse-client -n --query="SET input_format_skip_unknown_fields=1; INSERT INTO event FORMAT JSONEachRow;"
在documentation中查看更多详细信息。
关于database - 将JSON导入ClickHouse,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39390174/