From 01dd31abd6bd4537793598bfaa392e9a6492b67f Mon Sep 17 00:00:00 2001 From: Robin Norgren <68205730+rjoelnorgren@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:01:38 -0700 Subject: [PATCH 1/2] update CHANGELOG --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3d4536..09ae63d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Unreleased +### Improvement +* Added support for [range_hashed](https://clickhouse.com/docs/en/sql-reference/dictionaries#range_hashed) and [complex_key_range_hashed](https://clickhouse.com/docs/en/sql-reference/dictionaries#complex_key_range_hashed) layouts to the dictionary materialization. ([#361](https://github.com/ClickHouse/dbt-clickhouse/pull/361)) + ### Release [1.8.4], 2024-09-17 ### Improvement * The S3 help macro now support a `role_arn` parameter as an alternative way to provide authentication for S3 based models. Thanks to @@ -527,4 +531,4 @@ for Replicated tables that use the `{uuid}` macro in the path to avoid name conf [0.19.1]: https://github.com/ClickHouse/dbt-clickhouse/compare/v0.19.0.2...v0.19.1 [0.19.0.2]: https://github.com/ClickHouse/dbt-clickhouse/compare/v0.19.0.1...v0.19.0.2 [0.19.0.1]: https://github.com/ClickHouse/dbt-clickhouse/compare/v0.19.0...v0.19.0.1 -[0.19.0]: https://github.com/ClickHouse/dbt-clickhouse/compare/eb3020a...v0.19.0 \ No newline at end of file +[0.19.0]: https://github.com/ClickHouse/dbt-clickhouse/compare/eb3020a...v0.19.0 From 86f88438fd8f8eb398750fb2bcf1d18ec2fa7c98 Mon Sep 17 00:00:00 2001 From: Robin Norgren <68205730+rjoelnorgren@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:17:55 -0700 Subject: [PATCH 2/2] add test for range dictionary layout --- .../adapter/dictionary/test_dictionary.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/integration/adapter/dictionary/test_dictionary.py b/tests/integration/adapter/dictionary/test_dictionary.py index 77ee1aae..563d6b1a 100644 --- a/tests/integration/adapter/dictionary/test_dictionary.py +++ b/tests/integration/adapter/dictionary/test_dictionary.py @@ -6,6 +6,7 @@ import os import pytest + from dbt.tests.util import run_dbt testing_s3 = os.environ.get('DBT_CH_TEST_INCLUDE_S3', '').lower() in ('1', 'true', 'yes') @@ -114,6 +115,33 @@ - name: people """ +RANGE_DICTIONARY = """ +{{ config( + materialized='dictionary', + fields=[ + ('id', 'UInt8'), + ('start', 'UInt8'), + ('stop', 'UInt8'), + ('value', 'String') + ], + primary_key='id', + layout='RANGE_HASHED()', + lifetime='MIN 0 MAX 0', + source_type='clickhouse', + range='min start max stop' +) }} + +select + c1 as id, + c2 as start, + c3 as stop, + c4 as value +from values( + (0, 0, 2, 'foo'), + (0, 3, 5, 'bar') +) +""" + class TestQueryDictionary: @pytest.fixture(scope="class") @@ -193,3 +221,17 @@ def test_create(self, project): "select count(distinct LocationID) from taxi_zone_dictionary", fetch="all" ) assert results[0][0] == 265 + + +class TestRangeDictionary: + @pytest.fixture(scope="class") + def models(self): + return {"range_dictionary.sql": RANGE_DICTIONARY} + + def test_create(self, project): + run_dbt() + + results = project.run_sql("select dictGet(range_dictionary, 'value', 0, 1)", fetch="all") + assert results[0][0] == "foo" + results = project.run_sql("select dictGet(range_dictionary, 'value', 0, 5)", fetch="all") + assert results[0][0] == "bar"