diff --git a/dbt-athena/src/dbt/adapters/athena/impl.py b/dbt-athena/src/dbt/adapters/athena/impl.py index 5b94a4c9..e70cca3c 100755 --- a/dbt-athena/src/dbt/adapters/athena/impl.py +++ b/dbt-athena/src/dbt/adapters/athena/impl.py @@ -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}" @@ -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) diff --git a/dbt-athena/tests/functional/adapter/test_unique_tmp_table_suffix.py b/dbt-athena/tests/functional/adapter/test_unique_tmp_table_suffix.py index 563e5dcb..0f188ce1 100644 --- a/dbt-athena/tests/functional/adapter/test_unique_tmp_table_suffix.py +++ b/dbt-athena/tests/functional/adapter/test_unique_tmp_table_suffix.py @@ -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(