Repository navigation
fix(core): use the range_calendar period for prior-period comparisons in filters=[] - #3351
Open
straw-hat-gupta wants to merge 2 commits into
Open
straw-hat-gupta wants to merge 2 commits into
straw-hat-gupta wants to merge 2 commits into
Conversation
A big_value or table comparison with compare_vs "prior period" or "prior year" that takes its period from a range_calendar in filters=[...] compares the current period with itself and reports 0% (evidence-dev#3335). On a table with a date dimension the same bug shows as missing prior values. The cases run the generated SQL on chdb against inline values() data, with real Filters (range_calendar, dropdown), and assert whole result rows. RangeCalendarFilter also gets unit cases for the range it lends to comparisons, including none for an open-ended range. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… in filters=[]
A big_value (or table) with comparison={ compare_vs="prior period" } and
its period coming from filters=["dates"] instead of date_range= reported
a flat 0.00%. The calendar's predicate was applied to the comparison CTE as
well, so the "prior" period was the current one again.
Comparisons with no date_range of their own now borrow the bounded period
of the first date filter in filters=[] (Filter.comparisonDateRange,
implemented by RangeCalendarFilter), and that filter's predicate is left
out of the comparison CTE so the shifted range selects the prior period.
Open-ended calendar ranges lend nothing. Other filters still apply to both
periods; an explicit date_range is untouched.
Fixes evidence-dev#3335
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@straw-hat-gupta is attempting to deploy a commit to the Evidence Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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 #3335
Summary
A
big_valueortablecomparison withcompare_vs="prior period"or"prior year"showed 0% when its period came from arange_calendarinfilters=[...]instead ofdate_range=. The comparison had nodate_rangeto shift, and the calendar's predicate was also applied to the comparison CTE, so the "prior" period was the current one again.A comparison without its own
date_rangenow borrows the period of the first date filter infilters=[...], and that filter's predicate is left out of the comparison CTE, so the shifted range selects the prior period. Other filters still apply to both periods.Changes
Filter.svelte.ts: newcomparisonDateRange(),undefinedby default.RangeCalendarFilter: returns the active period onvalue_column. It returns nothing for a range with no period to shift: open-ended (from ...) or unbounded "all time".sql-options.ts:borrowFilterDateRangesgives those comparisons the borroweddate_rangeand acteFilterSqlwithout the date filter.build-comparisons.ts: the comparison CTE and its grouping usecteFilterSqlwhen it is set.An explicit
date_rangeon the component still takes precedence and behaves as before. The main query and target/benchmark comparisons are unchanged.One assumption: the filter and the query resolve relative presets like "last 7 days" against the same anchor date. They do today, because both use
computedDefaultDateRangeEndor today (Query.maxDateQueryreturnsundefined). If max-date detection is re-enabled, the prior period could stop being adjacent to the current one.Not covered:
period_selectorwithvalue_columnhas the same 0%. It would lend fixed dates, which shift by day count (March would compare against Jan 29 - Feb 28) rather than by month or quarter, so it needs its own change. Happy to follow up.Testing
common/sql-options.filter-comparisons.test.tsruns the generated SQL on chdb with realrange_calendaranddropdownfilters. It covers prior period and prior year, other filters kept on both periods, an explicitdate_rangeleft alone, and tables with a region or daily date dimension. Calendar results matchdate_range=row for row.RangeCalendarFilter.svelte.test.ts: unit cases forcomparisonDateRange(), including an open-ended range.main(for example the prior value is 161, the current value, instead of 107). The explicitdate_rangecase passes on both.TZ=UTC pnpm test: core 4224 passed, cli 423 passed.pnpm check: 0 errors.pnpm cli:buildsucceeds.