Fix metric filter columns not included in CTE SELECT#6
Merged
Conversation
When a metric has filters like `filters: ["state IN ('confirmed', 'completed')"]`,
the filtered column must be included in the CTE's SELECT list for the WHERE clause
to reference it. Previously, metric filters were only processed after CTEs were built,
causing "Unrecognized name" errors in databases like BigQuery.
The fix extracts metric filter columns before building CTEs and passes them to
`_find_needed_dimensions` so they're included in each model's CTE SELECT clause.
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.
Summary
stateinfilters: ["state IN ('confirmed', 'completed')"]) are now included in CTE SELECT_extract_metric_filter_columns()helper to parse filter expressions before CTE generationBefore:
WHERE bookings_cte.state IN (...)failed becausestatewasn't selected in CTEAfter:
statecolumn is automatically added to CTE when referenced by metric filtersTest
Added two regression tests:
test_metric_filter_column_not_in_query_dimensions- single filter column casetest_metric_filter_multiple_columns_not_in_dimensions- multiple filter columns