【发布时间】:2021-01-15 18:59:34
【问题描述】:
我要将数据从 PostgreSQL 数据库迁移到 Yandex 的 ClickHouse。
源表中的字段之一是 JSON 类型 - 称为 additional_data。因此,PostgreSQL 允许我 在例如访问 json 属性 SELECT ... 查询 ->> 和 -> 等等。
我需要在 ClickHouse 存储中的结果表中坚持相同的行为。 (即在选择查询和/或使用过滤和聚合子句时解析 JSON 的能力)
这是我在 ClickHouse 客户端 CREATE TABLE ... 期间所做的:
create table if not exists analytics.events
(
uuid UUID,
...,
created_at DateTime,
updated_at DateTime,
additional_data Nested (
message Nullable(String),
eventValue Nullable(String),
rating Nullable(String),
focalLength Nullable(Float64)
)
)
engine = MergeTree
ORDER BY (uuid, created_at)
PRIMARY KEY uuid;
如何存储 JSON 可序列化数据是一个不错的选择吗?有什么想法吗?
也许将 JSON 数据存储为纯 String 而不是 Nested 并使用 special functions 玩它更好?
【问题讨论】:
-
json-document的结构是固定不变的吗?
-
@vladimir 将来可以用一些新属性进行更改。
标签: sql clickhouse yandex yandex-metrika