Skip to content

fix: alias filler column in expression_is_true for strict-alias dialects#1086

Open
sdebruyn wants to merge 1 commit into
dbt-labs:mainfrom
sdebruyn:fix-expression-is-true-alias
Open

fix: alias filler column in expression_is_true for strict-alias dialects#1086
sdebruyn wants to merge 1 commit into
dbt-labs:mainfrom
sdebruyn:fix-expression-is-true-alias

Conversation

@sdebruyn

Copy link
Copy Markdown
Contributor

Problem

default__test_expression_is_true emits an unnamed literal 1 as its placeholder column when should_store_failures() is false:

https://github.com/dbt-labs/dbt-utils/blob/main/macros/generic_tests/expression_is_true.sql#L7

{% set column_list = '*' if should_store_failures() else "1" %}

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:

  • T-SQL (Microsoft SQL Server / Fabric Data Warehouse): Msg 8155, Level 16, State 2: No column name was specified for column 1 of 'sub'.
  • Snowflake (historical): SQL compilation error: Missing column specification — reported in Missing column specification when using expression_is_true test (snowflake) #822, closed as Stale without a fix.
  • Some Spark configurations that enforce strict aliasing in nested SELECTs.

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.

-{% set column_list = '*' if should_store_failures() else "1" %}
+{% set column_list = '*' if should_store_failures() else "1 as filler_column" %}

The name filler_column matches the convention already used in at_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

{# In TSQL, subquery aggregate columns need aliases #}
{# thus: a filler col name, 'filler_column' #}
count({{ column_name }}) as filler_column

So the fix is consistent with how the project already solves the same class of problem in a sibling test.

Impact

  • Helps: every strict-alias dialect (T-SQL / Fabric, Snowflake under the configurations from Missing column specification when using expression_is_true test (snowflake) #822, some Spark setups, anyone wrapping the test in a subquery).
  • Breaks: nothing. select 1 as filler_column from x is 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 condition argument removed in #700. That decision stands; this is purely a portability fix for the existing macro.

Evidence

Test plan

  • Added 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.
  • Existing data_test_expression_is_true schema tests continue to pass on the supported adapter matrix.

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.
@sdebruyn sdebruyn marked this pull request as ready for review May 19, 2026 12:40
@sdebruyn sdebruyn requested a review from a team as a code owner May 19, 2026 12:40
@sdebruyn

Copy link
Copy Markdown
Contributor Author

Human reviewed. This would simplify the dbt-fabric adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant