Skip to content

Cannot create Refreshable Materialized View according to the documentation #513

@LPauzies

Description

@LPauzies

Describe the bug

I'm under dbt-clickhouse 1.9.1

Using this model, I should be able to create a refreshable materialized view :

{{  config(
        materialized='materialized_view',
        engine='AggregatingMergeTree()',
        refreshable={
            "interval": "EVERY 1 DAY",
            "randomize": "10 MINUTE"
        },
        order_by='(cleaned_name, city)'
    )
}}

with
    users as (
        select id, name, city, age
        from {{ ref('mat_users') }}
    )

select
    coalesce(name, '') as cleaned_name,
    city,
    countState() as count,
    avgState(age) as average_age
from users
group by name, city

The equivalent in SQL should be :

CREATE MATERIALIZED VIEW mv_agg ON CLUSTER '{cluster}'
REFRESH EVERY 1 DAY RANDOMIZE FOR 10 MINUTE
(
    cleaned_name String,
    city         String,
    count_state AggregateFunction(count, Int64),
    average_age_state AggregateFunction(avg, Decimal(10, 2))
)
ENGINE = AggregatingMergeTree()
ORDER BY (cleaned_name, city)
AS
(
    with
    users as (
        select id, name, city, age
        from {{ ref('mat_users') }}
    )

select
    cleaned_name,
    city,
    countState() as count,
    avgState(age) as average_age
from users
group by name, city
);

Expected behaviour

I expect to have a materialized view that can be retrieved using :

SELECT *
FROM system.view_refreshes
WHERE view = 'mv_agg'

But nothing appears...

Instead I have two elements : mv_agg_mv and mv_agg.

The first one is a classic MV at the sense of ClickHouse (insert trigger) while the other is a table with the correct engine. But this is not what I want... I would want to avoid multiple entities for nothing, while refreshing a simple MV is sufficient...

How would you achieve this in a DBT ClickHouse context ?

Configuration

Environment

  • dbt version: 1.9.8
  • dbt-clickhouse version: 1.9.1
  • clickhouse-driver version (if using native): 0.29
  • Python version: 3.12
  • Operating system: Ubuntu 22

ClickHouse server

  • ClickHouse Server version: 25.3.2.39

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions