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

Adding minimal write option when creating table with Delta format #416

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## New version
- Fix session provisioning timeout and delay handling
- Add write options for Delta format
- Add on_schema_change possibility
- Fix table materialization for Delta models
- Change GlueColumn parent from base Column to SparkColumn
Expand Down
9 changes: 7 additions & 2 deletions dbt/adapters/glue/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def delta_update_manifest(self, target_relation, custom_location, partition_by):
self._update_additional_location(target_relation, location)

@available
def delta_create_table(self, target_relation, request, primary_key, partition_key, custom_location):
def delta_create_table(self, target_relation, request, primary_key, partition_key, custom_location, delta_create_table_write_options=None):
session, client = self.get_connection()
logger.debug(request)

Expand All @@ -643,6 +643,11 @@ def delta_create_table(self, target_relation, request, primary_key, partition_ke
location = f"{session.credentials.location}/{target_relation.schema}/{target_relation.name}"
else:
location = custom_location

options_string = ""
if delta_create_table_write_options:
for key, value in delta_create_table_write_options.items():
options_string += f'.option("{key}", "{value}")'

create_table_query = f"""
CREATE TABLE {table_name}
Expand All @@ -654,7 +659,7 @@ def delta_create_table(self, target_relation, request, primary_key, partition_ke
custom_glue_code_for_dbt_adapter
spark.sql("""
{request}
""").write.format("delta").mode("overwrite")'''
""").write.format("delta").mode("overwrite"){options_string}'''

write_data_footer = f'''.save("{location}")
SqlWrapper2.execute("""select 1""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{%- set custom_location = config.get('custom_location', default='empty') -%}
{%- set expire_snapshots = config.get('iceberg_expire_snapshots', 'True') -%}
{%- set table_properties = config.get('table_properties', default='empty') -%}
{%- set delta_create_table_write_options = config.get('write_options', default={}) -%}

{% set target_relation = this %}
{%- set existing_relation = load_relation(this) -%}
Expand Down Expand Up @@ -50,7 +51,7 @@
{% endif %}
{% if existing_relation_type is none %}
{% if file_format == 'delta' %}
{{ adapter.delta_create_table(target_relation, sql, unique_key, partition_by, custom_location) }}
{{ adapter.delta_create_table(target_relation, sql, unique_key, partition_by, custom_location, delta_create_table_write_options) }}
{% set build_sql = "select * from " + target_relation.schema + "." + target_relation.identifier + " limit 1 " %}
{% elif file_format == 'iceberg' %}
{{ adapter.iceberg_write(target_relation, sql, unique_key, partition_by, custom_location, strategy, table_properties) }}
Expand All @@ -61,7 +62,7 @@
{% elif existing_relation_type == 'view' or should_full_refresh() %}
{{ drop_relation(target_relation) }}
{% if file_format == 'delta' %}
{{ adapter.delta_create_table(target_relation, sql, unique_key, partition_by, custom_location) }}
{{ adapter.delta_create_table(target_relation, sql, unique_key, partition_by, custom_location, delta_create_table_write_options) }}
{% set build_sql = "select * from " + target_relation.schema + "." + target_relation.identifier + " limit 1 " %}
{% elif file_format == 'iceberg' %}
{{ adapter.iceberg_write(target_relation, sql, unique_key, partition_by, custom_location, strategy, table_properties) }}
Expand Down
Loading