【问题标题】:clickhouse attach materialized view errorclickhouse附加物化视图错误
【发布时间】: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_table another_table 是什么?该表在哪个数据库中?
  • 它在同一个数据库中。刚刚更新了表定义,使其更接近于我正在尝试做的事情。我自己创建了视图的inner 表(net_by_country_15m),然后尝试附加视图,但它不起作用。
  • 使用CREATE 可以。

标签: docker clickhouse


【解决方案1】:

应该是TO default.a_table

ATTACH MATERIALIZED VIEW v_by_country_15m  to default.a_table
AS (
       SELECT startTimestamp,
              clientCountry,
              sum(bytes) as bytes
       FROM another_table
       GROUP BY startTimestamp, clientCountry
)

【讨论】:

  • 这实际上是一个复制粘贴错误。我那里确实有TO。无论如何,再次运行它,错误是一样的:DB::Exception: Table v_by_country_15m doesn't exist.。感谢您的帮助
猜你喜欢
  • 2018-10-27
  • 2021-12-06
  • 2021-10-09
  • 2019-01-28
  • 2018-12-28
  • 2018-11-10
  • 2021-01-09
  • 2021-06-13
  • 1970-01-01
相关资源
最近更新 更多