-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Star tree] Add date field rounding support in star tree (#15249)
--------- Signed-off-by: Bharathwaj G <[email protected]> (cherry picked from commit 1e49aa8) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9950cba
commit 33404fe
Showing
27 changed files
with
1,710 additions
and
259 deletions.
There are no files selected for viewing
221 changes: 190 additions & 31 deletions
221
server/src/internalClusterTest/java/org/opensearch/index/mapper/StarTreeMapperIT.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
server/src/main/java/org/opensearch/index/compositeindex/datacube/DataCubeDateTimeUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.index.compositeindex.datacube; | ||
|
||
import org.opensearch.index.compositeindex.datacube.startree.utils.date.DateTimeUnitRounding; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static java.util.Collections.unmodifiableMap; | ||
|
||
/** | ||
* Enum representing the extended date time units supported for star tree index as part of index mapping. | ||
* The enum values are: | ||
* <ul> | ||
* <li>HALF_HOUR_OF_DAY: Represents half hour of day rounding</li> | ||
* <li>QUARTER_HOUR_OF_DAY: Represents quarter hour of day rounding</li> | ||
* </ul> | ||
* <p> | ||
* The enum also provides a static map of date field units to their corresponding ExtendedDateTimeUnit instances. | ||
* | ||
* @see org.opensearch.common.Rounding.DateTimeUnit for more information on the dateTimeUnit enum and rounding logic. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public enum DataCubeDateTimeUnit implements DateTimeUnitRounding { | ||
HALF_HOUR_OF_DAY("half-hour") { | ||
@Override | ||
public long roundFloor(long utcMillis) { | ||
return utcMillis - (utcMillis % TimeUnit.MINUTES.toMillis(30)); | ||
} | ||
}, | ||
QUARTER_HOUR_OF_DAY("quarter-hour") { | ||
@Override | ||
public long roundFloor(long utcMillis) { | ||
return utcMillis - (utcMillis % TimeUnit.MINUTES.toMillis(15)); | ||
} | ||
}; | ||
|
||
public static final Map<String, DataCubeDateTimeUnit> DATE_FIELD_UNITS; | ||
static { | ||
Map<String, DataCubeDateTimeUnit> dateFieldUnits = new HashMap<>(); | ||
dateFieldUnits.put("30m", DataCubeDateTimeUnit.HALF_HOUR_OF_DAY); | ||
dateFieldUnits.put("half-hour", DataCubeDateTimeUnit.HALF_HOUR_OF_DAY); | ||
dateFieldUnits.put("15m", DataCubeDateTimeUnit.QUARTER_HOUR_OF_DAY); | ||
dateFieldUnits.put("quarter-hour", DataCubeDateTimeUnit.QUARTER_HOUR_OF_DAY); | ||
DATE_FIELD_UNITS = unmodifiableMap(dateFieldUnits); | ||
} | ||
|
||
private final String shortName; | ||
|
||
DataCubeDateTimeUnit(String shortName) { | ||
this.shortName = shortName; | ||
} | ||
|
||
/** | ||
* This rounds down the supplied milliseconds since the epoch down to the next unit. In order to retain performance this method | ||
* should be as fast as possible and not try to convert dates to java-time objects if possible | ||
* | ||
* @param utcMillis the milliseconds since the epoch | ||
* @return the rounded down milliseconds since the epoch | ||
*/ | ||
@Override | ||
public abstract long roundFloor(long utcMillis); | ||
|
||
@Override | ||
public String shortName() { | ||
return shortName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.