Clickhouse/Kafka: 将 JSON 对象类型读入字段
Clickhouse/Kafka: reading a JSON Object type into a field
我在 Kafka 主题中有这种数据:
{..., fields: { "a": "aval", "b": "bval" } }
如果我创建 Kafka 引擎 table,我在使用这样的字段定义时会收到错误消息:
fields 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)
由于 ClickHouse 目前没有 Map
或 JSONObject
类型,如果我事先不知道内部字段的名称,最好的处理方法是什么(示例中的 "a" 或 "b" - 所以我看不到嵌套结构有帮助)?
显然,目前 ClickHouse 不支持复杂的 JSON 解析。
来自 ClickHouse answer Github:
Clickhouse uses quick and dirty JSON parser, which does not how to read complex deep structures. 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.
我在 Kafka 主题中有这种数据:
{..., fields: { "a": "aval", "b": "bval" } }
如果我创建 Kafka 引擎 table,我在使用这样的字段定义时会收到错误消息:
fields 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)
由于 ClickHouse 目前没有 Map
或 JSONObject
类型,如果我事先不知道内部字段的名称,最好的处理方法是什么(示例中的 "a" 或 "b" - 所以我看不到嵌套结构有帮助)?
显然,目前 ClickHouse 不支持复杂的 JSON 解析。
来自 ClickHouse answer Github:
Clickhouse uses quick and dirty JSON parser, which does not how to read complex deep structures. 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.