Skip to content

Commit

Permalink
Merge branch 'main' into monorepo-prep
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare authored Dec 4, 2024
2 parents 23379d6 + b52d304 commit 2f24351
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dbt-athena-community/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
# these versions should always match and they both should match the local version of dbt-athena
dependencies = ["dbt-athena==1.9.0b1"]
version = "1.9.0b1"
dependencies = ["dbt-athena==1.9.0rc1"]
version = "1.9.0rc1"
[project.urls]
Homepage = "https://github.com/dbt-labs/dbt-athena/dbt-athena"
Documentation = "https://docs.getdbt.com"
Expand Down
2 changes: 1 addition & 1 deletion dbt-athena/src/dbt/adapters/athena/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.9.0b1"
version = "1.9.0rc1"
9 changes: 4 additions & 5 deletions dbt-athena/src/dbt/adapters/athena/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def clean_up_table(self, relation: AthenaRelation) -> None:

@available
def generate_unique_temporary_table_suffix(self, suffix_initial: str = "__dbt_tmp") -> str:
return f"{suffix_initial}_{str(uuid4())}"
return f"{suffix_initial}_{str(uuid4()).replace('-', '_')}"

def quote(self, identifier: str) -> str:
return f"{self.quote_character}{identifier}{self.quote_character}"
Expand Down Expand Up @@ -1209,22 +1209,21 @@ def _generate_snapshot_migration_sql(self, relation: AthenaRelation, table_colum
- Copy the content of the staging table to the final table
- Delete the staging table
"""
col_csv = f",\n{' ' * 16}".join(table_columns)
col_csv = f", \n{' ' * 16}".join(table_columns)
staging_relation = relation.incorporate(
path={"identifier": relation.identifier + "__dbt_tmp_migration_staging"}
)
ctas = dedent(
f"""\
select
{col_csv},
{col_csv} ,
dbt_snapshot_at as dbt_updated_at,
dbt_valid_from,
if(dbt_valid_to > cast('9000-01-01' as timestamp), null, dbt_valid_to) as dbt_valid_to,
dbt_scd_id
from {relation}
where dbt_change_type != 'delete'
;
"""
;"""
)
staging_sql = self.execute_macro(
"create_table_as", kwargs=dict(temporary=True, relation=staging_relation, compiled_code=ctas)
Expand Down
1 change: 1 addition & 0 deletions dbt-athena/src/dbt/adapters/athena/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class AthenaRelation(BaseRelation):
include_policy: Policy = field(default_factory=lambda: AthenaIncludePolicy())
s3_path_table_part: Optional[str] = None
detailed_table_type: Optional[str] = None # table_type option from the table Parameters in Glue Catalog
require_alias: bool = False

def render_hive(self) -> str:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{% set tmp_table_suffix = '__dbt_tmp' %}
{% endif %}

{% if unique_tmp_table_suffix == True and table_type == 'iceberg' %}
{% set tmp_table_suffix = adapter.generate_unique_temporary_table_suffix() %}
{% endif %}

{% set old_tmp_relation = adapter.get_relation(identifier=target_relation.identifier ~ tmp_table_suffix,
schema=schema,
database=database) %}
Expand Down
6 changes: 5 additions & 1 deletion dbt-athena/tests/functional/adapter/test_empty.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from dbt.tests.adapter.empty.test_empty import BaseTestEmpty
from dbt.tests.adapter.empty.test_empty import BaseTestEmpty, BaseTestEmptyInlineSourceRef


class TestAthenaEmpty(BaseTestEmpty):
pass


class TestAthenaEmptyInlineSourceRef(BaseTestEmptyInlineSourceRef):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test__unique_tmp_table_suffix(self, project, capsys):
model_run_result_row_count_query = f"select count(*) as records from {project.test_schema}.{relation_name}"
expected_unique_table_name_re = (
r"unique_tmp_table_suffix__dbt_tmp_"
r"[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}"
r"[0-9a-fA-F]{8}_[0-9a-fA-F]{4}_[0-9a-fA-F]{4}_[0-9a-fA-F]{4}_[0-9a-fA-F]{12}"
)

first_model_run = run_dbt(
Expand Down

0 comments on commit 2f24351

Please sign in to comment.