Skip to content

fix: honor datetime_frequency_interval in datetime_frequency aggregation#1139

Merged
matthewhanson merged 7 commits into
mainfrom
fix/datetime-frequency-interval-1117
Jul 1, 2026
Merged

fix: honor datetime_frequency_interval in datetime_frequency aggregation#1139
matthewhanson merged 7 commits into
mainfrom
fix/datetime-frequency-interval-1117

Conversation

@matthewhanson

Copy link
Copy Markdown
Member

Summary

Fixes #1117. The datetime_frequency aggregation hardcoded calendar_interval: 'month' in ALL_AGGREGATIONS, so the datetime_frequency_interval parameter was silently ignored — every request returned monthly buckets.

Change

  • Add extractDatetimeFrequencyInterval in api-utils.ts — validates against minute/hour/day/week/month/quarter/year, defaults to month (so existing behavior is unchanged), and returns 400 on an invalid value.
  • Thread the interval through api.aggregatebackend.aggregate (mirroring the existing geo-grid precision params).
  • In database.ts, override the datetime_frequency date_histogram.calendar_interval with the requested interval (same override pattern the geo-grid aggregations already use).

Tests

  • datetime_frequency_interval=day yields day-aligned buckets (2015-02-19, 2015-03-23) instead of month-aligned (2015-02-01, 2015-03-01).
  • An invalid interval (fortnight) returns 400.

Verified: typecheck, lint, and the full test-api-get-aggregate suite (12 tests) pass.

Note: like the existing aggregate precision params, this parameter isn't enumerated in openapi.yaml, so I left the spec untouched for consistency.

Closes #1117

🤖 Generated with Claude Code

The `datetime_frequency` aggregation hardcoded `calendar_interval: 'month'`,
so the `datetime_frequency_interval` parameter was ignored and buckets were
always monthly (#1117).

Add `extractDatetimeFrequencyInterval` (validates minute/hour/day/week/
month/quarter/year, defaults to month) mirroring the geo-grid precision
params, thread it through `backend.aggregate`, and override the
date_histogram's `calendar_interval` accordingly. Invalid intervals now
return a 400. Default behavior (month) is unchanged.

Closes #1117.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes datetime_frequency aggregation so it honors the datetime_frequency_interval request parameter (previously hardcoded to monthly buckets), aligning behavior with the STAC aggregation extension expectations and OpenSearch date_histogram capabilities.

Changes:

  • Added extractDatetimeFrequencyInterval to validate/normalize the interval (defaulting to month, invalid values → 400).
  • Threaded the interval through the API → backend aggregate call chain.
  • Overrode the datetime_frequency date_histogram.calendar_interval in the OpenSearch query when requested.
  • Added system tests for valid (day) and invalid (fortnight) intervals, and documented the fix in the changelog.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/system/test-api-get-aggregate.ts Adds system tests verifying interval bucketing and invalid interval rejection.
src/lib/types.ts Extends API/backend types to carry the new interval parameter through the stack.
src/lib/database.ts Applies the requested calendar_interval to the datetime_frequency aggregation query.
src/lib/api.ts Extracts the interval from request params and passes it to the backend.
src/lib/api-utils.ts Adds interval validation/extraction helper and supported-interval list.
CHANGELOG.md Documents the behavioral fix and the 400 response for invalid intervals.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/database.ts Outdated
Comment on lines +1054 to +1062
// datetime_frequency honors the requested calendar interval (default month)
if (aggregations.includes('datetime_frequency')) {
searchParams.body.aggs['datetime_frequency'] = {
date_histogram: {
field: 'properties.datetime',
calendar_interval: datetimeFrequencyInterval
}
}
}
Per feedback: drop sub-daily (minute/hour) granularity — day is the
finest useful bucket here — and skip decade (no native OpenSearch
support). Supported: day, week, month, quarter, year.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@matthewhanson

Copy link
Copy Markdown
Member Author

Updated per feedback: supported intervals are now day, week, month, quarter, year — dropped sub-daily (minute/hour) and skipped decade (no native OpenSearch calendar_interval for it). Default remains month.

Per review: avoid duplicating the field name so it can't drift from
ALL_AGGREGATIONS.datetime_frequency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@matthewhanson matthewhanson mentioned this pull request Jun 20, 2026
7 tasks

@jkeifer jkeifer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but the CHANGELOG entry disagrees with the code in one key detail.

Comment thread CHANGELOG.md Outdated
Co-authored-by: Jarrett Keifer <jkeifer@users.noreply.github.com>
@matthewhanson matthewhanson enabled auto-merge July 1, 2026 19:23
@matthewhanson matthewhanson added this pull request to the merge queue Jul 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jul 1, 2026
@matthewhanson matthewhanson enabled auto-merge July 1, 2026 19:55
@matthewhanson matthewhanson added this pull request to the merge queue Jul 1, 2026
Merged via the queue into main with commit f03d772 Jul 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

datetime_frequency aggregation ignores datetime_frequency_interval (always buckets by month)

3 participants