From 96a9d8a70eba4499263b805c05a6f17535dd9f51 Mon Sep 17 00:00:00 2001 From: bentsileviav Date: Tue, 20 Aug 2024 11:03:15 +0300 Subject: [PATCH] improve tests --- .../adapter/projections/test_projections.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/integration/adapter/projections/test_projections.py b/tests/integration/adapter/projections/test_projections.py index a3cb48b6..1719551f 100644 --- a/tests/integration/adapter/projections/test_projections.py +++ b/tests/integration/adapter/projections/test_projections.py @@ -1,5 +1,6 @@ import os import time +import uuid import pytest from dbt.tests.util import relation_from_name, run_dbt @@ -64,8 +65,10 @@ def test_create_and_verify_projection(self, project): run_dbt() relation = relation_from_name(project.adapter, "people_with_projection") - - query = f"SELECT department, avg(age) AS avg_age FROM {project.test_schema}.{relation.name} GROUP BY department ORDER BY department" + unique_query_identifier = str(uuid.uuid4()) + query = f""" -- {unique_query_identifier} + SELECT department, avg(age) AS avg_age FROM {project.test_schema}.{relation.name} + GROUP BY department ORDER BY department""" # Check that the projection works as expected result = project.run_sql(query, fetch="all") @@ -77,7 +80,9 @@ def test_create_and_verify_projection(self, project): # check that the latest query used the projection result = project.run_sql( - f"SELECT query, projections FROM system.query_log WHERE query like '%{query}%' ORDER BY query_start_time DESC", + f"SELECT query, projections FROM clusterAllReplicas(default, 'system.query_log') " + f"WHERE query like '%{unique_query_identifier}%' " + f"and query not like '%system.query_log%' and read_rows > 0 ORDER BY query_start_time DESC", fetch="all", ) assert len(result) > 0 @@ -92,8 +97,10 @@ def test_create_and_verify_distributed_projection(self, project): run_dbt(["seed"]) run_dbt() relation = relation_from_name(project.adapter, "distributed_people_with_projection") - - query = f"SELECT department, avg(age) AS avg_age FROM {project.test_schema}.{relation.name} GROUP BY department ORDER BY department" + unique_query_identifier = str(uuid.uuid4()) + query = f"""-- {unique_query_identifier} + SELECT department, avg(age) AS avg_age FROM {project.test_schema}.{relation.name} GROUP BY + department ORDER BY department""" # Check that the projection works as expected result = project.run_sql(query, fetch="all") @@ -105,9 +112,9 @@ def test_create_and_verify_distributed_projection(self, project): # check that the latest query used the projection result = project.run_sql( - f"SELECT query, projections FROM system.query_log WHERE query like '%{query}%' " - f"and query not like '%system.query_log%'" - f"ORDER BY query_start_time DESC", + f"SELECT query, projections FROM clusterAllReplicas(default, 'system.query_log') " + f"WHERE query like '%{unique_query_identifier}%' " + f"and query not like '%system.query_log%' and read_rows > 0 ORDER BY query_start_time DESC", fetch="all", ) assert len(result) > 0