Skip to content

feat(functions-aggregate): support sum(interval)#23177

Open
SubhamSinghal wants to merge 2 commits into
apache:mainfrom
SubhamSinghal:sum-interval
Open

feat(functions-aggregate): support sum(interval)#23177
SubhamSinghal wants to merge 2 commits into
apache:mainfrom
SubhamSinghal:sum-interval

Conversation

@SubhamSinghal

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

PostgreSQL supports sum() over interval values via component-wise addition; DataFusion currently
only supports sum() on Duration, so a query like

SELECT sum(value) FROM (VALUES
  (interval '1 second'), (interval '1 year'), (interval '1 month')) t(value);

errors with No function matches the given name and argument types 'sum(Interval(MonthDayNano))'. The
most useful real-world case is summing time-series gaps / durations expressed as intervals, which the
issue filer calls out.

What changes are included in this PR?

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes — SUM(<Interval(YearMonth | DayTime | MonthDayNano)>) and SUM(DISTINCT ) are now valid;
previously they errored at planning time with No function matches. No change to existing behavior on
any other type. No public API changes.

A note for reviewers: the rendered output for (months=13, days=0, nanos=1e9) is 13 mons 1.000000000
secs rather than PostgreSQL's 1 years 1 mons 0 days 0 hours 0 mins 1.0 secs. The stored value is
identical; the difference is a display-formatter choice in DataFusion (it doesn't normalize 13 mons to
1 year 1 month). Keeping that out of scope here.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for aggregate functions on intervals

1 participant