Skip to content

feat: RangeAgg and RangeIntersectAgg over a sequence of RangeSet - #192

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
feat/multirange-aggregates
Oct 18, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
feat/multirange-aggregates

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #93

Problem

PostgreSQL declares both aggregates twice: range_agg(anyrange) and range_agg(anymultirange), and range_intersect_agg(anyrange) and range_intersect_agg(anymultirange). The library had only the range-sourced overloads, so a sequence of RangeSet had nothing to call. ValueRangesAggregateMethodCallTranslator also keyed on the return type, and RangeAgg returns 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 of Intersect, or null for an empty source as the range form does. These are generic rather than one overload per range type, because RangeSet<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.
  • Translator: it reads the source type from the method's parameter and applies the multirange mapping to the selector when the source is sets. range_intersect_agg over a multirange returns the multirange mapping.
  • Docs: docs/ranges.md#aggregate-a-sequence-of-ranges says they take sets too, with an example. docs/efcore.md gets the example and the What runs where row. docs/architecture.md explains why these are generic.
  • Catalogues: claims R29, R30 and E47. Surface rows range_agg(anymultirange) and range_intersect_agg(anymultirange) are filled.
  • Changelogs: ### Added under 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 over SeatBlocks (int4multirange) and one over NodaBlockedDays (NodaTime datemultirange). Each sits next to the existing range_agg sweep.
  • A blind spot in the existing sweep, fixed here. Both sweeps listed the empty input first and folded the in-memory side in that order only. So a RangeIntersectAgg that 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, as range-intersect-agg-skips-later-empty-range.patch, alongside set-intersect-agg-skips-later-empty-set.patch. dotnet run tools/oracles.cs seeds intersect-agg reports CAUGHT for all three aggregate seeds, the existing intersect-agg-takes-the-first included.
  • Live probe on 17: range_intersect_agg over ('{}'), ('{[1,5]}') is {} in either order, and range_agg gives {[1,6)}.
  • RangeAggregateTests (core) and NodaTimeRangeSetTests hold the in-memory semantics. QueryTranslationTests and NodaQueryTranslationTests hold the translations.
  • The unit, NodaTime, EF, EF NodaTime, conventions and ASP.NET Core tests and the full integration suite (233) pass locally.

This PR is independent of #183 and #187. Shared lines in CHANGELOG.md and test/oracles/*.json may need merging by keeping both sides.

🤖 Generated with Claude Code

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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request area/range-set RangeSet and multirange algebra package/nodatime Affects CodoMetis.ValueRanges.NodaTime package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/core Affects CodoMetis.ValueRanges labels Oct 18, 2026
# 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
@CaffeinatedCoder
CaffeinatedCoder merged commit 44e6c31 into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/multirange-aggregates branch October 18, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/range-set RangeSet and multirange algebra enhancement New feature or request package/core Affects CodoMetis.ValueRanges package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/nodatime Affects CodoMetis.ValueRanges.NodaTime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RangeAgg and RangeIntersectAgg over a sequence of RangeSet (range_agg / range_intersect_agg on multiranges)

1 participant