Skip to content

Commit

Permalink
fix date hardcoding in date aggregator (opensearch-project#17239) (op…
Browse files Browse the repository at this point in the history
…ensearch-project#17244)

(cherry picked from commit b82ed5a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent fb32cfb commit fd9a9d9
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DateHistogramAggregator extends BucketsAggregator implements SizedBucketAg
private boolean starTreeDateRoundingRequired = true;

private final FilterRewriteOptimizationContext filterRewriteOptimizationContext;
public final String STARTREE_TIMESTAMP_FIELD = "@timestamp";
public final String fieldName;

DateHistogramAggregator(
String name,
Expand Down Expand Up @@ -172,6 +172,9 @@ protected Function<Long, Long> bucketOrdProducer() {
}
};
filterRewriteOptimizationContext = new FilterRewriteOptimizationContext(bridge, parent, subAggregators.length, context);
this.fieldName = (valuesSource instanceof ValuesSource.Numeric.FieldData)
? ((ValuesSource.Numeric.FieldData) valuesSource).getIndexFieldName()
: null;
this.starTreeDateDimension = (context.getQueryShardContext().getStarTreeQueryContext() != null)
? fetchStarTreeCalendarUnit()
: null;
Expand Down Expand Up @@ -244,13 +247,13 @@ private String fetchStarTreeCalendarUnit() {
.next();
DateDimension starTreeDateDimension = (DateDimension) compositeMappedFieldType.getDimensions()
.stream()
.filter(dim -> dim.getField().equals(STARTREE_TIMESTAMP_FIELD))
.filter(dim -> dim.getField().equals(fieldName))
.findFirst() // Get the first matching time dimension
.orElseThrow(() -> new AssertionError(String.format(Locale.ROOT, "Date dimension '%s' not found", STARTREE_TIMESTAMP_FIELD)));
.orElseThrow(() -> new AssertionError(String.format(Locale.ROOT, "Date dimension '%s' not found", fieldName)));

DateTimeUnitAdapter dateTimeUnitRounding = new DateTimeUnitAdapter(this.rounding.unit());
DateTimeUnitRounding rounding = starTreeDateDimension.findClosestValidInterval(dateTimeUnitRounding);
String dimensionName = STARTREE_TIMESTAMP_FIELD + "_" + rounding.shortName();
String dimensionName = fieldName + "_" + rounding.shortName();
if (rounding.shortName().equals(this.rounding.unit().shortName())) {
this.starTreeDateRoundingRequired = false;
}
Expand Down

0 comments on commit fd9a9d9

Please sign in to comment.