从Clickhouse的JSON列中提取所有可能的键
我在Clickhouse中有一个具有属性
列的表。此列是 JSON类型列,并存储一个具有多个键和值的对象。没有数组,只有一个具有多个键和值的对象。
我要做的是构建列中存在的所有唯一密钥名称的列表。
因此,如果该列具有此对象:
{ age: '25'}
以及此对象:
{ genre: 'pop'}
我想检索age
和类型
作为此查询的结果。
有什么办法可以做到吗?
I have a table in Clickhouse that has a properties
column. This column is a JSON type column and stores an object with several keys and values. No arrays, just a single object with multiple keys and values.
What I am trying to do is to build a list of all the unique key names present in the column.
So, if the column has this object:
{ age: '25'}
And also this object:
{ genre: 'pop'}
I'd like to retrieve age
and genre
as results for this query.
Any way this can be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用“ draction命令condict_extend_object_types = 1;
例如:
JSON_TEST
表中的“值”列实际上是JSON类型,但是它当前存储两个键,JSON_KEY
是INT8,value ,这是字符串类型。
我相信目前,您必须分析描述表查询的结果,以在另一个查询中使用这些列名/键。
You can retrieve all of the inferred columns/keys from a ClickHouse JSON column using the DESCRIBE command with the setting describe_extend_object_types=1;
For example:
The value column in the
json_test
table is actually a JSON type, but it currently stores two keys,json_key
which is an Int8, andvalue
, which is a String type.I believe at the moment you'd have to parse the results of the DESCRIBE TABLE query to use those column names/keys in another query.
我最终意识到我的用例更适合地图列类型。
将其更改为地图后,做我想做的事很容易:
I ended up realizing that my use case is better suited for a MAP column type.
After changing it to Map, doing what I wanted was very easy: