From de4d3deff44c5db0568b823e15c1424eed60769b Mon Sep 17 00:00:00 2001 From: 0xRob <0xRobin5@gmail.com> Date: Thu, 6 Jun 2024 13:00:59 +0200 Subject: [PATCH] capture error --- daily_spellbook/tests/generic/check_seed.sql | 20 -------------- .../compare_column_values_to_seed_values.sql | 22 --------------- .../generic/equal_rowcount_with_sources.sql | 27 ------------------- .../tests/generic/is_unique_filtered.sql | 13 --------- scripts/check_schema.sh | 6 +++-- 5 files changed, 4 insertions(+), 84 deletions(-) delete mode 100644 daily_spellbook/tests/generic/check_seed.sql delete mode 100644 daily_spellbook/tests/generic/compare_column_values_to_seed_values.sql delete mode 100644 daily_spellbook/tests/generic/equal_rowcount_with_sources.sql delete mode 100644 daily_spellbook/tests/generic/is_unique_filtered.sql diff --git a/daily_spellbook/tests/generic/check_seed.sql b/daily_spellbook/tests/generic/check_seed.sql deleted file mode 100644 index b1af4ffb53e..00000000000 --- a/daily_spellbook/tests/generic/check_seed.sql +++ /dev/null @@ -1,20 +0,0 @@ --- this tests checks a model for every row in a seed file. --- you need to specify the matching columns and the columns to check for equality. --- filter: dictionary filter of column:value that is applied to the seed file --- actual implementation in macros/test-helpers/check_seed.sql -{% test check_seed(model, seed_file, match_columns=[], check_columns=[], filter=None) %} - {# - --jinja comment - -- potential dynamic approach, but requires db access -- ci setup to allow in future? - -- {%- set unique_columns = config.get('unique_key') -%} - -- {%- set seed_check_columns = dbt_utils.get_filtered_columns_in_relation(from=seed_file, except=unique_columns) -%} - -- {%- set seed_matching_columns = dbt_utils.get_filtered_columns_in_relation(from=seed_file, except=seed_check_columns) -%} - --jinja comment - #} - {{ config(severity = 'error') }} - {%- set seed_check_columns = check_columns -%} - {%- set seed_matching_columns = match_columns -%} - {%- set seed = seed_file -%} - {{ check_seed_macro(model,seed,seed_matching_columns,seed_check_columns,filter) }} - -{% endtest %} diff --git a/daily_spellbook/tests/generic/compare_column_values_to_seed_values.sql b/daily_spellbook/tests/generic/compare_column_values_to_seed_values.sql deleted file mode 100644 index 1073925bf62..00000000000 --- a/daily_spellbook/tests/generic/compare_column_values_to_seed_values.sql +++ /dev/null @@ -1,22 +0,0 @@ -{% test compare_column_values_to_seed_values(model, column_name, seed_file_location) %} - - with unit_test as - ( - select - seed.test_description, - case - when m.{{ column_name }} = seed.{{ column_name }} - then True - else False - end as generic_column_test - from {{ model }} m - join {{ seed_file_location }} seed - on m.tx_hash = seed.tx_hash - and m.block_number = seed.block_number - ) - - select test_description - from unit_test - where generic_column_test = False - -{% endtest %} diff --git a/daily_spellbook/tests/generic/equal_rowcount_with_sources.sql b/daily_spellbook/tests/generic/equal_rowcount_with_sources.sql deleted file mode 100644 index 71be9489536..00000000000 --- a/daily_spellbook/tests/generic/equal_rowcount_with_sources.sql +++ /dev/null @@ -1,27 +0,0 @@ -{% test equal_rowcount_with_sources(model, evt_sources=[]) %} - - WITH - model_count as ( - select count(*) as count_a from {{ model }} - ) - ,sources_count as ( - select sum(count_b) as count_b - from ( - {% for source in evt_sources %} - select count(*) as count_b - from {{ source }} - where evt_block_time <= (select max(block_time) from {{ model }}) - {% if not loop.last %} UNION ALL {% endif %} - {% endfor %} - ) b - ) - - ,unit_test as ( - select count_a, count_b, abs(count_a - count_b) as diff_count - from model_count - full outer join sources_count - on 1=1 - ) - - select * from unit_test where diff_count > 0 -{% endtest %} diff --git a/daily_spellbook/tests/generic/is_unique_filtered.sql b/daily_spellbook/tests/generic/is_unique_filtered.sql deleted file mode 100644 index da19556226c..00000000000 --- a/daily_spellbook/tests/generic/is_unique_filtered.sql +++ /dev/null @@ -1,13 +0,0 @@ -{% test is_unique_filtered(model, column_name) %} - -select - {{ column_name }} as unique_field, - count(*) as n_records - -from {{ model }} -where {{ column_name }} is not null - and block_date >= NOW() - interval '2' day -group by {{ column_name }} -having count(*) > 1 - -{% endtest %} diff --git a/scripts/check_schema.sh b/scripts/check_schema.sh index dd5db9a6ff6..b3d3fd5869b 100755 --- a/scripts/check_schema.sh +++ b/scripts/check_schema.sh @@ -1,10 +1,12 @@ -# Run the dbt command and capture its output -test=$(dbt --quiet --no-print ls $PROFILE --resource-type model --select state:modified,config.schema:no_schema --output path --state . --project-dir $PROJECT_DIR) +# Run the dbt command and capture its output and error +test=$(dbt --quiet --no-print ls $PROFILE --resource-type model --select state:modified,config.schema:no_schema --output path --state . --project-dir $PROJECT_DIR 2>error_output.txt) dbt_exit_status=$? # Check if the dbt command failed if [[ $dbt_exit_status -ne 0 ]]; then echo "Error: dbt command failed with exit status $dbt_exit_status" + echo "dbt error output:" + cat error_output.txt exit $dbt_exit_status fi