Skip to content

Commit

Permalink
Merge pull request #1478 from fishtown-analytics/feature/archive-bloc…
Browse files Browse the repository at this point in the history
…ks-as-regex-materialization

Use merge pattern for Archival queries
  • Loading branch information
drewbanin authored Jun 3, 2019
2 parents 00cbe3e + 82793a0 commit 3cac2d3
Show file tree
Hide file tree
Showing 28 changed files with 507 additions and 364 deletions.
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):
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) %}
{% 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

0 comments on commit 3cac2d3

Please sign in to comment.