【发布时间】:2021-07-24 15:15:18
【问题描述】:
鉴于这个 dockerfile
FROM yandex/clickhouse-server:20.6.4.44
COPY default /var/lib/clickhouse/metadata/default
并将这些 sql 文件放在 default 目录中:
ATTACH TABLE IF NOT EXISTS default.a_table (
`startTimestamp` DateTime,
`fieldNumber` UInt32,
`clientCountry` UInt16,
`packets` UInt64,
`bytes` UInt64
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(startTimestamp)
ORDER BY (startTimestamp, clientCountry)
SETTINGS index_granularity = 8192
ATTACH TABLE IF NOT EXISTS default.net_by_country_15m (
`startTimestamp` DateTime,
`clientCountry` UInt16,
`bytes` UInt64
)
ENGINE = SummingMergeTree()
PARTITION BY toYYYYMM(startTimestamp)
ORDER BY (startTimestamp, clientCountry)
SETTINGS index_granularity = 8192;
还有这个观点:
ATTACH MATERIALIZED VIEW v_by_country_15m TO default.net_by_country_15m
AS (
SELECT startTimestamp,
clientCountry,
sum(bytes) as bytes
FROM default.a_table
GROUP BY startTimestamp, clientCountry
)
容器没有启动并手动运行我得到的语句
Received from localhost:9000. DB::Exception: Table `v_by_country_15m` doesn't exist.
(这是clickhouse: create materialized view on startup (docker) 的后续行动,但我不想使用docker-entrypoint-initdb.d 目录,而是想继续使用metadata 目录,因为这是我继承的一个项目,并且不想改变太多,直到我更好地了解 Clickhouse)。
(更新的表定义)
【问题讨论】:
-
FROM another_tableanother_table 是什么?该表在哪个数据库中? -
它在同一个数据库中。刚刚更新了表定义,使其更接近于我正在尝试做的事情。我自己创建了视图的
inner表(net_by_country_15m),然后尝试附加视图,但它不起作用。 -
使用
CREATE可以。
标签: docker clickhouse