-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use better adapter macros. Full pg support
- Loading branch information
Showing
23 changed files
with
174 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
{%- macro get_max_sql(relation, field = 'collector_tstamp') -%} | ||
|
||
select | ||
|
||
coalesce( | ||
max({{field}}), | ||
'0001-01-01' -- a long, long time ago | ||
) as start_ts | ||
|
||
from {{ relation }} | ||
|
||
{%- endmacro -%} | ||
|
||
|
||
{%- macro get_most_recent_record(relation, field = 'collector_tstamp') -%} | ||
|
||
{%- set result = run_query(get_max_sql(relation, field)) -%} | ||
|
||
{% if execute %} | ||
{% set start_ts = result.columns['start_ts'].values()[0] %} | ||
{% else %} | ||
{% set start_ts = '' %} | ||
{% endif %} | ||
|
||
{{ return(start_ts) }} | ||
|
||
{%- endmacro -%} | ||
|
||
|
||
{%- macro get_start_ts(relation, field = 'collector_tstamp') -%} | ||
{{ adapter_macro('get_start_ts', relation, field) }} | ||
{%- endmacro -%} | ||
|
||
|
||
{%- macro default__get_start_ts(relation, field = 'collector_tstamp') -%} | ||
({{get_max_sql(relation, field)}}) | ||
{%- endmacro -%} | ||
|
||
|
||
{%- macro bigquery__get_start_ts(relation, field = 'collector_tstamp') -%} | ||
|
||
{%- set partition_by = config.get('partition_by', none) -%} | ||
{%- set partitions = config.get('partitions', none) -%} | ||
|
||
{%- set start_ts -%} | ||
{%- if config.incremental_strategy == 'insert_overwrite' -%} | ||
|
||
{%- if partitions -%} least({{partitions|join(',')}}) | ||
{%- elif partition_by.data_type == 'date' -%} _dbt_max_partition | ||
{%- else -%} date(_dbt_max_partition) | ||
{%- endif -%} | ||
|
||
{%- else -%} | ||
|
||
{%- set rendered -%} | ||
{%- if partition_by.data_type == 'date' -%} {{partition_by.field}} | ||
{%- else -%} date({{partition_by.field}}) {%- endif -%} | ||
{%- endset -%} | ||
{%- set record = get_most_recent_record(relation, rendered) -%} | ||
'{{record}}' | ||
|
||
{%- endif -%} | ||
{%- endset -%} | ||
|
||
{%- do return(start_ts) -%} | ||
|
||
{%- endmacro -%} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{%- macro create_udf_convert_timezone() -%} | ||
{{ adapter_macro('create_udf_convert_timezone') }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__create_udf_convert_timezone() %} | ||
select 1 as fun -- noop | ||
{% endmacro %} | ||
|
||
{% macro postgres__create_udf_convert_timezone() %} | ||
create or replace function convert_timezone( | ||
in_tzname text, | ||
out_tzname text, | ||
in_t timestamptz | ||
) returns timestamptz | ||
as $$ | ||
declare | ||
begin | ||
return in_t at time zone out_tzname at time zone in_tzname; | ||
end; | ||
$$ language plpgsql; | ||
{% endmacro %} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.