【问题标题】:clickhouse: create materialized view on startup (docker)clickhouse:在启动时创建物化视图(docker)
【发布时间】:2021-04-30 19:02:02
【问题描述】:

我正在尝试设置一个在启动时具有物化视图的本地开发泊坞窗。所以有了这个 Dockerfile:

FROM yandex/clickhouse-server:20.6.4.44
COPY default /var/lib/clickhouse/metadata/default

default 中我们有这两个定义:

a_table.sql:

CREATE TABLE default.a_table (
    `startTimestamp` DateTime,
    `fieldNumber` UInt32,
    `clientCountry` UInt16,
    `packets` UInt64,
    `bytes` UInt64
)
ENGINE = SummingMergeTree()
PARTITION BY toYYYYMM(startTimestamp)
ORDER BY (startTimestamp, clientCountry)
SETTINGS index_granularity = 8192

还有观点,v_by_country_15m.sql::

CREATE MATERIALIZED VIEW v_by_country_15m 
ENGINE = SummingMergeTree()
PARTITION BY toYYYYMM(startTimestamp)
PRIMARY KEY (startTimestamp, clientCountry)
ORDER BY (startTimestamp, clientCountry)
AS (
       SELECT startTimestamp,
              clientCountry,
              sum(bytes) as bytes
       FROM a_table
       GROUP BY startTimestamp, clientCountry
)

如果我只在default 文件夹中包含a_table.sql 文件,容器可以正常启动,但如果我在default 文件夹中包含v_by_country_15m.sql 文件,它无法启动。如果我只从表格开始,然后 execclickhouse-client 并创建物化视图,它就可以工作,所以我认为问题不在于物化视图本身。

我们可以对启动有具体的看法吗?

【问题讨论】:

  • 但元数据文件夹存储附加脚本未创建
  • 嗨@DennyCrane 但是当它是一个表时似乎没有什么区别(表已创建)。实践上有什么不同?
  • 差别很大,我无法在评论中解释。你应该使用附加。
  • 好的,谢谢。将所有内容更改为ATTACH,但现在有另一个问题.. 你能帮忙stackoverflow.com/questions/67348100/…吗?

标签: docker clickhouse


【解决方案1】:

需要将sql-scripts复制到/docker-entrypoint-initdb.d/-folder:

FROM yandex/clickhouse-server:20.6.4.44
COPY default/* /docker-entrypoint-initdb.d/

检查一下:

docker build -t test_ch:latest  .
docker run test_ch

docker exec -it {container-id} bash
> clickhouse client
  > USE default
  > SHOW TABLES
  > ┌─name────────────────────┐
  > │ .inner.v_by_country_15m │
  > │ a_table                 │
  > │ v_by_country_15m        │
  > └─────────────────────────┘

【讨论】:

    猜你喜欢
    • 2021-01-09
    • 2021-12-06
    • 2021-08-07
    • 2021-07-24
    • 2021-10-09
    • 2021-05-04
    • 2019-01-28
    • 2018-12-28
    • 2018-11-10
    相关资源
    最近更新 更多