Skip to content

Commit

Permalink
Add update_type and rowcount to dbt commands SQL status in CLI output
Browse files Browse the repository at this point in the history
  • Loading branch information
damian3031 committed Aug 14, 2024
1 parent a8f4a98 commit 6b6f60a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20240812-161625.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Added update_type and rowcount to dbt commands SQL status in CLI output
time: 2024-08-12T16:16:25.330055+02:00
custom:
Author: damian3031
Issue: "428"
PR: "429"
12 changes: 10 additions & 2 deletions dbt/adapters/trino/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,20 @@ def open(cls, connection):

@classmethod
def get_response(cls, cursor) -> TrinoAdapterResponse:
message = "SUCCESS"
code = cursor._cursor.update_type
if code is None:
code = "SUCCESS"

rows_affected = cursor._cursor.rowcount
if rows_affected == -1:
message = f"{code}"
else:
message = f"{code} ({rows_affected:_} rows)"
return TrinoAdapterResponse(
_message=message,
query=cursor._cursor.query,
query_id=cursor._cursor.query_id,
rows_affected=cursor._cursor.rowcount,
rows_affected=rows_affected,
) # type: ignore

def cancel(self, connection):
Expand Down
60 changes: 60 additions & 0 deletions tests/functional/adapter/test_sql_status_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest
from dbt.tests.util import run_dbt, run_dbt_and_capture

seed_csv = """
id,name,some_date
1,Easton,1981-05-20 06:46:51
2,Lillian,1978-09-03 18:10:33
3,Jeremiah,1982-03-11 03:59:51
4,Nolan,1976-05-06 20:21:35
""".lstrip()

model_sql = """
select * from {{ ref('seed') }}
"""


class TestSqlStatusOutput:
"""
Testing if SQL status output contains update_type and rowcount
"""

@pytest.fixture(scope="class")
def seeds(self):
return {
"seed.csv": seed_csv,
}

@pytest.fixture(scope="class")
def models(self):
return {
"materialization_table.sql": model_sql,
"materialization_view.sql": model_sql,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"name": "sql_status_output",
"models": {
"sql_status_output": {
"materialization_table": {"+materialized": "table"},
"materialization_view": {"+materialized": "view"},
}
},
}

def test_run_seed_test(self, project):
results = run_dbt(["seed"], expect_pass=True)
assert len(results) == 1

results, logs = run_dbt_and_capture(["--no-use-colors", "run"], expect_pass=True)
assert len(results) == 2
assert (
f" of 2 OK created sql table model {project.test_schema}.materialization_table [CREATE TABLE (4 rows) in "
in logs
)
assert (
f" of 2 OK created sql view model {project.test_schema}.materialization_view [CREATE VIEW in "
in logs
)

0 comments on commit 6b6f60a

Please sign in to comment.