Skip to content

Commit c8022c2

Browse files
committed
try updating json_operations
1 parent 213f47a commit c8022c2

File tree

1 file changed

+19
-7
lines changed
  • airbyte-integrations/bases/base-normalization/dbt-project-template/macros/cross_db_utils

1 file changed

+19
-7
lines changed

airbyte-integrations/bases/base-normalization/dbt-project-template/macros/cross_db_utils/json_operations.sql

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@
4343
{%- endmacro %}
4444

4545
{% macro redshift__format_json_path(json_path_list) -%}
46+
{%- set quote = '"' if redshift_super_type() else "'" -%}
4647
{%- set str_list = [] -%}
4748
{%- for json_path in json_path_list -%}
48-
{%- if str_list.append(json_path.replace("'", "''")) -%} {%- endif -%}
49+
{%- if str_list.append(json_path.replace(quote, quote + quote)) -%} {%- endif -%}
4950
{%- endfor -%}
50-
{{ "'" ~ str_list|join("','") ~ "'" }}
51+
{{ quote ~ str_list|join(quote + "," + quote) ~ quote }}
5152
{%- endmacro %}
5253

5354
{% macro snowflake__format_json_path(json_path_list) -%}
@@ -114,11 +115,14 @@
114115
{%- endmacro %}
115116

116117
{% macro redshift__json_extract(from_table, json_column, json_path_list, normalized_json_path) -%}
117-
{%- if from_table|string() == '' %}
118+
{%- if from_table|string() != '' -%}
119+
{%- set json_column = from_table|string() + "." + json_column|string() -%}
120+
{%- endif -%}
121+
{%- if redshift_super_type() -%}
122+
case when {{ json_column }}.{{ format_json_path(json_path_list) }} != '' then {{ json_column }}.{{ format_json_path(json_path_list) }} end
123+
{%- else -%}
118124
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
119-
{% else %}
120-
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
121-
{% endif -%}
125+
{%- endif -%}
122126
{%- endmacro %}
123127

124128
{% macro snowflake__json_extract(from_table, json_column, json_path_list, normalized_json_path) -%}
@@ -168,7 +172,11 @@
168172
{%- endmacro %}
169173

170174
{% macro redshift__json_extract_scalar(json_column, json_path_list, normalized_json_path) -%}
175+
{%- if redshift_super_type() -%}
176+
case when {{ json_column }}.{{ format_json_path(json_path_list) }} != '' then {{ json_column }}.{{ format_json_path(json_path_list) }} end
177+
{%- else -%}
171178
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
179+
{%- endif -%}
172180
{%- endmacro %}
173181

174182
{% macro snowflake__json_extract_scalar(json_column, json_path_list, normalized_json_path) -%}
@@ -210,7 +218,11 @@
210218
{%- endmacro %}
211219

212220
{% macro redshift__json_extract_array(json_column, json_path_list, normalized_json_path) -%}
221+
{%- if redshift_super_type() -%}
222+
{{ json_column }}.{{ format_json_path(json_path_list) }}
223+
{%- else -%}
213224
json_extract_path_text({{ json_column }}, {{ format_json_path(json_path_list) }}, true)
225+
{%- endif -%}
214226
{%- endmacro %}
215227

216228
{% macro snowflake__json_extract_array(json_column, json_path_list, normalized_json_path) -%}
@@ -223,4 +235,4 @@
223235

224236
{% macro clickhouse__json_extract_array(json_column, json_path_list, normalized_json_path) -%}
225237
JSONExtractArrayRaw({{ json_column }}, {{ format_json_path(json_path_list) }})
226-
{%- endmacro %}
238+
{%- endmacro %}

0 commit comments

Comments
 (0)