Empty unit test fixtures (rows: []) emit invalid LIMIT 0 syntax#699
Open
Benjamin-Knight wants to merge 5 commits into
Open
Empty unit test fixtures (rows: []) emit invalid LIMIT 0 syntax#699Benjamin-Knight wants to merge 5 commits into
Benjamin-Knight wants to merge 5 commits into
Conversation
Chore/version v1.10.0rc1
…698) dbt-core's get_fixture_sql/get_expected_sql hardcode `limit 0` for empty fixture rows, which is not valid T-SQL. These macros are not dispatched, so shadow them in the adapter package and emit `select top 0` instead. get_expected_sql's empty branch builds typed nulls rather than selecting from dbt_internal_unit_test_actual, which is out of scope inside the view created by sqlserver__get_unit_test_sql. Also fix sqlserver__get_columns_in_query for queries starting with a CTE (hit by unit tests with an empty `expect` block): such queries cannot be wrapped in a subquery, so describe their result set via sp_describe_first_result_set instead of executing them. Non-CTE queries keep the existing TOP 0 wrapping. The CTE detection is factored into a shared sqlserver__select_starts_with_cte helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
axellpadilla
requested changes
Jun 4, 2026
Collaborator
There was a problem hiding this comment.
I don't see any other solution than shadowing, that said, inside the shadowed macro we could introduce a call to macro sqlserver__get_fixture_sql(...) instead. This would keep the SQL Server-specific logic isolated and make the implementation closer to what we would want upstream if they use adapter calls later.
This is not that important but ideally with a link to an upstream dbt-core/dbt-adapters issue requesting dispatch support. If upstream adds that dispatch point later, our future patch should mostly be removing the shadow and keeping only the SQL Server-specific sqlserver__get_fixture_sql implementation.
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.
Fixes #698
dbt-core hardcodes
limit 0for empty fixture rows, which is not valid T-SQL. These macros are not dispatched, so shadow them in the adapter package and emitselect top 0instead.Also fix sqlserver__get_columns_in_query for queries starting with a CTE (hit by unit tests with an empty
expectblock): such queries cannot be wrapped in a subquery, so describe their result set via sp_describe_first_result_set instead of executing them. Non-CTE queries keep the existing TOP 0 wrapping. The CTE detection is factored into a shared sqlserver__select_starts_with_cte helper.