fix: alias filler column in expression_is_true for strict-alias dialects#1086
Open
sdebruyn wants to merge 1 commit into
Open
fix: alias filler column in expression_is_true for strict-alias dialects#1086sdebruyn wants to merge 1 commit into
sdebruyn wants to merge 1 commit into
Conversation
The placeholder column emitted when should_store_failures() is false was an unnamed literal `1`. That is valid SQL standalone but invalid inside a subquery on strict-alias dialects (T-SQL / Microsoft Fabric Data Warehouse, some Spark configurations). Naming the column `filler_column` matches the convention already used in at_least_one and is valid SQL on every supported adapter. Adds an integration test that wraps the rendered macro in an outer SELECT to lock in subquery compatibility.
Contributor
Author
|
Human reviewed. This would simplify the dbt-fabric adapter. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
default__test_expression_is_trueemits an unnamed literal1as its placeholder column whenshould_store_failures()is false:https://github.com/dbt-labs/dbt-utils/blob/main/macros/generic_tests/expression_is_true.sql#L7
This compiles fine standalone, but as soon as anything wraps the rendered SQL in a subquery, strict-alias dialects reject it because the inner column has no name. Concrete failure modes:
Msg 8155, Level 16, State 2: No column name was specified for column 1 of 'sub'.SQL compilation error: Missing column specification— reported in Missing column specification when usingexpression_is_truetest (snowflake) #822, closed as Stale without a fix.Subquery wrapping is not exotic — it happens whenever a downstream macro composes generic tests, when stored-failures alternates with non-stored-failures, or when users manually wrap the test (for example to feed it into a custom monitoring model).
Fix
One-line change: name the placeholder column.
The name
filler_columnmatches the convention already used inat_least_one, which carries an explicit comment about this same T-SQL constraint:https://github.com/dbt-labs/dbt-utils/blob/main/macros/generic_tests/at_least_one.sql#L36-L38
So the fix is consistent with how the project already solves the same class of problem in a sibling test.
Impact
expression_is_truetest (snowflake) #822, some Spark setups, anyone wrapping the test in a subquery).select 1 as filler_column from xis valid SQL on PostgreSQL, Snowflake, BigQuery, Redshift, Databricks, Spark, T-SQL, and DuckDB. The test still returns the same row count to dbt, so pass/fail semantics are unchanged.Out of scope
This PR does not reintroduce the
conditionargument removed in #700. That decision stands; this is purely a portability fix for the existing macro.Evidence
expression_is_truetest (snowflake) #822dbt-fabric: https://github.com/sdebruyn/dbt-fabric/blob/main/src/dbt/include/fabric/macros/dbt_package_support/dbt_utils/generic_tests/expression_is_true.sql — patches exactly the same line to"1 as col". With this PR, that override can be deleted.Test plan
integration_tests/tests/generic/expression_is_true_subquery_alias.sql, which compiles the macro and wraps its output in an outer SELECT. Without the fix this would have failed to compile on strict-alias dialects.data_test_expression_is_trueschema tests continue to pass on the supported adapter matrix.