housepower / clickhouse_sinker

Easily load data from kafka to ClickHouse
https://housepower.github.io/clickhouse_sinker
Apache License 2.0
516 stars 118 forks source link

如何写入clickhouse的array字段 #21

Closed maidangdang closed 4 years ago

maidangdang commented 4 years ago

clickhouse表: CREATE TABLE test.test(gname String, glist Array(String)) ENGINE = Memory

task/json_reques.json: { "name" : "json_test",

    "kafka": "kfk",
    "topic": "test",
    "earliest" : false,
    "consumerGroup" : "testgroup1",
    "parser" : "json",

    "clickhouse" : "ch",
    "tableName" : "test",

    "@desc_of_autoSchema" : "auto schema will auto fetch the schema from clickhouse",
    "autoSchema" : true,
    "@desc_of_exclude_columns" : "this columns will be excluded by insert SQL ",
    "excludeColumns" : [],
    "bufferSize" : 90000

}

往kafka写入数据: {"gname": "name", "glist":["1","2"]} {"gname": "name", "glist":['1','2']}

最后从clickhouse查到gname列是写进去了,但是glist写不进去。 请问下: 1.写array列应该怎样写? 2.是否支持写clickhouse的map类型字段,支持的话也给个demo

谢谢!

sundy-li commented 4 years ago

好的,最近工作比较忙,我们内部版本是实现了 复杂json的拓展的, 包括array, map类型(展开), 但是nested类型 还没支持

maidangdang commented 4 years ago

@sundy-li 感谢回复,但是我看不到回复的内容,麻烦看看,谢谢!

另外,前面的问题2,应该是:clickhouse_sinker是否支持写clickhouse的nested字段?,支持的话也给个demo

sundy-li commented 4 years ago

@maidangdang 加入了 GjsonParser, 这里是 map,array的解析示例 https://github.com/housepower/clickhouse_sinker/blob/master/parser/parser_test.go#L84