From c15d55ee982b30a7e9bab739d7cee5f845068e8f Mon Sep 17 00:00:00 2001 From: Liam O'Boyle Date: Wed, 28 Sep 2022 12:32:43 +1000 Subject: [PATCH] Limit columns selected in `expression_is_true` if failures not stored. (#686) * Update from template to dbt copyright (#647) * Update from template to dbt copyright I want to give proper attribution and licensing to code from dbt_utils that I'm using, so made this fix. Hope it's ok. * Update LICENSE * Limit columns selected in `expression_is_true` if failures not stored. Fixes #683 Co-authored-by: Maayan Salom Co-authored-by: Joel Labes --- CHANGELOG.md | 1 + LICENSE | 2 +- macros/generic_tests/expression_is_true.sql | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f41e876e..e09a5f3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ## New features - Implemented an optional `group_by_columns` argument across many of the generic testing macros to test for properties that only pertain to group-level or are can be more rigorously conducted at the group level. Property available in `recency`, `at_least_one`, `equal_row_count`, `fewer_rows_than`, `not_constant`, `not_null_proportion`, and `sequential` tests [#633](https://github.com/dbt-labs/dbt-utils/pull/633) - New feature to omit the `source_column_name` column on the `union_relations` macro ([#331](https://github.com/dbt-labs/dbt-utils/issues/331), [#624](https://github.com/dbt-labs/dbt-utils/pull/624)) +- New feature to select fewer columns in `expression_is_true` ([#683](https://github.com/dbt-labs/dbt-utils/issues/683), [#686](https://github.com/dbt-labs/dbt-utils/pull/686)) - Add `not_empty_string` generic test that asserts column values are not an empty string. ([#632](https://github.com/dbt-labs/dbt-utils/issues/632), [#634](https://github.com/dbt-labs/dbt-utils/pull/634)) ## Under the hood diff --git a/LICENSE b/LICENSE index 261eeb9e..d807259a 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2022 dbt Labs, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/macros/generic_tests/expression_is_true.sql b/macros/generic_tests/expression_is_true.sql index 611685b4..b8aa7ad4 100644 --- a/macros/generic_tests/expression_is_true.sql +++ b/macros/generic_tests/expression_is_true.sql @@ -6,12 +6,14 @@ {% macro default__test_expression_is_true(model, expression, column_name, condition) %} +{% set column_list = '*' if should_store_failures() else "1" %} + with meet_condition as ( select * from {{ model }} where {{ condition }} ) select - * + {{ column_list }} from meet_condition {% if column_name is none %} where not({{ expression }})