Skip to content

Commit

Permalink
Update dbt-core to 1.6.0rc1
Browse files Browse the repository at this point in the history
- Update dbt-core and dbt-tests-adapter version to 1.6.0rc1
- Remove 'execute' method from TrinoConnectionManager, as implementation in SQLConnectionManager is sufficient, and new parameter was added there
- Remove redundant addition of query comments in 'add_query' method, as it is handled in 'execute' method in SQLConnectionManager class
- Revert "Fix tests for query comments." (commit a8309e9)
- rename relation type 'materializedview' to 'materialized_view'
- adjust hooks tests
  • Loading branch information
damian3031 committed Jul 25, 2023
1 parent 3327580 commit efddcb2
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 81 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Breaking Changes-20230721-125806.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Breaking Changes
body: Update dbt-core to 1.6.0rc1
time: 2023-07-21T12:58:06.169523+02:00
custom:
Author: damian3031
Issue: ""
PR: "332"
9 changes: 9 additions & 0 deletions .changes/unreleased/Breaking Changes-20230724-140221.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: Breaking Changes
body: Renamed relation type 'materializedview' to 'materialized_view' to be consistent
with dbt-core 1.6. If you have any custom macro where you check if relation type
equals to 'materializedview', change it to 'materialized_view'
time: 2023-07-24T14:02:21.439344+02:00
custom:
Author: damian3031
Issue: ""
PR: "332"
2 changes: 1 addition & 1 deletion dbt/adapters/trino/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.5.1"
version = "1.6.0rc1"
8 changes: 0 additions & 8 deletions dbt/adapters/trino/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,6 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False):
if without_comments == "":
continue

individual_query = self._add_query_comment(individual_query)

parent = super(TrinoConnectionManager, self)
connection, cursor = parent.add_query(
individual_query, auto_begin, bindings, abridge_sql_log
Expand All @@ -505,12 +503,6 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False):

return connection, cursor

def execute(self, sql, auto_begin=False, fetch=False):
_, cursor = self.add_query(sql, auto_begin)
status = self.get_response(cursor)
table = self.get_result_from_cursor(cursor)
return status, table

@classmethod
def data_type_code_to_name(cls, type_code) -> str:
return type_code.split("(")[0].upper()
6 changes: 3 additions & 3 deletions dbt/include/trino/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
t.table_catalog as database,
t.table_name as name,
t.table_schema as schema,
case when mv.name is not null then 'materializedview'
case when mv.name is not null then 'materialized_view'
when t.table_type = 'BASE TABLE' then 'table'
when t.table_type = 'VIEW' then 'view'
else t.table_type
Expand Down Expand Up @@ -149,7 +149,7 @@
{% macro trino__drop_relation(relation) -%}
{% set relation_type = 'materialized view' if relation.type == 'materializedview' else relation.type %}
{% set relation_type = relation.type|replace("_", " ") %}
{% call statement('drop_relation', auto_begin=False) -%}
drop {{ relation_type }} if exists {{ relation }}
{%- endcall %}
Expand Down Expand Up @@ -183,7 +183,7 @@
{% macro trino__rename_relation(from_relation, to_relation) -%}
{% set from_relation_type = 'materialized view' if from_relation.type == 'materializedview' else from_relation.type %}
{% set from_relation_type = from_relation.type|replace("_", " ") %}
{% call statement('rename_relation') -%}
alter {{ from_relation_type }} {{ from_relation }} rename to {{ to_relation }}
{%- endcall %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{ log("No existing materialized view found, creating materialized view...", info=true) }}
{%- set build_sql = create_materialized_view_as(target_relation) %}

{% elif full_refresh_mode or existing_relation.type != "materializedview" %}
{% elif full_refresh_mode or existing_relation.type != "materialized_view" %}
{{ log("Found a " ~ existing_relation.type ~ " with same name. Dropping it...", info=true) }}
{#-- Make sure the backup doesn't exist so we don't encounter issues with the rename below #}
{% set backup_identifier = existing_relation.identifier ~ "__dbt_backup" %}
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dbt-tests-adapter~=1.5.3
dbt-tests-adapter~=1.6.0rc1
mypy==1.4.1 # patch updates have historically introduced breaking changes
pre-commit~=3.3
pytest~=7.4
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/adapter/hooks/data/seed_model.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ create table {schema}.on_model_hook (
target_pass VARCHAR,
target_threads INTEGER,
run_started_at VARCHAR,
invocation_id VARCHAR
invocation_id VARCHAR,
thread_id VARCHAR
);
3 changes: 2 additions & 1 deletion tests/functional/adapter/hooks/data/seed_run.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ create table {schema}.on_run_hook (
target_pass VARCHAR,
target_threads INTEGER,
run_started_at VARCHAR,
invocation_id VARCHAR
invocation_id VARCHAR,
thread_id VARCHAR
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestIcebergMaterializedViewExists:
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"name": "materializedview",
"name": "materialized_view",
}

@pytest.fixture(scope="class")
Expand All @@ -37,8 +37,8 @@ def test_mv_is_dropped_when_model_runs_view(self, project):

# check relation types
expected = {
"my_table": "materializedview",
"my_view": "materializedview",
"my_table": "materialized_view",
"my_view": "materialized_view",
}
check_relation_types(project.adapter, expected)

Expand Down Expand Up @@ -176,15 +176,15 @@ def models(self):
return {
"mat_view_overrides_table.sql": model_sql,
"mat_view_overrides_view.sql": model_sql,
"mat_view_overrides_materializedview.sql": model_sql,
"mat_view_overrides_materialized_view.sql": model_sql,
}

def test_mv_overrides_relation(self, project):
# Create relation with same name
project.adapter.execute("CREATE VIEW mat_view_overrides_view AS SELECT 3 c")
project.adapter.execute("CREATE TABLE mat_view_overrides_table AS SELECT 4 d")
project.adapter.execute(
"CREATE MATERIALIZED VIEW mat_view_overrides_materializedview AS SELECT 5 e"
"CREATE MATERIALIZED VIEW mat_view_overrides_materialized_view AS SELECT 5 e"
)

# Seed seed
Expand All @@ -197,9 +197,9 @@ def test_mv_overrides_relation(self, project):

# Check if MVs were created correctly
expected = {
"mat_view_overrides_view": "materializedview",
"mat_view_overrides_table": "materializedview",
"mat_view_overrides_materializedview": "materializedview",
"mat_view_overrides_view": "materialized_view",
"mat_view_overrides_table": "materialized_view",
"mat_view_overrides_materialized_view": "materialized_view",
}
check_relation_types(project.adapter, expected)

Expand All @@ -209,7 +209,7 @@ def test_mv_overrides_relation(self, project):
"seed",
"mat_view_overrides_view",
"mat_view_overrides_table",
"mat_view_overrides_materializedview",
"mat_view_overrides_materialized_view",
],
)

Expand Down
67 changes: 11 additions & 56 deletions tests/functional/adapter/test_query_comments.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,32 @@
import json

import pytest
from dbt.exceptions import DbtRuntimeError
from dbt.tests.adapter.query_comment.test_query_comment import (
BaseDefaultQueryComments,
BaseEmptyQueryComments,
BaseMacroArgsQueryComments,
BaseMacroInvalidQueryComments,
BaseMacroQueryComments,
BaseNullQueryComments,
BaseQueryComments,
)
from dbt.tests.util import run_dbt_and_capture
from dbt.version import __version__ as dbt_version


# TODO: below tests could be simplified to just
# pass statements, when tests in dbt.tests.adapter
# will be fixed
class BaseDefaultQueryCommentsTrino(BaseDefaultQueryComments):
def run_get_json(self, expect_pass=True):
res, raw_logs = run_dbt_and_capture(
["--debug", "--log-format=json", "run"], expect_pass=expect_pass
)

# empty lists evaluate as False
assert len(res) > 0
query = res[0].adapter_response["query"]
return raw_logs, query


class TestQueryCommentsTrino(BaseDefaultQueryCommentsTrino, BaseQueryComments):
def test_matches_comment(self) -> bool:
logs, query = self.run_get_json()
assert r"/* dbt\nrules! */\n" in logs
assert query.startswith("/* dbt\nrules! */\n")
class TestQueryCommentsTrino(BaseQueryComments):
pass


class TestMacroQueryCommentsTrino(BaseDefaultQueryCommentsTrino, BaseMacroQueryComments):
def test_matches_comment(self) -> bool:
logs, query = self.run_get_json()
assert r"/* dbt macros\nare pretty cool */\n" in logs
assert query.startswith("/* dbt macros\nare pretty cool */\n")
class TestMacroQueryCommentsTrino(BaseMacroQueryComments):
pass


class TestMacroArgsQueryCommentsTrino(BaseDefaultQueryCommentsTrino, BaseMacroArgsQueryComments):
def test_matches_comment(self) -> bool:
logs, query = self.run_get_json()
expected_dct = {
"app": "dbt++",
"dbt_version": dbt_version,
"macro_version": "0.1.0",
"message": "blah: default",
}
expected = "/* {} */\n".format(json.dumps(expected_dct, sort_keys=True))
assert expected in query
class TestMacroArgsQueryCommentsTrino(BaseMacroArgsQueryComments):
pass


class TestMacroInvalidQueryCommentsTrino(BaseMacroInvalidQueryComments):
def test_run_assert_comments(self):
with pytest.raises(DbtRuntimeError):
self.run_get_json(expect_pass=False)
pass


class TestNullQueryCommentsTrino(BaseDefaultQueryCommentsTrino, BaseNullQueryComments):
def test_matches_comment(self) -> bool:
logs, query = self.run_get_json()
assert "/*" not in logs or "*/" not in logs
assert not query.startswith("/*")
class TestNullQueryCommentsTrino(BaseNullQueryComments):
pass


class TestEmptyQueryCommentsTrino(BaseDefaultQueryCommentsTrino, BaseEmptyQueryComments):
def test_matches_comment(self) -> bool:
logs, query = self.run_get_json()
assert "/*" not in logs or "*/" not in logs
assert not query.startswith("/*")
class TestEmptyQueryCommentsTrino(BaseEmptyQueryComments):
pass

0 comments on commit efddcb2

Please sign in to comment.