Skip to content

Filter metrics by coalesced output dimensions - #2755

Open
Miskho wants to merge 2 commits into
DataJunction:mainfrom
Miskho:codex/dj-fix-output-dimension-filters
Open

Miskho wants to merge 2 commits into
DataJunction:mainfrom
Miskho:codex/dj-fix-output-dimension-filters

Conversation

@Miskho

@Miskho Miskho commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

A day filter can discard valid rows when combining metrics from facts with different dates. This PR makes the final filter use the same coalesced day that appears in the output.

For example, the regression fixture has these daily inputs. A dash means there is no input row for that day.

day A: downloads B: visitors
2024-01-01 13 —
2024-01-02 — 1
2024-01-03 4 3

A FULL OUTER JOIN keeps the visitor-only day, with the output day taken from B:

A.day B.day Output day: COALESCE(A.day, B.day) Downloads Visitors
NULL 2024-01-02 2024-01-02 NULL 1

But the old final predicate could filter on A.day, which is NULL for this row. In simplified SQL:

-- Before: discards the visitor-only row
WHERE A.day = DATE '2024-01-02'

-- After: filters on the day actually projected in the result
WHERE COALESCE(A.day, B.day) = DATE '2024-01-02'
Filter Before After (expected)
day = 2024-01-02 No rows (2024-01-02, downloads = NULL, visitors = 1)

Resolve final dimension predicates against copies of the output projection expressions. Preserve missing metrics as NULL, filter pushdown, filter-only dimensions, metric HAVING, and the window stage's already-coalesced dimensions. Update the affected metric and cube SQL expectations.

This also handles a bare Boolean predicate such as enabled: when the column is the entire predicate, replace the predicate root directly so it uses the coalesced output value, just as enabled = TRUE does.

Test Plan

  • Current integration run with all three compiler fixes and Greptile follow-ups: 1,950 compiler, cube API, and SQL instrumentation tests passed; 14 expected failures, zero failures. Combined Ruff, format and mypy checks passed.
  • Current focused module: 81 passed, including 77 native DuckDB executions and four Spark/Trino rendering checks. Covers equality, BETWEEN, IN/NOT IN, bare Boolean/explicit TRUE/NOT/compound predicates, metric/group order, sparse dates, multiple facts, NULL keys, metric filters, and windows.
  • Follow-up filter/roled-join/window-lookback/SQL snapshot checks: 147 passed. The 16 new Boolean cases produced four bare-filter failures and 12 passing controls before the fix; all pass afterward. Repository hooks, including Ruff, formatting and mypy, passed.
  • Entire cube API module: 83 passed after correcting three SQL expectations.
  • Earlier full server/doctest run: 7,044 passed, 823 skipped, 26 expected failures, plus those three stale cube expectations. The cube rerun passed, and full-run plus appended coverage met the 100% statement/branch gate. Subsequent changes added a comment and eight test cases.
  • Changed-file hooks, Ruff, mypy, and 14 live authenticated HTTP/native DuckDB restart cases passed.

Local execution used Python 3.13 and DuckDB. Native Spark/Trino, other Python CI versions, and optional integration stacks were not run locally.

Deployment Plan

No schema migration. Final dimension filters use the same coalesced values as the projected result.

Companion compiler fixes, validated together: #2754 (cross-fact aggregation) and #2756 (CTE identity). These PRs share compiler files; later PRs may need rebasing after the first merge.

@netlify

netlify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

👷 Deploy request for thriving-cassata-78ae72 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit f4f9960

@Miskho
Miskho marked this pull request as ready for review November 26, 2026 09:14
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; the bare Boolean filter issue is fixed.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the bare Boolean filter issue is fixed.

Summary

Final dimension filters use copies of the expressions shown in the output, preserving rows supplied only by later facts in a FULL OUTER JOIN.

  • Filters on multi-fact metrics now use the displayed dimension value.

Reviews (2) · Last reviewed commit: "Rebind bare Boolean filters to coalesced..." · Reviewed by Greptile

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