Repository navigation
feat: translate the bridges from a range set to a value set (#650) - #653
Merged
Merged
Conversation
…a value set (#650) ToInt32Set(), ToInt64Set(), ToDateSet(), ToLocalDateSet() and ToYearMonthSet() run in the database: ARRAY((SELECT x FROM unnest(ranges) AS r CROSS JOIN generate_series(...) AS x ORDER BY x)), built by the SQL guard after EF Core's alias pass, inside CASE WHEN ranges IS NULL THEN NULL. An unbounded range raises (memory's message cast to the element type), a date extreme is the sentinel Npgsql stores, a NodaTime range from -infinity raises, and with the infinity conversions off a stored infinity raises. Measured on PostgreSQL 16 and 18. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…without its sentinels (#650) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…650) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-value-set # Conflicts: # test/oracles/claims/docs-efcore.json
…tabase per type (#650) On CI the class failed with 53300 (too many clients) after creating a database per assertion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #650
Part of #407 (split into #650, #651, #652).
Problem
ToInt32Set(),ToInt64Set(),ToDateSet(),ToLocalDateSet()andToYearMonthSet()ran in memory only: a filter over them failed to translate, and a finalSelectloaded the range set. The other direction,ToRangeSet(), runs as SQL since #487.Change
ValueSetsMethodCallTranslator: the bridge class's other overloads go toTranslateValueBridge:CASE WHEN ranges IS NULL THEN NULL ELSE <placeholder>(ranges) END, the operand mapped as the declared range set, the result as the returned set; any other overload isMissingArm(Sweep the EF translators for name-only dispatch and default operand classification #295).ValueSetSqlGuard: builds the placeholder asARRAY((SELECT x FROM unnest(ranges) AS vrN(r) CROSS JOIN generate_series(first, last[, step]) AS vrM(x) ORDER BY x)), without theORDER BYwhere the consumer can't see order (the outermost projection, containment, null tests), as Translate value set Intersect, Except, Add and a canonical Union for the non-text families with composed SQL #478's expander does. Its null test reads the range set.NotSupportedException;generate_series(NULL, …)has no rows, so the first value is memory's message cast to the element type and raises (22P02 / 22007).infinity]lists memory's last date asinfinity, an exclusive one ends on 9999-12-30 (LowerBound(), UpperBound() and Clamp in a query read a date range another tool wrote with an exclusive infinite bound one day wider than memory loads it #489), and the same at-infinity; a finite first/last date another tool wrote maps to the sentinel too, withDISTINCTwhere both are there.-infinitylower bound raises (the days afterLocalDate.MinIsoValuehave no PostgreSQL date, so memory's answer can't be saved).YearMonthsteps by1 monthto itsCoarseUpperBound.docs/efcore.md#list-the-values-of-a-range-set-with-toint32set, the what-runs-where tables (doc and EF README),value-sets.md, a migration section for the finalSelect(labelledbreakinglike Translate ToRangeSet() from Int32Set, Int64Set, DateSet, LocalDateSet and YearMonthSet (split from #407) #487: an unbounded range now fails withPostgresExceptionwhere it threwNotSupportedException).translation-support.json:*ValueSetRangeExtensions.*isserver. Claims: E31 and E90 drop the "stays in memory" part; new E99. Fragmentchanges/650.md(Breaking).All SQL measured by hand on PostgreSQL 16 and 18 first (int, bigint, date with every infinity form, month, empty, unbounded).
Tests
ValueBridgeTranslationTests(core) andNodaRangeBridgeTranslationTests(NodaTime): the whole statement per family, multiset vs sorted form, NULL, the null test, nesting underToRangeSet().ValueBridgeParityTests(integration, registered as a differential oracle): every subset of four ranges per family incl. the domain ends; projected,==the stored memory value,Containsper bound and neighbour, nullable column,ExecuteUpdate; unbounded raises; NodaTime from-infinityraises; raw rows another tool wrote. Green locally on PG 16 and 18.RangeBridgeInfinityDisabledTests: the extremes as dates, and a storedinfinityraises.ClientSideOnlyTranslationTests,RangeBridgeTranslationTests.TheReverseConversion_IsNotTranslated, the NodaTime one, the projection case) failed with the change and are removed.value-bridge-drops-an-unbounded-range.patchandvalue-bridge-lists-the-extremes-as-dates.patch, each shown CAUGHT byValueBridgeParityTests.🤖 Generated with Claude Code