Skip to content

Commit e7de8d2

Browse files
author
Anand Kumar Shaw
committed
[Star Tree] Add date dimension support for range aggregation validation
This change extends the star-tree range aggregation validation to support DateDimension in addition to NumericDimension. Previously, range aggregations with star-tree optimization only worked with numeric fields. Now date fields can also leverage star-tree indexes for range aggregations. Signed-off-by: Anand Kumar Shaw <anandkrshawheritage@gmail.com>
1 parent 3e747cb commit e7de8d2

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
- Add a dynamic setting to change skip_cache_factor and min_frequency for querycache ([#18351](https://github.com/opensearch-project/OpenSearch/issues/18351))
1616
- Add overload constructor for Translog to accept Channel Factory as a parameter ([#18918](https://github.com/opensearch-project/OpenSearch/pull/18918))
1717
- Add subdirectory-aware store module with recovery support ([#19132](https://github.com/opensearch-project/OpenSearch/pull/19132))
18+
- [Star Tree] Add support for date type dimensions in range aggregation validation ([#20460](https://github.com/opensearch-project/OpenSearch/pull/20460))
1819

1920
### Changed
2021
- Add CompletionStage variants to methods in the Client Interface and default to ActionListener impl ([#18998](https://github.com/opensearch-project/OpenSearch/pull/18998))

server/src/main/java/org/opensearch/search/startree/StarTreeQueryContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ private static boolean validateRangeAggregationSupport(
176176
return false;
177177
}
178178

179-
// Validate request field is part of dimensions & is a numeric field
180-
// TODO: Add support for date type ranges
179+
// Validate request field is part of dimensions & is a numeric or date field
181180
if (compositeIndexFieldInfo.getDimensions()
182181
.stream()
183182
.noneMatch(
184-
dimension -> rangeAggregatorFactory.getField().equals(dimension.getField()) && dimension instanceof NumericDimension
183+
dimension -> rangeAggregatorFactory.getField().equals(dimension.getField())
184+
&& (dimension instanceof NumericDimension || dimension instanceof DateDimension)
185185
)) {
186186
return false;
187187
}

server/src/test/java/org/opensearch/search/SearchServiceStarTreeTests.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,33 @@ public void testQueryParsingForRangeAggregations() throws IOException {
910910
sourceBuilder = new SearchSourceBuilder().size(0).query(baseQuery).aggregation(rangeAggregationBuilder);
911911
assertStarTreeContext(request, sourceBuilder, null, -1);
912912

913-
// Case 6: Range Aggregation on non-numeric field, should not use star tree
913+
// Case 6: Range Aggregation on date field with DateDimension in star-tree, should use star tree
914914
rangeAggregationBuilder = range("range").field(TIMESTAMP_FIELD).addRange(0, 100).subAggregation(maxAggNoSub);
915915
baseQuery = new MatchAllQueryBuilder();
916916
sourceBuilder = new SearchSourceBuilder().size(0).query(baseQuery).aggregation(rangeAggregationBuilder);
917-
assertStarTreeContext(request, sourceBuilder, null, -1);
917+
assertStarTreeContext(
918+
request,
919+
sourceBuilder,
920+
getStarTreeQueryContext(
921+
searchContext,
922+
starTreeFieldConfiguration,
923+
"startree1",
924+
-1,
925+
List.of(
926+
new DateDimension(
927+
TIMESTAMP_FIELD,
928+
List.of(new DateTimeUnitAdapter(Rounding.DateTimeUnit.MONTH_OF_YEAR)),
929+
DateFieldMapper.Resolution.MILLISECONDS
930+
),
931+
new OrdinalDimension(KEYWORD_FIELD)
932+
),
933+
List.of(new Metric(STATUS, List.of(MetricStat.SUM, MetricStat.MAX))),
934+
baseQuery,
935+
sourceBuilder,
936+
true
937+
),
938+
-1
939+
);
918940

919941
// Case 7: Valid range aggregation and valid metric aggregation, should use star tree & cache
920942
rangeAggregationBuilder = range("range").field(NUMERIC_FIELD).addRange(0, 100).subAggregation(maxAggNoSub);

0 commit comments

Comments
 (0)