简体   繁体   English

Clickhouse/Kafka:将 JSON 对象类型读入字段

[英]Clickhouse/Kafka: reading a JSON Object type into a field

I have this kind of data in a Kafka Topic:我在 Kafka 主题中有这种数据:

{..., fields: { "a": "aval", "b": "bval" } }

If I create a Kafka Engine table, I get an error when using a field definition like this:如果我创建一个 Kafka Engine 表,在使用这样的字段定义时会出现错误:

fields String

because it (correctly) doesn't recognize it as a String:因为它(正确地)无法将其识别为字符串:

2018.07.09 17:09:54.362061 [ 27 ] <Error> void DB::StorageKafka::streamThread(): Code: 26, e.displayText() = DB::Exception: Cannot parse JSON string: expected opening quote: (while read the value of key fields): (at row 1)

As ClickHouse does not currently have a Map or JSONObject type, what would be the best way to work over it, provided I don't know in advance the name of the inner fields ("a" or "b" in the example - so I cannot see Nested structures helping)?由于 ClickHouse 目前没有MapJSONObject类型,如果我事先不知道内部字段的名称(示例中的“a”或“b”),那么最好的处理方法是什么 - 所以我看不到嵌套结构有帮助)?

Apparently, at the moment ClickHouse does not support complex JSON parsing.显然,目前 ClickHouse 不支持复杂的 JSON 解析。

From this answer in ClickHouse Github:来自 ClickHouse Github 中的这个答案

Clickhouse uses quick and dirty JSON parser, which does not how to read complex deep structures. Clickhouse 使用快速而肮脏的 JSON 解析器,它不会读取复杂的深层结构。 So it can't skip that field as it does not know where that nested structure ends.所以它不能跳过那个字段,因为它不知道嵌套结构在哪里结束。 Sorry.对不起。 :/ :/

So you should preprocess your json with some external tools, of you can contribute to Clickhouse and improve JSON parser.所以你应该使用一些外部工具预处理你的 json,你可以为 Clickhouse 做出贡献并改进 JSON 解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM