Skip to content

[IOTDB-17108] Support inclusive end time syntax [start, end] in GROUP BY clause#17180

Open
PDGGK wants to merge 1 commit intoapache:masterfrom
PDGGK:feature/support-inclusive-end-time-17108
Open

[IOTDB-17108] Support inclusive end time syntax [start, end] in GROUP BY clause#17180
PDGGK wants to merge 1 commit intoapache:masterfrom
PDGGK:feature/support-inclusive-end-time-17108

Conversation

@PDGGK
Copy link

@PDGGK PDGGK commented Feb 7, 2026

Summary

This PR adds support for double-closed interval [start, end] in GROUP BY time clause, complementing the existing half-open interval [start, end).

New Syntax

-- Inclusive end time (NEW)
SELECT count(s1) FROM root.test GROUP BY ([0, 100], 10ms)  -- includes timestamp 100

-- Exclusive end time (existing)
SELECT count(s1) FROM root.test GROUP BY ([0, 100), 10ms)  -- excludes timestamp 100

Changes

File Description
IoTDBSqlParser.g4 Add grammar rule for ] right bracket
GroupByTimeComponent.java Add rightClosed field
GroupByTimeParameter.java Add serialization support for rightClosed
ASTVisitor.java Parse right bracket type
AggregationUtil.java Pass rightClosed to factory
TimeRangeIteratorFactory.java Update signature (9 args)
AggrWindowIterator.java Override getFinalTimeRange() for inclusive end
PreAggrWindowIterator.java Override getFinalTimeRange() for inclusive end
PreAggrWindowWithNaturalMonthIterator.java Constructor update
GroupByTimeExpression.java Add fields and serialization
ExpressionFactory.java Normalize [start, end] to [start, end+1)
TimeRangeIteratorTest.java Fix test signatures for new factory

Test Plan

  • Unit tests pass (TimeRangeIteratorTest - 4 tests)
  • Code formatting verified (mvn spotless:check)
  • Integration tests (to be added if needed)

Compatibility

This is a backward-compatible change. The existing [start, end) syntax continues to work as before. The new [start, end] syntax is opt-in.

Fixes #17108

… BY clause

This commit adds support for double-closed interval [start, end] in GROUP BY
time clause, complementing the existing half-open interval [start, end).

Changes:
- Add grammar rule for [start, end] syntax in IoTDBSqlParser.g4
- Add rightClosed field to GroupByTimeComponent and GroupByTimeParameter
- Implement getFinalTimeRange() override in iterator classes to handle
  inclusive end time by preserving the right boundary
- Update TimeRangeIteratorFactory signature (9 args) with rightClosed param
- Update ExpressionFactory to normalize [start, end] to [start, end+1)
- Fix test signatures in TimeRangeIteratorTest for new factory signature

Usage:
  SELECT count(s1) FROM root.test GROUP BY ([0, 100], 10ms)  -- includes 100

Fixes apache#17108
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.

[Bug] Support inclusive end time syntax ] in GROUP BY clause IoTDB 2.0.5

1 participant