Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
### Next Version

#### New Features
* [ClickHouse indexes](https://clickhouse.com/docs/en/optimize/sparse-primary-indexes) are now fully supported for `table` materialization.
The index config should be added to the model config. for instance:
```python
{{ config(
materialized='%s',
indexes=[{
'name': 'your_index_name',
'definition': 'your_column TYPE minmax GRANULARITY 2'
}]
) }}
```

### Release [1.8.7], 2025-01-05

### New Features
Expand Down
14 changes: 13 additions & 1 deletion dbt/include/clickhouse/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@
{% if config.get('projections')%}
{{ projection_statement(relation) }}
{% endif %}

{% if config.get('indexes') %}
{{ indexes_statement(relation) }}
{% endif %}

{{ clickhouse__insert_into(relation, sql, has_contract) }}
{%- endif %}
Expand All @@ -169,6 +171,16 @@
{%- endfor %}
{%- endmacro %}

{% macro indexes_statement(relation) %}
{%- set indexes = config.get('indexes', default=[]) -%}

{%- for index in indexes %}
{% call statement('add_indexes') %}
ALTER TABLE {{ relation }} ADD INDEX {{ index.get('name') }} {{ index.get('definition') }}
{%endcall %}
{%- endfor %}
{%- endmacro %}

{% macro create_table_or_empty(temporary, relation, sql, has_contract) -%}
{%- set sql_header = config.get('sql_header', none) -%}

Expand Down