From 00de0cd4b5b11dc08d824b5214d109e361ceec6f Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Sat, 3 Oct 2020 16:19:48 -0600 Subject: [PATCH 1/8] adding new debug_query function to base adapter --- core/dbt/adapters/base/connections.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/dbt/adapters/base/connections.py b/core/dbt/adapters/base/connections.py index bbbea465cff..11a274a1398 100644 --- a/core/dbt/adapters/base/connections.py +++ b/core/dbt/adapters/base/connections.py @@ -30,6 +30,7 @@ class BaseConnectionManager(metaclass=abc.ABCMeta): - commit - clear_transaction - execute + - debug_query You must also set the 'TYPE' class attribute with a class-unique constant string. @@ -287,6 +288,14 @@ def _add_query_comment(self, sql: str) -> str: return sql return self.query_header.add(sql) + def debug_query(self, sql: str): + if sql is None: + self.execute('select 1 as id') + else: + self.execute(sql) + + + @abc.abstractmethod def execute( self, sql: str, auto_begin: bool = False, fetch: bool = False @@ -303,3 +312,4 @@ def execute( raise dbt.exceptions.NotImplementedException( '`execute` is not implemented for this adapter!' ) + From 354ab5229b5f0e61aedcd1d7b0b81bd611da4b31 Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Sat, 3 Oct 2020 16:20:52 -0600 Subject: [PATCH 2/8] adding new debug_query function to base debug task --- core/dbt/task/debug.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/task/debug.py b/core/dbt/task/debug.py index 26ad51d00c5..a3ef3963b17 100644 --- a/core/dbt/task/debug.py +++ b/core/dbt/task/debug.py @@ -334,7 +334,7 @@ def attempt_connection(profile): adapter = get_adapter(profile) try: with adapter.connection_named('debug'): - adapter.execute('select 1 as id') + adapter.debug_query() except Exception as exc: return COULD_NOT_CONNECT_MESSAGE.format( err=str(exc), From dcb6854683b610d5411ff5d6d7695236dd6f2e81 Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Wed, 7 Oct 2020 19:20:16 -0600 Subject: [PATCH 3/8] adding debug_query to base/impl.py enabling plugin authors to write their own debug_query --- core/dbt/adapters/base/connections.py | 8 -------- core/dbt/adapters/base/impl.py | 3 +++ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/core/dbt/adapters/base/connections.py b/core/dbt/adapters/base/connections.py index 11a274a1398..068cb09a9a4 100644 --- a/core/dbt/adapters/base/connections.py +++ b/core/dbt/adapters/base/connections.py @@ -288,14 +288,6 @@ def _add_query_comment(self, sql: str) -> str: return sql return self.query_header.add(sql) - def debug_query(self, sql: str): - if sql is None: - self.execute('select 1 as id') - else: - self.execute(sql) - - - @abc.abstractmethod def execute( self, sql: str, auto_begin: bool = False, fetch: bool = False diff --git a/core/dbt/adapters/base/impl.py b/core/dbt/adapters/base/impl.py index f0dcba0e878..4c0d776d986 100644 --- a/core/dbt/adapters/base/impl.py +++ b/core/dbt/adapters/base/impl.py @@ -180,6 +180,9 @@ def clear_transaction(self) -> None: def commit_if_has_connection(self) -> None: self.connections.commit_if_has_connection() + def debug_query(self): + self.execute('select 1 as id') + def nice_connection_name(self) -> str: conn = self.connections.get_if_exists() if conn is None or conn.name is None: From 5ff383a025c26ccc6dc64296cb92f688f7d2a666 Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Wed, 7 Oct 2020 19:25:00 -0600 Subject: [PATCH 4/8] Adding type hint for debug_query --- core/dbt/adapters/base/impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/adapters/base/impl.py b/core/dbt/adapters/base/impl.py index 4c0d776d986..9b013ee8fa6 100644 --- a/core/dbt/adapters/base/impl.py +++ b/core/dbt/adapters/base/impl.py @@ -180,7 +180,7 @@ def clear_transaction(self) -> None: def commit_if_has_connection(self) -> None: self.connections.commit_if_has_connection() - def debug_query(self): + def debug_query(self) -> None: self.execute('select 1 as id') def nice_connection_name(self) -> str: From 4c58438e8a3179afd839992438a6634f987b0eea Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Wed, 7 Oct 2020 19:29:49 -0600 Subject: [PATCH 5/8] removing errant reference to debug_query method --- core/dbt/adapters/base/connections.py | 1 - 1 file changed, 1 deletion(-) diff --git a/core/dbt/adapters/base/connections.py b/core/dbt/adapters/base/connections.py index 068cb09a9a4..58009514bf6 100644 --- a/core/dbt/adapters/base/connections.py +++ b/core/dbt/adapters/base/connections.py @@ -30,7 +30,6 @@ class BaseConnectionManager(metaclass=abc.ABCMeta): - commit - clear_transaction - execute - - debug_query You must also set the 'TYPE' class attribute with a class-unique constant string. From fd6edfccc4c903800fdc8f6529f1d044d5005090 Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Wed, 7 Oct 2020 19:30:48 -0600 Subject: [PATCH 6/8] Removing accidental whitespace addition --- core/dbt/adapters/base/connections.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/dbt/adapters/base/connections.py b/core/dbt/adapters/base/connections.py index 58009514bf6..2442908e982 100644 --- a/core/dbt/adapters/base/connections.py +++ b/core/dbt/adapters/base/connections.py @@ -302,5 +302,4 @@ def execute( """ raise dbt.exceptions.NotImplementedException( '`execute` is not implemented for this adapter!' - ) - + ) \ No newline at end of file From 214d1376721af343500c8cbd2c0586387b472d1a Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Thu, 8 Oct 2020 07:45:35 -0600 Subject: [PATCH 7/8] adding entry to changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34f2ef619c3..45c8490f6e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,10 +14,12 @@ ### Under the hood - Added strategy-specific validation to improve the relevancy of compilation errors for the `timestamp` and `check` snapshot strategies. (([#2787](https://github.com/fishtown-analytics/dbt/issues/2787), [#2791](https://github.com/fishtown-analytics/dbt/pull/2791)) - Changed rpc test timeouts to avoid locally run test failures ([#2803](https://github.com/fishtown-analytics/dbt/issues/2803),[#2804](https://github.com/fishtown-analytics/dbt/pull/2804)) +- Added a debug_query on the base adapter that will allow plugin authors to create custom debug queries ([#2751](https://github.com/fishtown-analytics/dbt/issues/2751),[#2871](https://github.com/fishtown-analytics/dbt/pull/2817)) Contributors: - [@joelluijmes](https://github.com/joelluijmes) ([#2749](https://github.com/fishtown-analytics/dbt/pull/2749)) - [@kingfink](https://github.com/kingfink) ([#2791](https://github.com/fishtown-analytics/dbt/pull/2791)) +- [@zmac12](https://github.com/zmac12) ([#2871](https://github.com/fishtown-analytics/dbt/pull/2817)) ## dbt 0.18.1 (Release TBD) From 03d3943e996de81e9bc0bf7aaa555626f22b8192 Mon Sep 17 00:00:00 2001 From: Zach McQuiston Date: Thu, 8 Oct 2020 07:47:16 -0600 Subject: [PATCH 8/8] fixing linter problem in connections.py --- core/dbt/adapters/base/connections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/adapters/base/connections.py b/core/dbt/adapters/base/connections.py index 2442908e982..bbbea465cff 100644 --- a/core/dbt/adapters/base/connections.py +++ b/core/dbt/adapters/base/connections.py @@ -302,4 +302,4 @@ def execute( """ raise dbt.exceptions.NotImplementedException( '`execute` is not implemented for this adapter!' - ) \ No newline at end of file + )