Skip to content

Commit

Permalink
add test for range dictionary layout
Browse files Browse the repository at this point in the history
  • Loading branch information
rjoelnorgren committed Oct 31, 2024
1 parent 01dd31a commit 86f8843
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/integration/adapter/dictionary/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"

0 comments on commit 86f8843

Please sign in to comment.