Repository navigation
fix: RangeAgg and RangeIntersectAgg skip a null input, as range_agg does - #368
Merged
Merged
Conversation
…oes (#361) PostgreSQL's range_agg and range_intersect_agg skip a NULL row, and the docs call the two the in-memory versions of those aggregates. They didn't skip a null: RangeIntersectAgg folded it in as Intersect(null), which is empty for every shape but (,), where it throws, and RangeAgg handed it to RangeSet.From, which threw while sorting or built a set holding null. Over sets, a null set threw. Every per-type overload (nine in the core, four in the NodaTime package) and both set overloads now drop nulls before folding. A source of nothing but nulls is an empty source, which keeps the documented zero-rows difference for RangeAgg. The filter sits where each overload calls its fold, so the three aggregate seeds apply as they were; all three are still caught. Tests: a reflection sweep over every per-type overload, linked into the NodaTime tests; the set overloads; and RangeAggregateParityTests over a nullable range, multirange and NodaTime range column with the NULL row at every position, which fails on 116 results with the filter removed. That revert is kept as the seed aggregates-fold-a-null-input.patch. Claim R48 quotes the new docs/ranges.md bullet. Found-By: US Defect-Class: ALG Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #361
Problem
docs/ranges.md#aggregate-a-sequence-of-rangescallsRangeAgg()andRangeIntersectAgg()"the in-memory versions of PostgreSQL'srange_aggandrange_intersect_agg". Those skip a NULL row; the in-memory versions didn't skip anull:RangeIntersectAgg()over ranges folded anullin asIntersect(null). That isemptyfor every shape but(,), where it throwsNullReferenceException; measured for the core and the NodaTime types alike. So[[1,10], [5,25], null]returnedempty, silently, whererange_intersect_aggreturns[5,10].RangeAgg()over ranges handed thenulltoRangeSet.From. That threwInvalidOperationExceptionwhile sorting two or more inputs, or built a set holdingnull(Count1,IsEmpty()false) from[null]alone.nullset madeRangeAgg()throwNullReferenceException, andRangeIntersectAgg()too when it came after another set.A consumer meets this when aggregating the loaded values of a nullable column or property in memory: a test double, a cache, or a grid that filters on the client.
Change
RangeAggregateExtensionsandNodaTimeRangeAggregateExtensions: every per-type overload (nine in the core, four in the NodaTime package) and both set overloads drop nulls before folding, through a privateWithoutNulls(OfType<TItem>()). A source of nothing but nulls is an empty source. SoRangeIntersectAgg()answersnull, as the server does, andRangeAgg()answers the empty set, which is the zero-rows difference E07 already documents. The XML docs say so.IntersectSetsCorewith its text unchanged, so their context lines are byte-identical.docs/ranges.md: "Anullrange is skipped, as PostgreSQL skips aNULLrow…", plus "Anullset is skipped." for sets. Claim R48 quotes the first.docs/migration.md: a bullet and a subsection under## Migration from v10.x, with the measured before/after table.Ranges:line under### Breakingin[11.0.0-preview.1], since a silent fix into a major's preview goes there. The 10.x port is 10.x: RangeIntersectAgg returns empty over a sequence holding a null range, where range_intersect_agg skips the NULL; RangeAgg throws (port of #361) #363, under### Changed answersin 10.2.0.Tests
Local, SDK
11.0.100-rc.2.26504.105, Docker (OrbStack).AggregateNullInputs(new, in the core tests, linked into the NodaTime tests): a reflection sweep over every per-typeRangeAgg/RangeIntersectAggoverload. It feeds each one[null],[(,), null],[null, (,)]and[(,), null, empty], and compares with the same input without the null. Held byRangeAggregateTests.EveryRangeOverload_SkipsANullRangeWhereverItStands(18 overloads at least) andNodaTimeRangeAggregateTests(8 at least).RangeAggregateTests.TheSetOverloads_SkipANullSetWhereverItStands: the null at each of three positions, and a source of only nulls.RangeAggregateParityTests.Aggregates_OverANullableColumn_SkipTheNullRows: a database of its own with a nullableInt32Range,RangeSet<Int32Range, int>andLocalDateRangecolumn. It has one group per subset of a four-input universe, each with a NULL row added, and asserts the SQL holdsrange_agg(/range_intersect_agg(. The in-memory fold runs with the null at every position against the server's answer. The all-NULL group is checked as the documented zero-rows case.WithoutNullsreturning its input): all four new tests fail. The integration test fails on 116 results, the reflection sweeps on every overload. That revert is kept astest/oracles/seeds/aggregates-fold-a-null-input.patch, anddotnet run tools/oracles.cs seeds fold-a-nullreports it caught.dotnet run tools/oracles.cs seeds intersect-agg: the three existing aggregate seeds still apply and are all caught.postgres:16-alpine: all eight projects pass (core 1399, NodaTime 239, EF 293, EF NodaTime 83, ASP.NET Core 92, conventions 407, integration 287, infinity-disabled 4).🤖 Generated with Claude Code