Skip to content

Commit

Permalink
Merge pull request #2721 from fishtown-analytics/feature/more-test-on…
Browse files Browse the repository at this point in the history
…ly-adapter-methods

add more test helper methods
  • Loading branch information
beckjake authored Aug 21, 2020
2 parents acfa849 + 685873a commit fe46138
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## dbt 0.18.0 (Release TBD)


### Under the hood
- Added 3 more adapter methods that the new dbt-adapter-test suite can use for testing. ([#2492](https://github.com/fishtown-analytics/dbt/issues/2492), [#2721](https://github.com/fishtown-analytics/dbt/pull/2721))


## dbt 0.18.0rc1 (August 19, 2020)


Expand Down
42 changes: 38 additions & 4 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,44 @@ def post_model_hook(self, config: Mapping[str, Any], context: Any) -> None:
"""
pass

def get_compiler(self):
from dbt.compilation import Compiler
return Compiler(self.config)

# Methods used in adapter tests
def update_column_sql(
self,
dst_name: str,
dst_column: str,
clause: str,
where_clause: Optional[str] = None,
) -> str:
clause = f'update {dst_name} set {dst_column} = {clause}'
if where_clause is not None:
clause += f' where {where_clause}'
return clause

def timestamp_add_sql(
self, add_to: str, number: int = 1, interval: str = 'hour'
) -> str:
# for backwards compatibility, we're compelled to set some sort of
# default. A lot of searching has lead me to believe that the
# '+ interval' syntax used in postgres/redshift is relatively common
# and might even be the SQL standard's intention.
return f"{add_to} + interval '{number} {interval}'"

def string_add_sql(
self, add_to: str, value: str, location='append',
) -> str:
if location == 'append':
return f"{add_to} || '{value}'"
elif location == 'prepend':
return f"'{value}' || {add_to}"
else:
raise RuntimeException(
f'Got an unexpected location value of "{location}"'
)

def get_rows_different_sql(
self,
relation_a: BaseRelation,
Expand Down Expand Up @@ -1147,10 +1185,6 @@ def get_rows_different_sql(

return sql

def get_compiler(self):
from dbt.compilation import Compiler
return Compiler(self.config)


COLUMNS_EQUAL_SQL = '''
with diff_count as (
Expand Down
7 changes: 4 additions & 3 deletions core/dbt/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def name(self) -> str:
)

def track_deprecation_warn(self) -> None:
dbt.tracking.track_deprecation_warn({
"deprecation_name": self.name
})
if dbt.tracking.active_user is not None:
dbt.tracking.track_deprecation_warn({
"deprecation_name": self.name
})

@property
def description(self) -> str:
Expand Down
17 changes: 17 additions & 0 deletions plugins/bigquery/dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,3 +831,20 @@ def get_rows_different_sql(
column_names=column_names,
except_operator=except_operator,
)

def timestamp_add_sql(
self, add_to: str, number: int = 1, interval: str = 'hour'
) -> str:
return f'timestamp_add({add_to}, interval {number} {interval})'

def string_add_sql(
self, add_to: str, value: str, location='append',
) -> str:
if location == 'append':
return f"concat({add_to}, '{value}')"
elif location == 'prepend':
return f"concat('{value}', {add_to})"
else:
raise dbt.exceptions.RuntimeException(
f'Got an unexpected location value of "{location}"'
)
5 changes: 5 additions & 0 deletions plugins/postgres/dbt/adapters/postgres/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ def _link_cached_relations(self, manifest):
def _relations_cache_for_schemas(self, manifest):
super()._relations_cache_for_schemas(manifest)
self._link_cached_relations(manifest)

def timestamp_add_sql(
self, add_to: str, number: int = 1, interval: str = 'hour'
) -> str:
return f"{add_to} + interval '{number} {interval}'"
5 changes: 5 additions & 0 deletions plugins/snowflake/dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ def list_relations_without_caching(
))

return relations

def timestamp_add_sql(
self, add_to: str, number: int = 1, interval: str = 'hour'
) -> str:
return f'DATEADD({interval}, {number}, {add_to})'

0 comments on commit fe46138

Please sign in to comment.