Repository navigation
feat: translate the DateRange calendar factories over a column (#191) - #447
Merged
Merged
Conversation
DateRange.Month, Quarter, Year and IsoWeek failed translation in a Where when their argument was a column. They now run as SQL with memory's answers: daterange(<first day>, <last day>, '[]') The first and last periods of DateOnly are constants taken from memory's own factory and written through the date mapping, so they are -infinity and infinity as Npgsql binds DateOnly.MinValue and MaxValue (the days themselves with DisableDateTimeInfinityConversions). A date column at or past them takes them too, so date_trunc never sees an infinity. Otherwise date_trunc(unit, d::timestamp) and that plus '<n> <unit> -1 day'. Measured on PostgreSQL 16 and 18 first (#191): to_date(..., 'IYYY-IW') rolls week 53 of a 52-week year over, make_date accepts the years 10000 and -1, and the proposed [) form over date_trunc(infinity) is empty. So the integer forms use make_date with a guard for the year, IsoWeek counts from January 4 and checks the week against date_part('week', Dec 28), and every argument memory rejects raises: a message cast to the type it stands in for, which always holds an argument, since PostgreSQL folds a constant cast while planning, even in a CASE arm no row reaches. LocalDateRange and YearMonthRange stay in memory: a LocalDate at -infinity (-9998-01-01) and the years before 4713 BC have no PostgreSQL date, so the server would fail where memory answers. CalendarFactoryParityTests holds every condition on #408's parity list; CalendarFactoryExtremesTests the extremes with the infinity conversions off. translation-support.json classifies DateRange server, and the docs move the row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
Closed
This was referenced Oct 25, 2026
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.
Closes #191
The third addition of 10.3.0 (#408).
mainfirst, then cherry-picked intorelease/10.x.Problem
DateRange.Month,Quarter,YearandIsoWeekfailed translation in aWherewhen their argument was a column (DateRange.Month(b.Day)), and ran in memory in a finalSelect. The proposal on #191 (date_trunc,make_date, a[)constructor,to_date(…, 'IYYY-IW')) had three silent differences, measured on PostgreSQL 16.15 and 18.1 (measurements):to_date('2025-53', 'IYYY-IW')is2025-12-29: week 53 of a 52-week year rolls over to week 1 of the next year, where memory throws.make_date(10000, 1, 1)andmake_date(-1, 1, 1)succeed, whereDateRangethrows outside 1 to 9999.date_trunckeepsinfinity, so the[)range over a column holdingDateOnly.MaxValueorMinValueisempty, where memory gives[9999-12-01,9999-12-31]and[0001-01-01,0001-01-31]. Adateargument also resolves todate_trunc'stimestamptzoverload, which reads the session time zone.Change
ValueRangesMethodCallTranslatortranslates the eightDateRangeoverloads (date form and integer form of each factory). Its dispatch is by whole signature, and any other overload of those names throwsMissingArm:-infinityandinfinityas Npgsql bindsDateOnly.MinValue/MaxValue. WithNpgsql.DisableDateTimeInfinityConversionsset they are the days themselves. A column holding an infinity falls into one of these arms, sodate_truncnever sees it.[]over the first and last day, not[). PostgreSQL turns a finite]into), and aninfinity]stays as Npgsql writes it, so the result equals a stored range of the same period.make_date, which raises for a bad month and for year 0. A guard raises for any other year outside 1 to 9999.IsoWeek(weekYear, week)is the Monday on or before January 4 plus7 * (week - 1), and it raises for a week outside 1 todate_part('week', make_date(y, 12, 28)).to_dateis not used.invalid input syntax for type integer: "DateRange.Month: the year 10000 is outside 1 to 9999". Every message holds an argument. A fully constant cast is folded while planning, even inside aCASEarm no row reaches. The first version of the week-past-9999 raise did exactly that and failed every query.NullOverNullElement.LocalDateRangeandYearMonthRangestay in memory. ALocalDatecolumn at-infinitystands for -9998-01-01, and neither its month nor any year before 4713 BC has a PostgreSQL date. So the database would fail where memory returns a range. That cell can't match, so per Epic: 10.3.0 #408 the member stays in memory on those types. The reason is indocs/efcore.md#what-runs-where,translation-support.jsonandNodaCalendarFactoryClientSideTests.Docs:
docs/efcore.md#what-runs-wheremovesDateRange's forms to "Runs as SQL" and adds two "Good to know" bullets (claim E76). The in-memory row now names the NodaTime forms and gives their reason.docs/ranges.mdand the EF Core README follow.Inventory and claims:
translation-support.jsonmakes*Range.Month/Quarter/Year/IsoWeek(*clientwithDateRange: server, in place ofplannedTranslate the calendar factories when they read a column #191. Claim E46 is held on the NodaTime types now. Claim E76 is new.Changelogs:
### Addedunder[11.0.0-preview.1], in the root and EF Core changelogs.Tests
CalendarFactoryTranslationTests(no database): the SQL for the date form, the week-past-9999 raise, the integer form with its year guard and a NULL argument, and the week check (noto_date).CalendarFactoryParityTests(integration; registered as an oracle with the seedcalendar-last-period-ends-on-a-day-not-infinity.patch) covers Epic: 10.3.0 #408's parity list against memory over the loaded rows:DateOnly.MinValueandMaxValueare stored as-infinity/infinity. The integer forms cover years 1 and 9999 with their first and last month, quarter and week, plus 52- and 53-week years..Value, a missing outer-join child, and a constant beside a column argument.Where(== null),Where(!= null)and a finalSelect. Each of 16 predicates inWhere,Where(!)andSelect, throughCompositionRunner.Judge. The predicates areContainsof a column and of the extreme days, equality with a stored range,Overlaps,IsContainedBy, bounds, and compound&&/||.MaxValue, month 13, years 0, -1 and 10000, quarters 0 and 5). Each throwsArgumentOutOfRangeExceptionin memory and raises aPostgresExceptionin aSelectand aWhere.RangeExtensionsandRangeSetmembers, not a range type's static factories, so they don't reach these. That is why the parity test carries the list itself.CalendarFactoryExtremesTests(the infinity-disabled process): with the switch set, the first and last periods equal the stored ranges memory writes, as days rather than infinities.DeclaredNullabilityTestsnow includes the four factories over the nullable date column and their integer forms.date_trunc,make_dateanddate_partare checked againstpg_proc.DateRangearm removed, every parity call is "Untranslated", and the ordering and rejection tests fail too.infinity) fails parity on every row in 9999-12 and 9999. Equality with the stored range andContains(DateOnly.MaxValue)disagree, and the server's[9999-12-01,10000-01-01)doesn't load.dotnet run tools/oracles.cs seeds calendar: CAUGHT.TranslationSupportProbeTestspasses withDateRangeserverand the NodaTime typesclient.TranslatorDispatchSweepTestspasses.🤖 Generated with Claude Code