Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BentsiLeviav committed Aug 20, 2024
1 parent e670523 commit 96a9d8a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/integration/adapter/projections/test_projections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import time
import uuid

import pytest
from dbt.tests.util import relation_from_name, run_dbt
Expand Down Expand Up @@ -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")
Expand 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
Expand All @@ -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")
Expand 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
Expand Down

0 comments on commit 96a9d8a

Please sign in to comment.