From 988e6c186fbd19c086b70257b8e0c9252bb2c099 Mon Sep 17 00:00:00 2001 From: niteshy Date: Mon, 12 Jun 2023 15:47:09 -0700 Subject: [PATCH] DBT-704: Changes required for making it compatible with dbt-core 1.4 and 1.5 (#175) Co-authored-by: Nitesh Yadav --- dbt/adapters/impala/__version__.py | 2 +- dbt/adapters/impala/connections.py | 8 ++++---- dbt/adapters/impala/impl.py | 7 +++---- dbt/adapters/impala/relation.py | 7 +++---- dev-requirements.txt | 2 +- setup.py | 2 +- tests/functional/adapter/test_utils.py | 15 +++++++++++++-- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/dbt/adapters/impala/__version__.py b/dbt/adapters/impala/__version__.py index 509cb5a..8523d8e 100644 --- a/dbt/adapters/impala/__version__.py +++ b/dbt/adapters/impala/__version__.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -version = "1.3.2" +version = "1.4.0" diff --git a/dbt/adapters/impala/connections.py b/dbt/adapters/impala/connections.py index 97b1855..d67a30b 100644 --- a/dbt/adapters/impala/connections.py +++ b/dbt/adapters/impala/connections.py @@ -78,7 +78,7 @@ def __pre_deserialize__(cls, data): def __post_init__(self): # impala classifies database and schema as the same thing if self.database is not None and self.database != self.schema: - raise dbt.exceptions.RuntimeException( + raise dbt.exceptions.DbtRuntimeError( f" schema: {self.schema} \n" f" database: {self.database} \n" f"On Impala, database must be omitted or have the same value as" @@ -169,12 +169,12 @@ def exception_handler(self, sql: str): yield except HttpError as httpError: logger.debug(f"Authorization error: {httpError}") - raise dbt.exceptions.RuntimeException( + raise dbt.exceptions.DbtRuntimeError( "HTTP Authorization error: " + str(httpError) + ", please check your credentials" ) except HiveServer2Error as servError: logger.debug(f"Server connection error: {servError}") - raise dbt.exceptions.RuntimeException( + raise dbt.exceptions.DbtRuntimeError( "Unable to establish connection to Impala server: " + str(servError) ) except DatabaseError as dbError: @@ -182,7 +182,7 @@ def exception_handler(self, sql: str): raise dbt.exceptions.DatabaseException("Database Connection error: " + str(dbError)) except Exception as exc: logger.debug(f"Error running SQL: {sql}") - raise dbt.exceptions.RuntimeException(str(exc)) + raise dbt.exceptions.DbtRuntimeError(str(exc)) @classmethod def open(cls, connection): diff --git a/dbt/adapters/impala/impl.py b/dbt/adapters/impala/impl.py index fd062c2..7ec65e2 100644 --- a/dbt/adapters/impala/impl.py +++ b/dbt/adapters/impala/impl.py @@ -24,7 +24,6 @@ from dbt.clients import agate_helper from dbt.clients.agate_helper import ColumnTypeBuilder, NullableAgateType, _NullMarker from dbt.events import AdapterLogger -from dbt.exceptions import warn_or_error from dbt.utils import executor import dbt.adapters.impala.cloudera_tracking as tracker @@ -103,7 +102,7 @@ def list_relations_without_caching( try: results = self.execute_macro(LIST_RELATIONS_MACRO_NAME, kwargs=kwargs) - except dbt.exceptions.RuntimeException as e: + except dbt.exceptions.DbtRuntimeError as e: errmsg = getattr(e, "msg", "") if f"Database '{schema_relation}' not found" in errmsg: return [] @@ -115,7 +114,7 @@ def list_relations_without_caching( relations = [] for row in results: if len(row) != 2: - raise dbt.exceptions.RuntimeException( + raise dbt.exceptions.DbtRuntimeError( f'Invalid value from "show table extended ...", ' f"got {len(row)} values, expected 4" ) @@ -152,7 +151,7 @@ def get_columns_in_relation(self, relation: Relation) -> List[ImpalaColumn]: try: rows: List[agate.Row] = super().get_columns_in_relation(relation) columns = self.parse_describe_extended(relation, rows) - except dbt.exceptions.RuntimeException as e: + except dbt.exceptions.DbtRuntimeError as e: # impala would throw error when table doesn't exist errmsg = getattr(e, "msg", "") if ( diff --git a/dbt/adapters/impala/relation.py b/dbt/adapters/impala/relation.py index f0288a9..02e3aaf 100644 --- a/dbt/adapters/impala/relation.py +++ b/dbt/adapters/impala/relation.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from dataclasses import dataclass +from dataclasses import dataclass, field from dbt.adapters.base.relation import BaseRelation, Policy -from dbt.exceptions import RuntimeException import dbt.adapters.impala.cloudera_tracking as tracker @@ -36,8 +35,8 @@ class ImpalaIncludePolicy(Policy): @dataclass(frozen=True, eq=False, repr=False) class ImpalaRelation(BaseRelation): - quote_policy: ImpalaQuotePolicy = ImpalaQuotePolicy() - include_policy: ImpalaIncludePolicy = ImpalaIncludePolicy() + quote_policy: ImpalaQuotePolicy = field(default_factory=lambda: ImpalaQuotePolicy()) + include_policy: ImpalaIncludePolicy = field(default_factory=lambda: ImpalaIncludePolicy()) quote_character: str = None information: str = None diff --git a/dev-requirements.txt b/dev-requirements.txt index 973ee2d..38b9a28 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,4 +1,4 @@ -dbt-tests-adapter==1.3.* +dbt-tests-adapter==1.4.* pre-commit~=2.21;python_version=="3.7" pre-commit~=3.2;python_version>="3.8" pytest diff --git a/setup.py b/setup.py index aba68d9..2857319 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ def _get_dbt_core_version(): package_name = "dbt-impala" # make sure this always matches dbt/adapters/dbt_impala/__version__.py -package_version = "1.3.2" +package_version = "1.4.0" description = """The Impala adapter plugin for dbt""" dbt_core_version = _get_dbt_core_version() diff --git a/tests/functional/adapter/test_utils.py b/tests/functional/adapter/test_utils.py index a04e293..c4a513a 100644 --- a/tests/functional/adapter/test_utils.py +++ b/tests/functional/adapter/test_utils.py @@ -168,8 +168,19 @@ def models(self): models__test_escape_single_quotes_quote_sql = """ -select '{{ escape_single_quotes("they're") }}' as actual, 'they\\'re' as expected union all -select '{{ escape_single_quotes("they are") }}' as actual, 'they are' as expected +select + '{{ escape_single_quotes("they're") }}' as actual, + 'they\\'re' as expected, + {{ length(string_literal(escape_single_quotes("they're"))) }} as actual_length, + 7 as expected_length + +union all + +select + '{{ escape_single_quotes("they are") }}' as actual, + 'they are' as expected, + {{ length(string_literal(escape_single_quotes("they are"))) }} as actual_length, + 8 as expected_length """