use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.
the class TestTimeRangeUtils method provideComputeTimeRanges.
@DataProvider(name = "computeTimeRanges")
public Object[][] provideComputeTimeRanges() {
DateTime now = DateTime.now();
DateTime yesterday = now.minusDays(1);
List<Object[]> entries = new ArrayList<>();
entries.add(new Object[] { null, yesterday, now, Collections.singletonList(Range.closedOpen(yesterday, now)) });
entries.add(new Object[] { new TimeGranularity(1, TimeUnit.DAYS), yesterday, now, Collections.singletonList(Range.closedOpen(yesterday, now)) });
entries.add(new Object[] { new TimeGranularity(6, TimeUnit.HOURS), yesterday, now, Arrays.asList(Range.closedOpen(yesterday, yesterday.plusHours(6)), Range.closedOpen(yesterday.plusHours(6), yesterday.plusHours(12)), Range.closedOpen(yesterday.plusHours(12), yesterday.plusHours(18)), Range.closedOpen(yesterday.plusHours(18), yesterday.plusHours(24))) });
return entries.toArray(new Object[entries.size()][]);
}
use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.
the class ThirdEyeUtils method getTimeSpecFromDatasetConfig.
public static TimeSpec getTimeSpecFromDatasetConfig(DatasetConfigDTO datasetConfig) {
String timeFormat = datasetConfig.getTimeFormat();
if (timeFormat.startsWith(TimeFormat.SIMPLE_DATE_FORMAT.toString())) {
timeFormat = getSDFPatternFromTimeFormat(timeFormat);
}
TimeSpec timespec = new TimeSpec(datasetConfig.getTimeColumn(), new TimeGranularity(datasetConfig.getTimeDuration(), datasetConfig.getTimeUnit()), timeFormat);
return timespec;
}
use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.
the class TestDetectionJobSchedulerUtils method testGetNewEntriesForDetectionSchedulerMinuteLevel.
@Test
public void testGetNewEntriesForDetectionSchedulerMinuteLevel() throws Exception {
DatasetConfigDTO datasetConfig = new DatasetConfigDTO();
datasetConfig.setTimeColumn("Date");
datasetConfig.setTimeUnit(TimeUnit.MINUTES);
datasetConfig.setTimeDuration(5);
DateTimeZone dateTimeZone = DateTimeZone.UTC;
AnomalyFunctionDTO anomalyFunction = new AnomalyFunctionDTO();
anomalyFunction.setFrequency(new TimeGranularity(15, TimeUnit.MINUTES));
DateTimeFormatter dateTimeFormatter = DetectionJobSchedulerUtils.getDateTimeFormatterForDataset(datasetConfig, dateTimeZone);
String currentDateTimeString = "201702140336";
String currentDateTimeStringRounded = "201702140330";
DateTime currentDateTime = minuteDateTimeFormatter.parseDateTime(currentDateTimeString);
DateTime currentDateTimeRounded = dateTimeFormatter.parseDateTime(currentDateTimeStringRounded);
DetectionStatusDTO lastEntryForFunction = null;
// null last entry
Map<String, Long> newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
Assert.assertEquals(newEntries.size(), 1);
Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));
// last entry same as current time
lastEntryForFunction = new DetectionStatusDTO();
lastEntryForFunction.setDateToCheckInSDF(currentDateTimeStringRounded);
lastEntryForFunction.setDateToCheckInMS(currentDateTimeRounded.getMillis());
newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
Assert.assertEquals(newEntries.size(), 0);
// last entry 15 MINUTES before current time
String lastEntryDateTimeString = "201702140315";
DateTime lastEntryDateTime = dateTimeFormatter.parseDateTime(lastEntryDateTimeString);
lastEntryForFunction = new DetectionStatusDTO();
lastEntryForFunction.setDateToCheckInSDF(lastEntryDateTimeString);
lastEntryForFunction.setDateToCheckInMS(lastEntryDateTime.getMillis());
newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
Assert.assertEquals(newEntries.size(), 1);
Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));
// last entry 45 MINUTES before current time
lastEntryDateTimeString = "201702140245";
lastEntryDateTime = dateTimeFormatter.parseDateTime(lastEntryDateTimeString);
lastEntryForFunction = new DetectionStatusDTO();
lastEntryForFunction.setDateToCheckInSDF(lastEntryDateTimeString);
lastEntryForFunction.setDateToCheckInMS(lastEntryDateTime.getMillis());
newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
Assert.assertEquals(newEntries.size(), 3);
Assert.assertNotNull(newEntries.get("201702140300"));
Assert.assertNotNull(newEntries.get("201702140315"));
Assert.assertNotNull(newEntries.get("201702140330"));
Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));
}
use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.
the class TimeSeriesHandler method handle.
public TimeSeriesResponse handle(TimeSeriesRequest timeSeriesRequest) throws Exception {
List<Range<DateTime>> timeranges = new ArrayList<>();
TimeGranularity aggregationTimeGranularity = timeSeriesRequest.getAggregationTimeGranularity();
// time ranges
DateTime start = timeSeriesRequest.getStart();
DateTime end = timeSeriesRequest.getEnd();
if (timeSeriesRequest.isEndDateInclusive()) {
// ThirdEyeRequest is exclusive endpoint, so increment by one bucket
end = end.plus(aggregationTimeGranularity.toMillis());
}
timeranges = TimeRangeUtils.computeTimeRanges(aggregationTimeGranularity, start, end);
// create request
ThirdEyeRequest request = createThirdEyeRequest("timeseries", timeSeriesRequest, start, end);
Future<ThirdEyeResponse> responseFuture = queryCache.getQueryResultAsync(request);
// 5 minutes timeout
ThirdEyeResponse response = responseFuture.get(5, TimeUnit.MINUTES);
TimeSeriesResponseParser timeSeriesResponseParser = new TimeSeriesResponseParser(response, timeranges, timeSeriesRequest.getAggregationTimeGranularity(), timeSeriesRequest.getGroupByDimensions());
List<TimeSeriesRow> rows = timeSeriesResponseParser.parseResponse();
// compute the derived metrics
computeDerivedMetrics(timeSeriesRequest, rows);
return new TimeSeriesResponse(rows);
}
use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.
the class Utils method resizeTimeGranularity.
/**
* Given a duration (in millis), a time granularity, and the target number of chunk to divide the
* duration, this method returns the time granularity that is able to divide the duration to a
* number of chunks that is fewer than or equals to the target number.
*
* For example, if the duration is 25 hours, time granularity is HOURS, and target number is 12,
* then the resized time granularity is 3_HOURS, which divide the duration to 9 chunks.
*
* @param duration the duration in milliseconds.
* @param timeGranularityString time granularity in String format.
* @param targetChunkNum the target number of chunks.
* @return the resized time granularity in order to divide the duration to the number of chunks
* that is smaller than or equals to the target chunk number.
*/
public static String resizeTimeGranularity(long duration, String timeGranularityString, int targetChunkNum) {
TimeGranularity timeGranularity = Utils.getTimeGranularityFromString(timeGranularityString);
long timeGranularityMillis = timeGranularity.toMillis();
long chunkNum = duration / timeGranularityMillis;
if (duration % timeGranularityMillis != 0) {
++chunkNum;
}
if (chunkNum > targetChunkNum) {
long targetIntervalDuration = (long) Math.ceil((double) duration / (double) targetChunkNum);
long unitTimeGranularityMillis = timeGranularity.getUnit().toMillis(1);
int size = (int) Math.ceil((double) targetIntervalDuration / (double) unitTimeGranularityMillis);
String newTimeGranularityString = size + "_" + timeGranularity.getUnit();
return newTimeGranularityString;
} else {
return timeGranularityString;
}
}
Aggregations