Skip to content

Commit 575c7b2

Browse files
authored
Merge pull request #2 from rjh336/fix/generate_select_logs-snowflake-schema
replace hard coded db with snowflake target
2 parents 830673f + 85b4bbe commit 575c7b2

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

.circleci/config.yml

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ jobs:
2626
. venv/bin/activate
2727
pip install -U pip setuptools wheel
2828
pip install -r dev-requirements.txt
29+
- run:
30+
name: Rename dbt models
31+
command: |
32+
. venv/bin/activate
33+
export GLOBAL_MODEL_SUFFIX=`date +%s`
34+
touch .env && echo "GLOBAL_MODEL_SUFFIX=$GLOBAL_MODEL_SUFFIX" >> .env
35+
mv ./integration_tests/models/test_model_table.sql ./integration_tests/models/test_model_table_`echo $GLOBAL_MODEL_SUFFIX`.sql
36+
mv ./integration_tests/models/test_model_view.sql ./integration_tests/models/test_model_view_`echo $GLOBAL_MODEL_SUFFIX`.sql
37+
sed -i -e "s/test_model_table/test_model_table_$GLOBAL_MODEL_SUFFIX/g" ./integration_tests/models/properties.yml
38+
sed -i -e "s/test_model_view/test_model_view_$GLOBAL_MODEL_SUFFIX/g" ./integration_tests/models/properties.yml
2939
- run:
3040
name: Install dbt dependencies
3141
command: |

dev-requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ dbt-postgres
33
dbt-bigquery
44
dbt-snowflake
55
pytest
6+
python-dotenv
67
google-cloud-bigquery
7-
snowflake-connector-python==2.7.9
8+
snowflake-connector-python==2.8.1

macros/common/generate_select_logs_query.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
query_id,
6767
query_text
6868
from
69-
table(dbt_model_usage.information_schema.query_history(result_limit => 10000))
69+
table({{ target_model.database }}.information_schema.query_history(result_limit => 10000))
7070
where
7171
query_type = 'SELECT'
7272
and start_time between timestampadd({{ time_unit }}, -{{ num_units }}, current_timestamp()) and current_timestamp()

scripts/query_database.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
from dotenv import load_dotenv
2+
load_dotenv()
13
import os
24
import sys
35
import snowflake.connector
46
from google.cloud import bigquery
57

68
QUERIES = {
79
'models_query': """
8-
select * from {0}.{1}.test_model_view
10+
select * from {0}.{1}.test_model_view_{2}
911
union all
10-
select * from {0}.{1}.test_model_table
12+
select * from {0}.{1}.test_model_table_{2}
1113
""",
1214

1315
'columns_query': """
1416
select string_field
15-
from {0}.{1}.test_model_view
17+
from {0}.{1}.test_model_view_{2}
1618
"""
1719
}
1820

@@ -24,7 +26,8 @@ def main(target, query_name):
2426
bigquery_ctx = bigquery.Client()
2527
query = query_format_string.format(
2628
os.getenv('BIGQUERY_TEST_DATABASE'),
27-
os.getenv('TEST_SCHEMA')
29+
os.getenv('TEST_SCHEMA'),
30+
os.getenv('GLOBAL_MODEL_SUFFIX')
2831
)
2932
print(f"{query}\n")
3033
_ = bigquery_ctx.query(query).result()
@@ -36,7 +39,9 @@ def main(target, query_name):
3639
account=os.getenv('SNOWFLAKE_ACCOUNT_ID'))
3740
query = query_format_string.format(
3841
os.getenv('SNOWFLAKE_TEST_DATABASE'),
39-
os.getenv('TEST_SCHEMA'))
42+
os.getenv('TEST_SCHEMA'),
43+
os.getenv('GLOBAL_MODEL_SUFFIX')
44+
)
4045
print(f"{query}\n")
4146
cur = snowflake_ctx.cursor()
4247
cur.execute(query)

scripts/run_tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ printf "\n\nRunning integration test query:"
1818
python3 ./scripts/query_database.py $dbt_target models_query
1919

2020
printf "\n\ndbt test ...\n"
21-
dbt test -t $dbt_target --project-dir $DBT_PROJECT_DIR --vars '{time_unit: second, num_units: 60}' || true
21+
dbt test -t $dbt_target --project-dir $DBT_PROJECT_DIR --vars '{time_unit: second, num_units: 30}' || true
2222
printf "\nRun results validation:\n"
2323
pytest -v scripts/test_run_results.py::test_build_failure_column_test
2424

2525
printf "\n\nRunning integration test query:"
2626
python3 ./scripts/query_database.py $dbt_target columns_query
2727

2828
printf "\n\ndbt test ...\n"
29-
dbt test -t $dbt_target --project-dir $DBT_PROJECT_DIR --vars '{time_unit: hour, num_units: 1}'
29+
dbt test -t $dbt_target --project-dir $DBT_PROJECT_DIR --vars '{time_unit: second, num_units: 40}'
3030
printf "\nRun results validation:\n"
3131
pytest -v scripts/test_run_results.py::test_build_success

0 commit comments

Comments
 (0)