Skip to content

Commit

Permalink
DBT-704: Changes required for making it compatible with dbt-core 1.4 …
Browse files Browse the repository at this point in the history
…and 1.5 (#175)

Co-authored-by: Nitesh Yadav <[email protected]>
  • Loading branch information
niteshy and Nitesh Yadav authored Jun 12, 2023
1 parent 9c2be85 commit 988e6c1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/impala/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions dbt/adapters/impala/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -169,20 +169,20 @@ 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:
logger.debug(f"Database connection error: {str(dbError)}")
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):
Expand Down
7 changes: 3 additions & 4 deletions dbt/adapters/impala/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 []
Expand All @@ -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"
)
Expand Down Expand Up @@ -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 (
Expand Down
7 changes: 3 additions & 4 deletions dbt/adapters/impala/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

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.3.*
dbt-tests-adapter==1.4.*
pre-commit~=2.21;python_version=="3.7"
pre-commit~=3.2;python_version>="3.8"
pytest
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions tests/functional/adapter/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""


Expand Down

0 comments on commit 988e6c1

Please sign in to comment.