-
Notifications
You must be signed in to change notification settings - Fork 128
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
Support for setting table properties as part of a model configuration #49
Changes from 5 commits
ff629ed
fe3a7b8
ef35ec1
23e6ba4
d273899
65002cf
294965c
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 |
---|---|---|
|
@@ -79,6 +79,17 @@ | |
{%- endif %} | ||
{%- endmacro -%} | ||
|
||
{% macro dbt_databricks_tblproperties_clause() -%} | ||
{%- set tblproperties = config.get('tblproperties') -%} | ||
{%- if tblproperties is not none %} | ||
tblproperties ( | ||
{%- for prop in tblproperties -%} | ||
{{ prop }} = '{{ tblproperties[prop] }}' {% if not loop.last %}, {% endif %} | ||
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. it might be better to treat the prop as a string literal and wrap it in single quotes 'delta.appendOnly' just in case the user puts a reserved keyword in there. 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. for tableproperties[prop], technically the value can be a boolean, string, or numeric type. I think wrapping the value in single quotes is okay because it will try to be implicitly casted but we should double check. |
||
{%- endfor %} | ||
) | ||
{%- endif %} | ||
{%- endmacro -%} | ||
|
||
{#-- We can't use temporary tables with `create ... as ()` syntax #} | ||
{% macro dbt_databricks_create_temporary_view(relation, sql) -%} | ||
create temporary view {{ relation.include(schema=false) }} as | ||
|
@@ -100,6 +111,7 @@ | |
{{ dbt_databricks_clustered_cols(label="clustered by") }} | ||
{{ dbt_databricks_location_clause() }} | ||
{{ dbt_databricks_comment_clause() }} | ||
{{ dbt_databricks_tblproperties_clause() }} | ||
as | ||
{{ sql }} | ||
{%- endif %} | ||
superdupershant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{ config( | ||
materialized = 'incremental', | ||
unique_key = 'id', | ||
tblproperties={ | ||
'delta.autoOptimize.optimizeWrite' : 'true', | ||
'delta.autoOptimize.autoCompact' : 'true' | ||
} | ||
) }} | ||
|
||
{% if not is_incremental() %} | ||
|
||
select cast(1 as bigint) as id, 'hello' as msg | ||
union all | ||
select cast(2 as bigint) as id, 'goodbye' as msg | ||
|
||
{% else %} | ||
|
||
select cast(2 as bigint) as id, 'yo' as msg | ||
union all | ||
select cast(3 as bigint) as id, 'anyway' as msg | ||
|
||
{% endif %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
id,msg | ||
1,hello | ||
2,yo | ||
3,anyway |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from cProfile import run | ||
from tests.integration.base import DBTIntegrationTest, use_profile | ||
import dbt.exceptions | ||
|
||
import json | ||
|
||
|
||
class TestSetTblproperties(DBTIntegrationTest): | ||
@property | ||
def schema(self): | ||
return "set_tblproperties" | ||
|
||
@property | ||
def models(self): | ||
return "models" | ||
|
||
def test_set_tblproperties(self): | ||
self.run_dbt(['seed']) | ||
self.run_dbt(['run']) | ||
self.run_dbt(['run']) | ||
|
||
self.assertTablesEqual("set_tblproperties", "expected") | ||
|
||
results = self.run_sql( | ||
'describe extended {schema}.{table}'.format( | ||
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. nit: you can use "SHOW TBLPROPERTIES" it's shorter and doesn't need to be parsed. |
||
schema=self.unique_schema(), table='set_tblproperties' | ||
), | ||
fetch='all' | ||
) | ||
|
||
for result in results: | ||
if result[0] == 'Table Properties': | ||
assert 'delta.autoOptimize.optimizeWrite' in result[1] | ||
assert 'delta.autoOptimize.autoCompact' in result[1] | ||
|
||
@use_profile("databricks_cluster") | ||
def test_set_tblproperties_databricks_cluster(self): | ||
self.test_set_tblproperties() | ||
|
||
@use_profile("databricks_sql_endpoint") | ||
def test_set_tblproperties_databricks_sql_endpoint(self): | ||
self.test_set_tblproperties() |
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.
How about "Support for setting table properties as part of a model configuration"