Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable sql_header within generic data tests #9854

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Apr 4, 2024

part of addressing #9775

This is part of proof-of-concept (POC). See dbt-labs/dbt-adapters#145 for the other piece.

Problem

Currently, any sql_header config doesn't have any effect for:

And it only has effect for:

Put another way

The sql_header configuration only works for singular data tests that have store_failures_as="table" (or store_failures=true).

Solution

Enable sql_header to apply to both singular and generic data tests regardless if they are storing failures or not.

Cons

  • The sql_header will be applied twice when storing failures -- the 2nd time is essentially wasted because it isn't needed there
  • Adding the sql_header to core/dbt/artifacts/resources/v1/config.py and core/dbt/parser/generic_test_builders.py don't seem like quite the right place -- it seems like it would be better defined one level higher and then inherited

Kicking the tires

Example project and commands to try this out

Project files:

models/model_with_singular_data_test.sql

select 1 as id

models/model_with_generic_data_test.sql

select 2 as id

tests/singular_data_test__store_failures_as_table.sql

{{ config(store_failures_as="table") }}

{%- call set_sql_header(config) -%}
    -- CREATE TEMP FUNCTION 1.2 singular store_failures_as table ...
{%- endcall -%}

select 1 as id
from {{ ref("model_with_singular_data_test") }}
where 1=0

tests/singular_data_test__store_failures_as_ephemeral.sql

{{ config(store_failures_as="ephemeral") }}

{%- call set_sql_header(config) -%}
    -- CREATE TEMP FUNCTION 1.1 singular store_failures_as ephemeral ...
{%- endcall -%}

select 1 as id
from {{ ref("model_with_singular_data_test") }}
where 1=0

models/_models.yml

models:
  - name: model_with_generic_data_test
    columns:
      - name: id
        data_tests:
          - unique:
              name: generic_data_test__store_failures_as_ephemeral
              config:
                sql_header: "-- CREATE TEMP FUNCTION 2.1 generic store_failures_as ephemeral ..."
                store_failures_as: ephemeral
          - unique:
              name: generic_data_test__store_failures_as_table
              config:
                sql_header: "-- CREATE TEMP FUNCTION 2.2 generic store_failures_as table ..."
                store_failures_as: table

Build the project (run the models and tests):

rm -rf logs
rm -rf target
dbt build

Open the logs file (logs/dbt.log).

Then search for -- CREATE TEMP FUNCTION.

All of the following should show up in the search (at the beginning of separate SQL statements) corresponding to each of the (4) main test cases:

  • 1.1 - singular store_failures_as ephemeral
  • 1.2 - singular store_failures_as table
  • 2.1 - generic store_failures_as ephemeral
  • 2.2 - generic store_failures_as table

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@cla-bot cla-bot bot added the cla:yes label Apr 4, 2024
Copy link
Contributor

github-actions bot commented Apr 4, 2024

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

Copy link

codecov bot commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.75%. Comparing base (a994ace) to head (7bde5ac).
Report is 250 commits behind head on main.

Files with missing lines Patch % Lines
core/dbt/parser/generic_test_builders.py 80.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (a994ace) and HEAD (7bde5ac). Click for more details.

HEAD has 27 uploads less than BASE
Flag BASE (a994ace) HEAD (7bde5ac)
unit 5 1
integration 25 2
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9854      +/-   ##
==========================================
- Coverage   88.12%   82.75%   -5.38%     
==========================================
  Files         178      178              
  Lines       22459    22465       +6     
==========================================
- Hits        19793    18590    -1203     
- Misses       2666     3875    +1209     
Flag Coverage Δ
integration 78.16% <83.33%> (-7.42%) ⬇️
unit 61.78% <50.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Oct 2, 2024

This PR has been marked as Stale because it has been open with no activity as of late. If you would like the PR to remain open, please comment on the PR or else it will be closed in 7 days.

@github-actions github-actions bot added stale Issues that have gone stale and removed stale Issues that have gone stale labels Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant