From a4bc6813448ade4979e75f6c642b02fa2463797a Mon Sep 17 00:00:00 2001 From: Alexandro Hou Date: Fri, 8 Nov 2024 15:01:18 +0000 Subject: [PATCH 1/2] =?UTF-8?q?remove=20dashes=20from=20=C2=B4=5F=5Fdbt=5F?= =?UTF-8?q?tmp=C2=B4=20suffix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbt-athena/src/dbt/adapters/athena/impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt-athena/src/dbt/adapters/athena/impl.py b/dbt-athena/src/dbt/adapters/athena/impl.py index 5b94a4c9..34698694 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}" From fddcb836a6ea3391bf47f9c0cfb6b025dda79a23 Mon Sep 17 00:00:00 2001 From: Alexandro Hou Date: Sat, 23 Nov 2024 09:36:14 +0000 Subject: [PATCH 2/2] fix integration test: test_unique_tmp_table_suffix --- dbt-athena/src/dbt/adapters/athena/impl.py | 9 ++++----- .../functional/adapter/test_unique_tmp_table_suffix.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dbt-athena/src/dbt/adapters/athena/impl.py b/dbt-athena/src/dbt/adapters/athena/impl.py index 34698694..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()).replace('-', '')}" + 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(