I need to parse data from Kafka in ClickHouse using Kafka Engine, as example, I have created a table, in https://fiddle.clickhouse.com/0e89bec6-4e76-410a-9fc4-cf58ace5f34f,
CREATE TABLE json(name String, data Array(Map(String, String)) ) ENGINE = Memory;
INSERT INTO JSON FORMAT JSONEachRow {"name": "asd", "data":[{"id":"1", "name": "test1"},{"id":"2", "name": "test2"}]};
And I got 2 columns
name data
asd [{'id':'1', 'name': 'test1'},{'id':'2', 'name': 'test2'}]
How to transform to take the following result?
name id name
asd 1 test1
asd 2 test2
2
Answers
Does something like this work for what you need?
mapApply
joins thename
column with thedata
column, andarrayJoin
applies it to each element indata
:The response looks like:
Instead of storing the JSON as a
Map
of arrays, you could parse that data out into individual rows. This might make your queries much easier to write.You could do something like this to each row as it’s being inserted:
The result is:
(You can ignore the
row
column of that response, and insert the other three columns into your table)