From e3a19ad10c062297b9f3a648bd2122532a0e4607 Mon Sep 17 00:00:00 2001 From: NGUYEN HUU BACH Date: Sat, 1 Oct 2022 16:46:16 +0000 Subject: [PATCH] change relation matching to case-insensitive --- .../unreleased/Fixes-20221002-081603.yaml | 7 ++ dbt/adapters/trino/relation.py | 5 ++ .../adapter/store_failures/fixtures.py | 42 ++++++++++++ .../store_failures/test_store_failures.py | 65 +++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 .changes/unreleased/Fixes-20221002-081603.yaml create mode 100644 tests/functional/adapter/store_failures/fixtures.py create mode 100644 tests/functional/adapter/store_failures/test_store_failures.py diff --git a/.changes/unreleased/Fixes-20221002-081603.yaml b/.changes/unreleased/Fixes-20221002-081603.yaml new file mode 100644 index 00000000..ea7aafd4 --- /dev/null +++ b/.changes/unreleased/Fixes-20221002-081603.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Ignore case when matching relations ([#140](https://github.com/starburstdata/dbt-trino/issues/140) +time: 2022-10-02T08:16:03.70013648Z +custom: + Author: bachng2017 + Issue: "140" + PR: "141" diff --git a/dbt/adapters/trino/relation.py b/dbt/adapters/trino/relation.py index 14d899fa..fd194486 100644 --- a/dbt/adapters/trino/relation.py +++ b/dbt/adapters/trino/relation.py @@ -1,6 +1,7 @@ from dataclasses import dataclass from dbt.adapters.base.relation import BaseRelation, Policy +from dbt.contracts.relation import ComponentName @dataclass @@ -13,3 +14,7 @@ class TrinoQuotePolicy(Policy): @dataclass(frozen=True, eq=False, repr=False) class TrinoRelation(BaseRelation): quote_policy: TrinoQuotePolicy = TrinoQuotePolicy() + + # Overridden as Trino converts relation identifiers to lowercase + def _is_exactish_match(self, field: ComponentName, value: str) -> bool: + return self.path.get_lowered_part(field) == value.lower() diff --git a/tests/functional/adapter/store_failures/fixtures.py b/tests/functional/adapter/store_failures/fixtures.py new file mode 100644 index 00000000..4f544a3c --- /dev/null +++ b/tests/functional/adapter/store_failures/fixtures.py @@ -0,0 +1,42 @@ +seed_csv = """ +id,value +1,1 +2,2 +3,3 +4,4 +""".lstrip() + +table_model = """ +{{config(materialized = "table")}} +select * from {{ ref('seed') }} +""" + +table_profile_yml = """ +version: 2 +models: + - name: table_model + columns: + - name: id + tests: + - unique + - not_null + - name: value + quote: true + tests: + - not_null + - accepted_values: + values: + - 1 + - 2 + - 3 + - 4 + quote: false + +seeds: + - name: seed + columns: + - name: id + - name: value + tests: + - not_null +""" diff --git a/tests/functional/adapter/store_failures/test_store_failures.py b/tests/functional/adapter/store_failures/test_store_failures.py new file mode 100644 index 00000000..4e3546fb --- /dev/null +++ b/tests/functional/adapter/store_failures/test_store_failures.py @@ -0,0 +1,65 @@ +import pytest +from dbt.tests.util import run_dbt + +from tests.functional.adapter.store_failures.fixtures import ( + seed_csv, + table_model, + table_profile_yml, +) + + +class TestStoreFailuresBase: + """ + Testing store_failures functionality + """ + + @property + def schema(self): + return "default" + + # everything that goes in the "seeds" directory + @pytest.fixture(scope="class") + def seeds(self): + return { + "seed.csv": seed_csv, + } + + +class TestStoreFailuresTable(TestStoreFailuresBase): + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "name": "store_failures_tests", + "quoting": { + "database": False, + "schema": False, + "identifier": True, + }, + "models": { + "+materialized": "table", + }, + "tests": { + "+store_failures": True, + }, + } + + # everything that goes in the "models" directory + @pytest.fixture(scope="class") + def models(self): + return { + "table_model.sql": table_model, + "table_store_failures.yml": table_profile_yml, + } + + def test_run_seed_test(self, project): + # seed seeds + results = run_dbt(["seed"], expect_pass=True) + assert len(results) == 1 + results = run_dbt(["run"], expect_pass=True) + assert len(results) == 1 + # test tests + results = run_dbt(["test"], expect_pass=True) + assert len(results) == 5 + # test tests 2nd times + results = run_dbt(["test"], expect_pass=True) + assert len(results) == 5