Skip to content

Commit

Permalink
Merge branch 'main' into redshift_connector_2.0.914
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-rogers-dbt authored Oct 11, 2023
2 parents 6715454 + 5d4f3f5 commit c35cf5d
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Dependencies-20230918-190833.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: "Dependencies"
body: "Update ddtrace requirement from ~=1.18 to ~=1.19"
time: 2023-09-18T19:08:33.00000Z
custom:
Author: dependabot[bot]
PR: 610
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230921-153707.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support storing test failures as views
time: 2023-09-21T15:37:07.970722-04:00
custom:
Author: mikealfare
Issue: "6914"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230807-174409.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Use the PID to terminate the session
time: 2023-08-07T17:44:09.15097-06:00
custom:
Author: dbeatty10
Issue: "553"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230923-091155.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: avoid nested loop in query planner execution of redshift__get_relations
time: 2023-09-23T09:11:55.2152725-04:00
custom:
Author: slin30
Issue: "609"
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20230925-150132.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Add tests for inlined limit + sql_header in dbt show query
time: 2023-09-25T15:01:32.025325+01:00
custom:
Author: michelleark
Issue: "616"
30 changes: 30 additions & 0 deletions .github/workflows/repository-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# **what?**
# Cleanup branches left over from automation and testing. Also cleanup
# draft releases from release testing.

# **why?**
# The automations are leaving behind branches and releases that clutter
# the repository. Sometimes we need them to debug processes so we don't
# want them immediately deleted. Running on Saturday to avoid running
# at the same time as an actual release to prevent breaking a release
# mid-release.

# **when?**
# Mainly on a schedule of 12:00 Saturday.
# Manual trigger can also run on demand

name: Repository Cleanup

on:
schedule:
- cron: '0 12 * * SAT' # At 12:00 on Saturday - details in `why` above

workflow_dispatch: # for manual triggering

permissions:
contents: write

jobs:
cleanup-repo:
uses: dbt-labs/actions/.github/workflows/repository-cleanup.yml@main
secrets: inherit
10 changes: 6 additions & 4 deletions dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ class RedshiftConnectionManager(SQLConnectionManager):
def _get_backend_pid(self):
sql = "select pg_backend_pid()"
_, cursor = self.add_query(sql)

res = cursor.fetchone()
return res
return res[0]

def cancel(self, connection: Connection):
try:
Expand All @@ -253,9 +254,10 @@ def cancel(self, connection: Connection):
raise

sql = f"select pg_terminate_backend({pid})"
_, cursor = self.add_query(sql)
res = cursor.fetchone()
logger.debug(f"Cancel query '{connection.name}': {res}")
cursor = connection.handle.cursor()
logger.debug(f"Cancel query on: '{connection.name}' with PID: {pid}")
logger.debug(sql)
cursor.execute(sql)

@classmethod
def get_response(cls, cursor: redshift_connector.Cursor) -> AdapterResponse:
Expand Down
2 changes: 1 addition & 1 deletion dbt/include/redshift/macros/relations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ with
from pg_depend
left join pg_rewrite
on pg_depend.objid = pg_rewrite.oid
where coalesce(pg_rewrite.ev_class, pg_depend.objid) != pg_depend.refobjid
)

select distinct
Expand All @@ -36,7 +37,6 @@ join relation ref
on dependency.ref_relation_id = ref.relation_id
join relation dep
on dependency.dep_relation_id = dep.relation_id
where ref.relation_name != dep.relation_name

{%- endcall -%}

Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-postgres&subdirectory=plugi
black~=23.9
bumpversion~=0.6.0
click~=8.1
ddtrace~=1.18
ddtrace~=1.19
flake8~=6.1
flaky~=3.7
freezegun~=1.2
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/adapter/dbt_show/test_dbt_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dbt.tests.adapter.dbt_show.test_dbt_show import BaseShowSqlHeader, BaseShowLimit


class TestRedshiftShowLimit(BaseShowLimit):
pass


class TestRedshiftShowSqlHeader(BaseShowSqlHeader):
pass
27 changes: 26 additions & 1 deletion tests/functional/adapter/test_store_test_failures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
from dbt.tests.adapter.store_test_failures_tests import basic
from dbt.tests.adapter.store_test_failures_tests.test_store_test_failures import (
TestStoreTestFailures,
)


class RedshiftTestStoreTestFailures(TestStoreTestFailures):
class TestRedshiftTestStoreTestFailures(TestStoreTestFailures):
pass


class TestStoreTestFailuresAsInteractions(basic.StoreTestFailuresAsInteractions):
pass


class TestStoreTestFailuresAsProjectLevelOff(basic.StoreTestFailuresAsProjectLevelOff):
pass


class TestStoreTestFailuresAsProjectLevelView(basic.StoreTestFailuresAsProjectLevelView):
pass


class TestStoreTestFailuresAsGeneric(basic.StoreTestFailuresAsGeneric):
pass


class TestStoreTestFailuresAsProjectLevelEphemeral(basic.StoreTestFailuresAsProjectLevelEphemeral):
pass


class TestStoreTestFailuresAsExceptions(basic.StoreTestFailuresAsExceptions):
pass
20 changes: 20 additions & 0 deletions tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
from dbt.tests.adapter.utils.test_current_timestamp import BaseCurrentTimestampNaive
from dbt.tests.adapter.utils.test_dateadd import BaseDateAdd
from dbt.tests.adapter.utils.test_datediff import BaseDateDiff
from dbt.tests.adapter.utils.test_date_spine import BaseDateSpine
from dbt.tests.adapter.utils.test_date_trunc import BaseDateTrunc
from dbt.tests.adapter.utils.test_escape_single_quotes import BaseEscapeSingleQuotesQuote
from dbt.tests.adapter.utils.test_except import BaseExcept
from dbt.tests.adapter.utils.test_generate_series import BaseGenerateSeries
from dbt.tests.adapter.utils.test_get_intervals_between import BaseGetIntervalsBetween
from dbt.tests.adapter.utils.test_get_powers_of_two import BaseGetPowersOfTwo
from dbt.tests.adapter.utils.test_hash import BaseHash
from dbt.tests.adapter.utils.test_intersect import BaseIntersect
from dbt.tests.adapter.utils.test_last_day import BaseLastDay
Expand Down Expand Up @@ -65,6 +69,10 @@ class TestDateDiff(BaseDateDiff):
pass


class TestDateSpine(BaseDateSpine):
pass


class TestDateTrunc(BaseDateTrunc):
pass

Expand All @@ -77,6 +85,18 @@ class TestExcept(BaseExcept):
pass


class TestGenerateSeries(BaseGenerateSeries):
pass


class TestGetIntervalsBeteween(BaseGetIntervalsBetween):
pass


class TestGetPowersOfTwo(BaseGetPowersOfTwo):
pass


class TestHash(BaseHash):
pass

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_redshift_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,13 @@ def test_cancel_open_connections_single(self):
with mock.patch.object(self.adapter.connections, "add_query") as add_query:
query_result = mock.MagicMock()
cursor = mock.Mock()
cursor.fetchone.return_value = 42
cursor.fetchone.return_value = (42,)
add_query.side_effect = [(None, cursor), (None, query_result)]

self.assertEqual(len(list(self.adapter.cancel_open_connections())), 1)
add_query.assert_has_calls(
[
call("select pg_backend_pid()"),
call("select pg_terminate_backend(42)"),
]
)

Expand Down

0 comments on commit c35cf5d

Please sign in to comment.