Skip to content

Commit

Permalink
Invalid tmp table name when using: unique_tmp_table_suffix (#754)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandro Hou <[email protected]>
Co-authored-by: Colin Rogers <[email protected]>
  • Loading branch information
3 people authored Nov 23, 2024
1 parent bacbe23 commit a425cc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
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
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 a425cc6

Please sign in to comment.