-
Notifications
You must be signed in to change notification settings - Fork 90
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
WIP - Glue integration #529
Changes from 23 commits
5b9dcac
e05cd0d
6f3eb70
9ded65c
4cce0c1
1cf8b8f
f2d0e38
d2580c2
1b24722
ee85c5d
afc20cd
9d27bf9
4445b12
b65eea4
0a0aa76
452f0f2
3587f5c
0f5887e
74bb6c4
a890dc3
169d494
82907bb
62e366f
b93b90c
685d52e
87a09fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,21 @@ | |
{% set queries_len = insert_rows_queries | length %} | ||
{% for insert_query in insert_rows_queries %} | ||
{% do elementary.file_log("[{}/{}] Running insert query.".format(loop.index, queries_len)) %} | ||
{% do elementary.run_query(insert_query) %} | ||
{% if target.type == 'glue' %} | ||
{% do dbt.glue_exec_query(insert_query) %} | ||
{% else %} | ||
{% do elementary.run_query(insert_query) %} | ||
{% endif %} | ||
{% endfor %} | ||
{% elif insert_rows_method == 'chunk' %} | ||
{% set rows_chunks = elementary.split_list_to_chunks(rows, chunk_size) %} | ||
{% for rows_chunk in rows_chunks %} | ||
{% set insert_rows_query = elementary.get_chunk_insert_query(table_relation, columns, rows_chunk) %} | ||
{% do elementary.run_query(insert_rows_query) %} | ||
{% if target.type == 'glue' %} | ||
{% do dbt.glue_exec_query(insert_rows_query) %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as #r1318786335 |
||
{% else %} | ||
{% do elementary.run_query(insert_rows_query) %} | ||
{% endif %} | ||
{% endfor %} | ||
{% else %} | ||
{% do exceptions.raise_compiler_error("Specified invalid value for 'insert_rows_method' var.") %} | ||
|
@@ -57,7 +65,7 @@ | |
{% do rendered_column_values.append(column_value) %} | ||
{% else %} | ||
{% set column_value = elementary.insensitive_get_dict_value(row, column.name) %} | ||
{% do rendered_column_values.append(elementary.render_value(column_value)) %} | ||
{% do rendered_column_values.append(elementary.render_value(column_value, column.data_type)) %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing column data_type in order to cast timestamp columns for glue |
||
{% endif %} | ||
{% endfor %} | ||
{% set row_sql = "({})".format(rendered_column_values | join(",")) %} | ||
|
@@ -92,7 +100,7 @@ | |
{% for row in rows -%} | ||
({%- for column in columns -%} | ||
{%- set column_value = elementary.insensitive_get_dict_value(row, column.name, none) -%} | ||
{{ elementary.render_value(column_value) }} | ||
{{ elementary.render_value(column_value, column.data_type) }} | ||
{{- "," if not loop.last else "" -}} | ||
{%- endfor -%}) {{- "," if not loop.last else "" -}} | ||
{%- endfor -%} | ||
|
@@ -116,10 +124,16 @@ | |
{{- return(string_value | replace("'", "''")) -}} | ||
{%- endmacro -%} | ||
|
||
{%- macro render_value(value) -%} | ||
{%- macro glue__escape_special_chars(string_value) -%} | ||
{{- return(string_value | replace("'", '"')) -}} | ||
{%- endmacro -%} | ||
|
||
{%- macro render_value(value, data_type=none) -%} | ||
{%- if value is defined and value is not none -%} | ||
{%- if value is number -%} | ||
{{- value -}} | ||
{%- elif target.type == 'glue' and data_type=='timestamp' -%} | ||
cast('{{- value -}}' as timestamp) | ||
{%- elif value is string -%} | ||
'{{- elementary.escape_special_chars(value) -}}' | ||
{%- elif value is mapping or value is sequence -%} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,15 @@ | |
|
||
{% do adapter.drop_relation(intermediate_relation) %} | ||
{% endmacro %} | ||
|
||
{# Glue - truncate and insert (non-atomic) #} | ||
{% macro glue__replace_table_data(relation, rows) %} | ||
{% set intermediate_relation = elementary.create_intermediate_relation(relation, rows, temporary=True) %} | ||
{% do dbt.glue_exec_query(dbt.get_insert_overwrite_sql(intermediate_relation, relation)) %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally should be using Note: When DDL and DML statements are passed to |
||
|
||
{% set query %} | ||
drop table if exists {{ intermediate_relation }} | ||
{% endset %} | ||
|
||
{% do dbt.glue_exec_query(query) %} | ||
{% endmacro %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as #r1318786335