ClickHouse / dbt-clickhouse

The Clickhouse plugin for dbt (data build tool)
Apache License 2.0
255 stars 113 forks source link

How do we create distributed table based on materialized view? #302

Closed hueiyuan closed 5 months ago

hueiyuan commented 5 months ago

Describe

As a title, How do we create distributed table based on materialized view? because we have create materialized view on cluster. But if we would like to read all of node from materialized view, need to create distributed table to query.

Example:

CREATE TABLE IF NOT EXISTS db.table ON CLUSTER '{cluster}'(
.....
)

CREATE MATERIALIZED VIEW IF NOT EXISTS db.table_mv ON CLUSTER '{cluster}' TO db.table AS
SELECT
.....

CREATE TABLE IF NOT EXISTS db.dist_table ON CLUSTER '{cluster}' ENGINE=Distributed('{cluster}', db, table, rand());

In order to achieve this objective, how do we set config on sql?

Hope someone can assist to answer it, I will be appreciate it, thank you.

bigEvilBanana commented 5 months ago

As a workaround you could create another model with view materialization for your local table

{{ config(materialized='view') }}

SELECT *
FROM clusterAllReplicas('cluster_name', {{ ref('local_table') }}) SETTINGS final = 1