Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use merge pattern for Archival queries #1478

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def list_schemas(self, database):
'`list_schemas` is not implemented for this adapter!'
)

@available.parse(lambda *a, **k: False)
def check_schema_exists(self, database, schema):
"""Check if a schema exists.

Expand Down Expand Up @@ -584,22 +585,22 @@ def valid_archive_target(self, relation):
dbt.exceptions.raise_compiler_error(msg)

@available.parse_none
def expand_target_column_types(self, temp_table, to_relation):
def expand_target_column_types(self, from_relation, to_relation):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, but this is a breaking change - we should be sure to document it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we should instead

  1. deprecate this method
  2. use expand_column_types directly henceforth?

this method was just a weirdo adapter method that converts a string into a Relation, then calls expand_column_types

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I think this is fine to just document for that reason.

if not isinstance(from_relation, self.Relation):
dbt.exceptions.invalid_type_error(
method_name='expand_target_column_types',
arg_name='from_relation',
got_value=from_relation,
expected_type=self.Relation)

if not isinstance(to_relation, self.Relation):
dbt.exceptions.invalid_type_error(
method_name='expand_target_column_types',
arg_name='to_relation',
got_value=to_relation,
expected_type=self.Relation)

goal = self.Relation.create(
database=None,
schema=None,
identifier=temp_table,
type='table',
quote_policy=self.config.quoting
)
self.expand_column_types(goal, to_relation)
self.expand_column_types(from_relation, to_relation)

def list_relations(self, database, schema):
if self._schema_is_cached(database, schema):
Expand Down
40 changes: 29 additions & 11 deletions core/dbt/include/global_project/macros/adapters/common.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
{%- endif -%}
{%- endmacro %}

{% macro get_columns_in_query(select_sql) -%}
{{ return(adapter_macro('get_columns_in_query', select_sql)) }}
{% endmacro %}

{% macro default__get_columns_in_query(select_sql) %}
{% call statement('get_columns_in_query', fetch_result=True, auto_begin=False) -%}
select * from (
{{ select_sql }}
) as __dbt_sbq
where false
limit 0
{% endcall %}

{{ return(load_result('get_columns_in_query').table.columns | map(attribute='name') | list) }}
{% endmacro %}

{% macro create_schema(database_name, schema_name) -%}
{{ adapter_macro('create_schema', database_name, schema_name) }}
{% endmacro %}
Expand Down Expand Up @@ -71,17 +87,6 @@
{% endmacro %}


{% macro create_archive_table(relation, columns) -%}
{{ adapter_macro('create_archive_table', relation, columns) }}
{%- endmacro %}

{% macro default__create_archive_table(relation, columns) -%}
create table if not exists {{ relation }} (
{{ column_list_for_create_table(columns) }}
);
{% endmacro %}


{% macro get_catalog(information_schemas) -%}
{{ return(adapter_macro('get_catalog', information_schemas)) }}
{%- endmacro %}
Expand Down Expand Up @@ -249,3 +254,16 @@
{% endcall %}
{{ return(load_result('check_schema_exists').table) }}
{% endmacro %}

{% macro make_temp_relation(base_relation, suffix='__dbt_tmp') %}
{{ return(adapter_macro('make_temp_relation', base_relation, suffix))}}
{% endmacro %}

{% macro default__make_temp_relation(base_relation, suffix) %}
beckjake marked this conversation as resolved.
Show resolved Hide resolved
{% set tmp_identifier = base_relation.identifier ~ suffix %}
{% set tmp_relation = base_relation.incorporate(
path={"identifier": tmp_identifier},
table_name=tmp_identifier) -%}

{% do return(tmp_relation) %}
{% endmacro %}
4 changes: 4 additions & 0 deletions core/dbt/include/global_project/macros/etc/datetime.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@
{{ return(dates_in_range(start_date, end_date, in_fmt=date_fmt)) }}
{% endmacro %}

{% macro py_current_timestring() %}
{% set dt = modules.datetime.datetime.now() %}
{% do return(dt.strftime("%Y%m%d%H%M%S%f")) %}
{% endmacro %}
Loading