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

🐛 Correct unnest_column_name conflict with table_alias #5467

Merged
merged 9 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,27 @@
{%- endmacro %}

{% macro postgres__json_extract(from_table, json_column, json_path_list, normalized_json_path) -%}
jsonb_extract_path({{ from_table }}.{{ json_column }}, {{ format_json_path(json_path_list) }})
{%- if json_column|string() == "_airbyte_nested_data" %}
marcosmarxm marked this conversation as resolved.
Show resolved Hide resolved
jsonb_extract_path({{ json_column }}, {{ format_json_path(json_path_list) }})
{% else %}
jsonb_extract_path({{ from_table }}.{{ json_column }}, {{ format_json_path(json_path_list) }})
{% endif -%}
{%- endmacro %}

{% macro mysql__json_extract(from_table, json_column, json_path_list, normalized_json_path) -%}
json_extract({{ from_table }}.{{ json_column }}, {{ format_json_path(normalized_json_path) }})
{%- if json_column|string() == "_airbyte_nested_data" %}
json_extract({{ json_column }}, {{ format_json_path(normalized_json_path) }})
{% else %}
json_extract({{ from_table }}.{{ json_column }}, {{ format_json_path(normalized_json_path) }})
{% endif -%}
{%- endmacro %}

{% macro redshift__json_extract(from_table, json_column, json_path_list, normalized_json_path) -%}
case when json_extract_path_text({{ from_table }}.{{ json_column }}, {{ format_json_path(json_path_list) }}, true) != '' then json_extract_path_text({{ from_table }}.{{ json_column }}, {{ format_json_path(json_path_list) }}, true) end
{%- if json_column|string() == "_airbyte_nested_data" %}
case when json_extract_path_text({{ json_column }}, {{ format_json_path(json_path_list) }}, true) != '' then json_extract_path_text({{ json_column }}, {{ format_json_path(json_path_list) }}, true) end
{% else %}
case when json_extract_path_text({{ from_table }}.{{ json_column }}, {{ format_json_path(json_path_list) }}, true) != '' then json_extract_path_text({{ from_table }}.{{ json_column }}, {{ format_json_path(json_path_list) }}, true) end
{% endif -%}
{%- endmacro %}

{% macro snowflake__json_extract(from_table, json_column, json_path_list, normalized_json_path) -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- SQL model to parse JSON blob stored in a single column and extract into separated field columns as described by the JSON Schema
select
json_extract_scalar(_airbyte_data, "$['id']") as id,
json_extract(table_alias._airbyte_data, "$['conflict_stream_array']") as conflict_stream_array,
json_extract_array(_airbyte_data, "$['conflict_stream_array']") as conflict_stream_array,
_airbyte_emitted_at
from `dataline-integration-testing`.test_normalization._airbyte_raw_conflict_stream_array as table_alias
-- conflict_stream_array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ select
cast(id as
string
) as id,
cast(conflict_stream_array as
string
) as conflict_stream_array,
conflict_stream_array,
_airbyte_emitted_at
from `dataline-integration-testing`._airbyte_test_normalization.`conflict_stream_array_ab1`
-- conflict_stream_array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ select
*,
to_hex(md5(cast(concat(coalesce(cast(id as
string
), ''), '-', coalesce(cast(conflict_stream_array as
), ''), '-', coalesce(cast(array_to_string(conflict_stream_array, "|", "") as
string
), '')) as
string
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- SQL model to parse JSON blob stored in a single column and extract into separated field columns as described by the JSON Schema
select
{{ json_extract_scalar('_airbyte_data', ['id'], ['id']) }} as id,
{{ json_extract('table_alias', '_airbyte_data', ['conflict_stream_array'], ['conflict_stream_array']) }} as conflict_stream_array,
{{ json_extract_array('_airbyte_data', ['conflict_stream_array'], ['conflict_stream_array']) }} as conflict_stream_array,
_airbyte_emitted_at
from {{ source('test_normalization', '_airbyte_raw_conflict_stream_array') }} as table_alias
-- conflict_stream_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- SQL model to cast each column to its adequate SQL type converted from the JSON schema type
select
cast(id as {{ dbt_utils.type_string() }}) as id,
cast(conflict_stream_array as {{ type_json() }}) as conflict_stream_array,
conflict_stream_array,
_airbyte_emitted_at
from {{ ref('conflict_stream_array_ab1') }}
-- conflict_stream_array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ select
*,
{{ dbt_utils.surrogate_key([
'id',
'conflict_stream_array',
array_to_string('conflict_stream_array'),
]) }} as _airbyte_conflict_stream_array_hashid
from {{ ref('conflict_stream_array_ab2') }}
-- conflict_stream_array
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading