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

Invalid tmp table name when using: unique_tmp_table_suffix #754

Merged
merged 5 commits into from
Nov 23, 2024
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
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