Repository navigation
feat: translate Clamp on every range type (#486) - #490
Merged
Merged
Conversation
Clamp ran as SQL only on Int32Range, Int64Range and DecimalRange, the three #406 measured. The same LEAST(GREATEST(...)) form, with the discrete step back, holds on the other ten types: ClampDomainParityTests measures each against memory over every range its factories build from points that include the element type's extremes, as a value column, a parameter and an inlined constant, exactly and in both orderings. One pairing stays in memory: a DateTime stored as timestamptz (Npgsql's default) against a DateTimeRange's tsrange. GREATEST and LEAST convert the range's bounds through the session's time zone; in a Europe/Berlin session [08:00,18:00) clamped 17:30Z to 17:00Z. Contains and the factories already fail on that pair, so Clamp now declines it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oracles (#486) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…omain tests run alone (#486) DeclaredNullabilityTests now records the GREATEST/LEAST Clamp emits on its DateRange column; they are not pg_proc functions and skip a NULL argument. The domain tests each seed a database of their own, so they run outside the parallel batch rather than adding a dozen pools to the server's limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 26, 2026
Closed
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 #486
Problem
Clampran as SQL only onInt32Range,Int64RangeandDecimalRange(#406). On the other ten range types it ran in memory: a filter or an ordering by the clamped value failed translation, and a projection loaded the rows. The reason given was verification, not a known disagreement.Change
ValueRangesMethodCallTranslator:Clamptranslates on every range type, with the sameLEAST(GREATEST(v, lower(x)), upper)form. The type list is gone, because the core plugin can't name the NodaTime types. In its place,EveryRangeType_HasAClampParityTestfails for any range type added later without a parity test.DateTimestored astimestamptz(Npgsql's default for aDateTimeproperty) against aDateTimeRange'stsrange.GREATESTandLEASTresolve totimestamptzthrough the session's time zone. In a Europe/Berlin session,[08:00,18:00)clamped 17:30Z to 17:00Z, where memory keeps 17:30.Containsand the range factories already fail on the server for that pair (operator does not exist), soClampnow declines it (MixesTimeZones): a filter fails translation, and a projection runs in memory.ranges.mdand the EF Core README. Changelogs: root, EF Core and EF Core NodaTime, under 11.0.0-preview.1.translation-support.jsonreclassifiesClampasserver. Claims E31 and E74 are updated, E83 is new (precision),ClampDomainParityTestsis registered, there's a new seedclamp-compares-a-timestamptz-value-through-the-session-zone, and the existing clamp seed now names both oracles.What was measured, not guessed:
±infinity. A range the plugin writes ending at the last date is storedinfinity], andinfinity - 1is stillinfinity, which memory reads back as the extreme. So clamping at the extreme agrees.YearMonthRange. It steps back one day, to the last day of its last month, which reads as that month.TimeOnly.MaxValue→23:59:59.999999), as any value sent to PostgreSQL does. This is documented, and pinned byClamp_ReturnsAnOperandAtTheStoresMicrosecond.Found along the way, filed separately:
LowerBound()andUpperBound()already disagree with memory.Clampreads the same bounds, so it shares that.Equals, so-0.0and0.0share one compiled query and the second reuses the first's literal. That's EF Core's, for any float constant. The test passes-0as a parameter instead, and says why.Tests
ClampDomainParityTests(integration, new). For each of the ten types, every range its factories build from points that include the extremes, crossed with every inclusiveness and every point as the value. Run as a value column, a parameter, an inlined constant and NULL range and value columns, throughCompositionRunner.Judge, compared exactly (sign of zero, offset) and in both orderings. Also: the mixed-zone pair in UTC, Europe/Berlin and America/Los_Angeles sessions, the precision rule, and the coverage check.ClampTranslationTests(no database): the SQL forDateRange,TimeRange,DateTimeRangeandDateTimeOffsetRange, and the mixed-zone refusal.ClientSideOnlyTranslationTestsnow uses the mixed-zone pair as its in-memoryClamp.DeclaredNullabilityTests:GREATEST/LEASTare conditional expressions rather thanpg_procfunctions, so they're treated as non-strict instead of failing the lookup.ClampParityTestsfail;dotnet run tools/oracles.cs seedscatches both clamp seeds.MSTest.Parallelize.Workers=4, because the shared container runs out of connections at full parallelism (53300), on cleanmaintoo (5 failures there).🤖 Generated with Claude Code