Repository navigation
feat: RangeAgg and RangeIntersectAgg over a sequence of RangeSet - #192
Merged
Merged
Conversation
PostgreSQL declares range_agg and range_intersect_agg over anymultirange as well as anyrange. RangeAggregateExtensions gains RangeAgg<TRange, T> and RangeIntersectAgg<TRange, T> over IEnumerable<RangeSet<TRange, T>>: the union of every set, and the fold of Intersect (null for an empty source). They are generic because RangeSet names both type arguments, so they serve every range type, NodaTime included. The aggregate translator keyed on the return type, which is a set for RangeAgg either way; it now reads the source type from the method's parameter and applies the multirange mapping to the argument, and range_intersect_agg over a multirange returns the multirange mapping. RangeAggregateParityTests sweeps both over every subset of eight sets for an int4multirange and a NodaTime datemultirange column. The sweeps now fold the in-memory side in both orders: with the empty input always listed first, a fold that skipped an empty input reached later passed the range sweep unnoticed (seeded and shown). Seeds: set-intersect-agg-skips-later-empty-set, range-intersect-agg-skips-later-empty-range. Closes #93 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md # docs/efcore.md # src/CodoMetis.ValueRanges.EFCore.PostgreSQL/CHANGELOG.md # src/CodoMetis.ValueRanges.NodaTime/CHANGELOG.md # src/CodoMetis.ValueRanges/CHANGELOG.md # test/CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime.Tests/NodaQueryTranslationTests.cs # test/CodoMetis.ValueRanges.NodaTime.Tests/NodaTimeRangeSetTests.cs # test/oracles/claims.json
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 #93
Problem
PostgreSQL declares both aggregates twice:
range_agg(anyrange)andrange_agg(anymultirange), andrange_intersect_agg(anyrange)andrange_intersect_agg(anymultirange). The library had only the range-sourced overloads, so a sequence ofRangeSethad nothing to call.ValueRangesAggregateMethodCallTranslatoralso keyed on the return type, andRangeAggreturns a set whatever its source.Change
RangeAggregateExtensions:RangeAgg<TRange, T>(this IEnumerable<RangeSet<TRange, T>>)returns the union of every set.RangeIntersectAgg<TRange, T>(…)returns the fold ofIntersect, ornullfor an empty source as the range form does. These are generic rather than one overload per range type, becauseRangeSet<TRange, T>names both type arguments and C# can infer them. That differs from what the issue proposed. It gives every range type, the four NodaTime ones included, the same two members with no NodaTime-side copy, and no new type is ever missed. The range overloads stay per type because inference cannot work there.range_intersect_aggover a multirange returns the multirange mapping.docs/ranges.md#aggregate-a-sequence-of-rangessays they take sets too, with an example.docs/efcore.mdgets the example and the What runs where row.docs/architecture.mdexplains why these are generic.range_agg(anymultirange)andrange_intersect_agg(anymultirange)are filled.### Addedunder 10.0.0 in the root, core, NodaTime and EF Core changelogs.Tests
RangeAggregateParityTests(integration): two new sweeps over every non-empty subset of eight sets. They cover{},{(,)}, unbounded sets, and two-element sets that the other sets merge, intersect or leave apart. One runs overSeatBlocks(int4multirange) and one overNodaBlockedDays(NodaTimedatemultirange). Each sits next to the existingrange_aggsweep.RangeIntersectAggthat skipped an empty input reached after another passed the range sweep: I seeded it and it passed. Both aggregates ignore row order, so every sweep now folds both ways. The same seeded defect now fails the range sweep, asrange-intersect-agg-skips-later-empty-range.patch, alongsideset-intersect-agg-skips-later-empty-set.patch.dotnet run tools/oracles.cs seeds intersect-aggreportsCAUGHTfor all three aggregate seeds, the existingintersect-agg-takes-the-firstincluded.range_intersect_aggover('{}'), ('{[1,5]}')is{}in either order, andrange_agggives{[1,6)}.RangeAggregateTests(core) andNodaTimeRangeSetTestshold the in-memory semantics.QueryTranslationTestsandNodaQueryTranslationTestshold the translations.This PR is independent of #183 and #187. Shared lines in
CHANGELOG.mdandtest/oracles/*.jsonmay need merging by keeping both sides.🤖 Generated with Claude Code