Skip to content

Commit

Permalink
change relation matching to case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
bachng2017 authored and hovaesco committed Oct 4, 2022
1 parent e9194b1 commit 537e38e
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20221002-081603.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Ignore case when matching relations
time: 2022-10-02T08:16:03.70013648Z
custom:
Author: bachng2017
Issue: "140"
PR: "141"
5 changes: 5 additions & 0 deletions dbt/adapters/trino/relation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass

from dbt.adapters.base.relation import BaseRelation, Policy
from dbt.contracts.relation import ComponentName


@dataclass
Expand All @@ -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()
41 changes: 41 additions & 0 deletions tests/functional/adapter/store_failures/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
seed_csv = """
id,value
1,1
2,2
3,3
4,4
""".lstrip()

table_model = """
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
"""
59 changes: 59 additions & 0 deletions tests/functional/adapter/store_failures/test_store_failures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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 TestStoreFailuresTable:
@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,
}

@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

0 comments on commit 537e38e

Please sign in to comment.