Skip to content

Commit

Permalink
introduce implementation for date-time support in normalization (#5180)
Browse files Browse the repository at this point in the history
* introduce implementation for date-time support in normalization

* update test output for all destinations

* add comment
  • Loading branch information
subodh1810 authored Aug 10, 2021
1 parent 6bcf811 commit 923884b
Show file tree
Hide file tree
Showing 141 changed files with 1,615 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,34 @@
{% macro mysql__type_timestamp() %}
time
{% endmacro %}


{# timestamp with time zone ------------------------------------------------- #}

{%- macro type_timestamp_with_timezone() -%}
{{ adapter.dispatch('type_timestamp_with_timezone')() }}
{%- endmacro -%}

{% macro default__type_timestamp_with_timezone() %}
timestamp with time zone
{% endmacro %}

{% macro bigquery__type_timestamp_with_timezone() %}
timestamp
{% endmacro %}

{# MySQL doesnt allow cast operation to work with TIMESTAMP so we have to use char #}
{%- macro mysql__type_timestamp_with_timezone() -%}
char
{%- endmacro -%}


{# date ------------------------------------------------- #}

{%- macro type_date() -%}
{{ adapter.dispatch('type_date')() }}
{%- endmacro -%}

{% macro default__type_date() %}
date
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ select
json_extract_scalar(_airbyte_data, "$['id']") as id,
json_extract_scalar(_airbyte_data, "$['currency']") as currency,
json_extract_scalar(_airbyte_data, "$['date']") as date,
json_extract_scalar(_airbyte_data, "$['timestamp_col']") as timestamp_col,
json_extract_scalar(_airbyte_data, "$['HKD@spéçiäl & characters']") as HKD_special___characters,
json_extract_scalar(_airbyte_data, "$['HKD_special___characters']") as HKD_special___characters_1,
json_extract_scalar(_airbyte_data, "$['NZD']") as NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ select
string
) as currency,
cast(date as
string
date
) as date,
cast(timestamp_col as
timestamp
) as timestamp_col,
cast(HKD_special___characters as
float64
) as HKD_special___characters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ select
string
), ''), '-', coalesce(cast(date as
string
), ''), '-', coalesce(cast(timestamp_col as
string
), ''), '-', coalesce(cast(HKD_special___characters as
string
), ''), '-', coalesce(cast(HKD_special___characters_1 as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ select
json_extract_scalar(_airbyte_data, "$['id']") as id,
json_extract_scalar(_airbyte_data, "$['currency']") as currency,
json_extract_scalar(_airbyte_data, "$['date']") as date,
json_extract_scalar(_airbyte_data, "$['timestamp_col']") as timestamp_col,
json_extract_scalar(_airbyte_data, "$['HKD@spéçiäl & characters']") as HKD_special___characters,
json_extract_scalar(_airbyte_data, "$['HKD_special___characters']") as HKD_special___characters_1,
json_extract_scalar(_airbyte_data, "$['NZD']") as NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ select
string
) as currency,
cast(date as
string
date
) as date,
cast(timestamp_col as
timestamp
) as timestamp_col,
cast(HKD_special___characters as
float64
) as HKD_special___characters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ select
string
), ''), '-', coalesce(cast(date as
string
), ''), '-', coalesce(cast(timestamp_col as
string
), ''), '-', coalesce(cast(HKD_special___characters as
string
), ''), '-', coalesce(cast(HKD_special___characters_1 as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ select
id,
currency,
date,
timestamp_col,
HKD_special___characters,
HKD_special___characters_1,
NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ select
id,
currency,
date,
timestamp_col,
HKD_special___characters,
HKD_special___characters_1,
NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ select
id,
currency,
date,
timestamp_col,
HKD_special___characters,
HKD_special___characters_1,
NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ models:
- id
- currency
- date
- timestamp_col
- HKD_special___characters
- HKD_special___characters_1
- NZD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
{{ json_extract_scalar('_airbyte_data', ['id'], ['id']) }} as id,
{{ json_extract_scalar('_airbyte_data', ['currency'], ['currency']) }} as currency,
{{ json_extract_scalar('_airbyte_data', ['date'], ['date']) }} as date,
{{ json_extract_scalar('_airbyte_data', ['timestamp_col'], ['timestamp_col']) }} as timestamp_col,
{{ json_extract_scalar('_airbyte_data', ['HKD@spéçiäl & characters'], ['HKD@spéçiäl & characters']) }} as HKD_special___characters,
{{ json_extract_scalar('_airbyte_data', ['HKD_special___characters'], ['HKD_special___characters']) }} as HKD_special___characters_1,
{{ json_extract_scalar('_airbyte_data', ['NZD'], ['NZD']) }} as NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
select
cast(id as {{ dbt_utils.type_bigint() }}) as id,
cast(currency as {{ dbt_utils.type_string() }}) as currency,
cast(date as {{ dbt_utils.type_string() }}) as date,
cast(date as {{ type_date() }}) as date,
cast(timestamp_col as {{ type_timestamp_with_timezone() }}) as timestamp_col,
cast(HKD_special___characters as {{ dbt_utils.type_float() }}) as HKD_special___characters,
cast(HKD_special___characters_1 as {{ dbt_utils.type_string() }}) as HKD_special___characters_1,
cast(NZD as {{ dbt_utils.type_float() }}) as NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ select
'id',
'currency',
'date',
'timestamp_col',
'HKD_special___characters',
'HKD_special___characters_1',
'NZD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
{{ json_extract_scalar('_airbyte_data', ['id'], ['id']) }} as id,
{{ json_extract_scalar('_airbyte_data', ['currency'], ['currency']) }} as currency,
{{ json_extract_scalar('_airbyte_data', ['date'], ['date']) }} as date,
{{ json_extract_scalar('_airbyte_data', ['timestamp_col'], ['timestamp_col']) }} as timestamp_col,
{{ json_extract_scalar('_airbyte_data', ['HKD@spéçiäl & characters'], ['HKD@spéçiäl & characters']) }} as HKD_special___characters,
{{ json_extract_scalar('_airbyte_data', ['HKD_special___characters'], ['HKD_special___characters']) }} as HKD_special___characters_1,
{{ json_extract_scalar('_airbyte_data', ['NZD'], ['NZD']) }} as NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
select
cast(id as {{ dbt_utils.type_bigint() }}) as id,
cast(currency as {{ dbt_utils.type_string() }}) as currency,
cast(date as {{ dbt_utils.type_string() }}) as date,
cast(date as {{ type_date() }}) as date,
cast(timestamp_col as {{ type_timestamp_with_timezone() }}) as timestamp_col,
cast(HKD_special___characters as {{ dbt_utils.type_float() }}) as HKD_special___characters,
cast(HKD_special___characters_1 as {{ dbt_utils.type_string() }}) as HKD_special___characters_1,
cast(NZD as {{ dbt_utils.type_float() }}) as NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ select
'id',
'currency',
'date',
'timestamp_col',
'HKD_special___characters',
'HKD_special___characters_1',
'NZD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
id,
currency,
date,
timestamp_col,
HKD_special___characters,
HKD_special___characters_1,
NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
id,
currency,
date,
timestamp_col,
HKD_special___characters,
HKD_special___characters_1,
NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
id,
currency,
date,
timestamp_col,
HKD_special___characters,
HKD_special___characters_1,
NZD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ select
json_value(_airbyte_data,
'$."date"') as `date`,
json_value(_airbyte_data,
'$."timestamp_col"') as timestamp_col,
json_value(_airbyte_data,
'$."HKD@spéçiäl & characters"') as `HKD@spéçiäl & characters`,
json_value(_airbyte_data,
'$."HKD_special___characters"') as hkd_special___characters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ select
signed
) as id,
cast(currency as char) as currency,
cast(`date` as char) as `date`,
cast(`date` as
date
) as `date`,
cast(timestamp_col as char) as timestamp_col,
cast(`HKD@spéçiäl & characters` as
float
) as `HKD@spéçiäl & characters`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- SQL model to build a hash column based on the values of this record
select
*,
md5(cast(concat(coalesce(cast(id as char), ''), '-', coalesce(cast(currency as char), ''), '-', coalesce(cast(`date` as char), ''), '-', coalesce(cast(`HKD@spéçiäl & characters` as char), ''), '-', coalesce(cast(hkd_special___characters as char), ''), '-', coalesce(cast(nzd as char), ''), '-', coalesce(cast(usd as char), '')) as char)) as _airbyte_dedup_exchange_rate_hashid
md5(cast(concat(coalesce(cast(id as char), ''), '-', coalesce(cast(currency as char), ''), '-', coalesce(cast(`date` as char), ''), '-', coalesce(cast(timestamp_col as char), ''), '-', coalesce(cast(`HKD@spéçiäl & characters` as char), ''), '-', coalesce(cast(hkd_special___characters as char), ''), '-', coalesce(cast(nzd as char), ''), '-', coalesce(cast(usd as char), '')) as char)) as _airbyte_dedup_exchange_rate_hashid
from _airbyte_test_normalization.`dedup_exchange_rate_ab2`
-- dedup_exchange_rate
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ select
json_value(_airbyte_data,
'$."date"') as `date`,
json_value(_airbyte_data,
'$."timestamp_col"') as timestamp_col,
json_value(_airbyte_data,
'$."HKD@spéçiäl & characters"') as `HKD@spéçiäl & characters`,
json_value(_airbyte_data,
'$."HKD_special___characters"') as hkd_special___characters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ select
signed
) as id,
cast(currency as char) as currency,
cast(`date` as char) as `date`,
cast(`date` as
date
) as `date`,
cast(timestamp_col as char) as timestamp_col,
cast(`HKD@spéçiäl & characters` as
float
) as `HKD@spéçiäl & characters`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- SQL model to build a hash column based on the values of this record
select
*,
md5(cast(concat(coalesce(cast(id as char), ''), '-', coalesce(cast(currency as char), ''), '-', coalesce(cast(`date` as char), ''), '-', coalesce(cast(`HKD@spéçiäl & characters` as char), ''), '-', coalesce(cast(hkd_special___characters as char), ''), '-', coalesce(cast(nzd as char), ''), '-', coalesce(cast(usd as char), '')) as char)) as _airbyte_exchange_rate_hashid
md5(cast(concat(coalesce(cast(id as char), ''), '-', coalesce(cast(currency as char), ''), '-', coalesce(cast(`date` as char), ''), '-', coalesce(cast(timestamp_col as char), ''), '-', coalesce(cast(`HKD@spéçiäl & characters` as char), ''), '-', coalesce(cast(hkd_special___characters as char), ''), '-', coalesce(cast(nzd as char), ''), '-', coalesce(cast(usd as char), '')) as char)) as _airbyte_exchange_rate_hashid
from _airbyte_test_normalization.`exchange_rate_ab2`
-- exchange_rate
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ select
id,
currency,
`date`,
timestamp_col,
`HKD@spéçiäl & characters`,
hkd_special___characters,
nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ select
id,
currency,
`date`,
timestamp_col,
`HKD@spéçiäl & characters`,
hkd_special___characters,
nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ select
id,
currency,
`date`,
timestamp_col,
`HKD@spéçiäl & characters`,
hkd_special___characters,
nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
{{ json_extract_scalar('_airbyte_data', ['id'], ['id']) }} as id,
{{ json_extract_scalar('_airbyte_data', ['currency'], ['currency']) }} as currency,
{{ json_extract_scalar('_airbyte_data', ['date'], ['date']) }} as {{ adapter.quote('date') }},
{{ json_extract_scalar('_airbyte_data', ['timestamp_col'], ['timestamp_col']) }} as timestamp_col,
{{ json_extract_scalar('_airbyte_data', ['HKD@spéçiäl & characters'], ['HKD@spéçiäl & characters']) }} as {{ adapter.quote('HKD@spéçiäl & characters') }},
{{ json_extract_scalar('_airbyte_data', ['HKD_special___characters'], ['HKD_special___characters']) }} as hkd_special___characters,
{{ json_extract_scalar('_airbyte_data', ['NZD'], ['NZD']) }} as nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
select
cast(id as {{ dbt_utils.type_bigint() }}) as id,
cast(currency as {{ dbt_utils.type_string() }}) as currency,
cast({{ adapter.quote('date') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('date') }},
cast({{ adapter.quote('date') }} as {{ type_date() }}) as {{ adapter.quote('date') }},
cast(timestamp_col as {{ type_timestamp_with_timezone() }}) as timestamp_col,
cast({{ adapter.quote('HKD@spéçiäl & characters') }} as {{ dbt_utils.type_float() }}) as {{ adapter.quote('HKD@spéçiäl & characters') }},
cast(hkd_special___characters as {{ dbt_utils.type_string() }}) as hkd_special___characters,
cast(nzd as {{ dbt_utils.type_float() }}) as nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ select
'id',
'currency',
adapter.quote('date'),
'timestamp_col',
adapter.quote('HKD@spéçiäl & characters'),
'hkd_special___characters',
'nzd',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
{{ json_extract_scalar('_airbyte_data', ['id'], ['id']) }} as id,
{{ json_extract_scalar('_airbyte_data', ['currency'], ['currency']) }} as currency,
{{ json_extract_scalar('_airbyte_data', ['date'], ['date']) }} as {{ adapter.quote('date') }},
{{ json_extract_scalar('_airbyte_data', ['timestamp_col'], ['timestamp_col']) }} as timestamp_col,
{{ json_extract_scalar('_airbyte_data', ['HKD@spéçiäl & characters'], ['HKD@spéçiäl & characters']) }} as {{ adapter.quote('HKD@spéçiäl & characters') }},
{{ json_extract_scalar('_airbyte_data', ['HKD_special___characters'], ['HKD_special___characters']) }} as hkd_special___characters,
{{ json_extract_scalar('_airbyte_data', ['NZD'], ['NZD']) }} as nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
select
cast(id as {{ dbt_utils.type_bigint() }}) as id,
cast(currency as {{ dbt_utils.type_string() }}) as currency,
cast({{ adapter.quote('date') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('date') }},
cast({{ adapter.quote('date') }} as {{ type_date() }}) as {{ adapter.quote('date') }},
cast(timestamp_col as {{ type_timestamp_with_timezone() }}) as timestamp_col,
cast({{ adapter.quote('HKD@spéçiäl & characters') }} as {{ dbt_utils.type_float() }}) as {{ adapter.quote('HKD@spéçiäl & characters') }},
cast(hkd_special___characters as {{ dbt_utils.type_string() }}) as hkd_special___characters,
cast(nzd as {{ dbt_utils.type_float() }}) as nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ select
'id',
'currency',
adapter.quote('date'),
'timestamp_col',
adapter.quote('HKD@spéçiäl & characters'),
'hkd_special___characters',
'nzd',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
id,
currency,
{{ adapter.quote('date') }},
timestamp_col,
{{ adapter.quote('HKD@spéçiäl & characters') }},
hkd_special___characters,
nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
id,
currency,
{{ adapter.quote('date') }},
timestamp_col,
{{ adapter.quote('HKD@spéçiäl & characters') }},
hkd_special___characters,
nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ select
id,
currency,
{{ adapter.quote('date') }},
timestamp_col,
{{ adapter.quote('HKD@spéçiäl & characters') }},
hkd_special___characters,
nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ select
jsonb_extract_path_text(_airbyte_data, 'id') as "id",
jsonb_extract_path_text(_airbyte_data, 'currency') as currency,
jsonb_extract_path_text(_airbyte_data, 'date') as "date",
jsonb_extract_path_text(_airbyte_data, 'timestamp_col') as timestamp_col,
jsonb_extract_path_text(_airbyte_data, 'HKD@spéçiäl & characters') as "HKD@spéçiäl & characters",
jsonb_extract_path_text(_airbyte_data, 'HKD_special___characters') as hkd_special___characters,
jsonb_extract_path_text(_airbyte_data, 'NZD') as nzd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ select
varchar
) as currency,
cast("date" as
varchar
date
) as "date",
cast(timestamp_col as
timestamp with time zone
) as timestamp_col,
cast("HKD@spéçiäl & characters" as
float
) as "HKD@spéçiäl & characters",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ select
varchar
), '') || '-' || coalesce(cast("date" as
varchar
), '') || '-' || coalesce(cast(timestamp_col as
varchar
), '') || '-' || coalesce(cast("HKD@spéçiäl & characters" as
varchar
), '') || '-' || coalesce(cast(hkd_special___characters as
Expand Down
Loading

0 comments on commit 923884b

Please sign in to comment.