use of com.linkedin.thirdeye.api.TimeSpec in project pinot by linkedin.
the class AnomaliesResource method getFormattedDateTime.
/**
* Get formatted date time for anomaly chart
* @param timestamp
* @param datasetConfig
* @param startEndDateFormatterHours
* @param startEndDateFormatterDays
* @return
*/
private String getFormattedDateTime(long timestamp, DatasetConfigDTO datasetConfig, DateTimeFormatter startEndDateFormatterHours, DateTimeFormatter startEndDateFormatterDays) {
TimeSpec timeSpec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
TimeUnit dataGranularityUnit = timeSpec.getDataGranularity().getUnit();
String formattedDateTime = null;
if (dataGranularityUnit.equals(TimeUnit.MINUTES) || dataGranularityUnit.equals(TimeUnit.HOURS)) {
formattedDateTime = startEndDateFormatterHours.print(timestamp);
} else if (dataGranularityUnit.equals(TimeUnit.DAYS)) {
formattedDateTime = startEndDateFormatterDays.print(timestamp);
}
return formattedDateTime;
}
use of com.linkedin.thirdeye.api.TimeSpec in project pinot by linkedin.
the class TabularViewHandler method generateTimeOnTimeComparisonRequest.
private TimeOnTimeComparisonRequest generateTimeOnTimeComparisonRequest(TabularViewRequest request) throws Exception {
TimeOnTimeComparisonRequest comparisonRequest = new TimeOnTimeComparisonRequest();
String collection = request.getCollection();
DateTime baselineStart = request.getBaselineStart();
DateTime baselineEnd = request.getBaselineEnd();
DateTime currentStart = request.getCurrentStart();
DateTime currentEnd = request.getCurrentEnd();
DatasetConfigDTO datasetConfig = CACHE_REGISTRY.getDatasetConfigCache().get(collection);
TimeSpec timespec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
if (!request.getTimeGranularity().getUnit().equals(TimeUnit.DAYS) || !StringUtils.isBlank(timespec.getFormat())) {
comparisonRequest.setEndDateInclusive(true);
}
Multimap<String, String> filters = request.getFilters();
List<MetricExpression> metricExpressions = request.getMetricExpressions();
comparisonRequest.setCollectionName(collection);
comparisonRequest.setBaselineStart(baselineStart);
comparisonRequest.setBaselineEnd(baselineEnd);
comparisonRequest.setCurrentStart(currentStart);
comparisonRequest.setCurrentEnd(currentEnd);
comparisonRequest.setFilterSet(filters);
comparisonRequest.setMetricExpressions(metricExpressions);
comparisonRequest.setAggregationTimeGranularity(request.getTimeGranularity());
return comparisonRequest;
}
use of com.linkedin.thirdeye.api.TimeSpec in project pinot by linkedin.
the class ThirdEyeUtils method createSchema.
public static Schema createSchema(CollectionSchema collectionSchema) {
Schema schema = new Schema();
for (DimensionSpec dimensionSpec : collectionSchema.getDimensions()) {
FieldSpec fieldSpec = new DimensionFieldSpec();
String dimensionName = dimensionSpec.getName();
fieldSpec.setName(dimensionName);
fieldSpec.setDataType(DataType.STRING);
fieldSpec.setSingleValueField(true);
schema.addField(dimensionName, fieldSpec);
}
for (MetricSpec metricSpec : collectionSchema.getMetrics()) {
FieldSpec fieldSpec = new MetricFieldSpec();
String metricName = metricSpec.getName();
fieldSpec.setName(metricName);
fieldSpec.setDataType(DataType.valueOf(metricSpec.getType().toString()));
fieldSpec.setSingleValueField(true);
schema.addField(metricName, fieldSpec);
}
TimeSpec timeSpec = collectionSchema.getTime();
String timeFormat = timeSpec.getFormat().equals("sinceEpoch") ? TimeFormat.EPOCH.toString() : TimeFormat.SIMPLE_DATE_FORMAT.toString() + ":" + timeSpec.getFormat();
TimeGranularitySpec incoming = new TimeGranularitySpec(DataType.LONG, timeSpec.getDataGranularity().getSize(), timeSpec.getDataGranularity().getUnit(), timeFormat, timeSpec.getColumnName());
TimeGranularitySpec outgoing = new TimeGranularitySpec(DataType.LONG, timeSpec.getDataGranularity().getSize(), timeSpec.getDataGranularity().getUnit(), timeFormat, timeSpec.getColumnName());
schema.addField(timeSpec.getColumnName(), new TimeFieldSpec(incoming, outgoing));
schema.setSchemaName(collectionSchema.getCollection());
return schema;
}
use of com.linkedin.thirdeye.api.TimeSpec in project pinot by linkedin.
the class DataCompletenessTaskUtilsTest method testGetDateTimeFormatterForDataset.
@Test
public void testGetDateTimeFormatterForDataset() {
DateTimeZone zone = DateTimeZone.UTC;
long dateTimeInMS = new DateTime(2017, 01, 12, 15, 30, zone).getMillis();
String columnName = "Date";
// DAYS bucket
TimeGranularity timeGranularity = new TimeGranularity(1, TimeUnit.DAYS);
String timeFormat = TimeSpec.SINCE_EPOCH_FORMAT;
TimeSpec timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
DateTimeFormatter dateTimeFormatter = DataCompletenessTaskUtils.getDateTimeFormatterForDataset(timeSpec, zone);
Assert.assertEquals(dateTimeFormatter.print(dateTimeInMS), "20170112");
zone = DateTimeZone.forID("America/Los_Angeles");
long dateTimeInMS1 = new DateTime(2017, 01, 12, 05, 30, zone).getMillis();
// DAYS bucket
timeGranularity = new TimeGranularity(1, TimeUnit.DAYS);
timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
dateTimeFormatter = DataCompletenessTaskUtils.getDateTimeFormatterForDataset(timeSpec, zone);
Assert.assertEquals(dateTimeFormatter.print(dateTimeInMS1), "20170112");
// HOURS bucket
zone = DateTimeZone.UTC;
dateTimeInMS = new DateTime(2017, 01, 12, 15, 30, zone).getMillis();
timeGranularity = new TimeGranularity(1, TimeUnit.HOURS);
timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
dateTimeFormatter = DataCompletenessTaskUtils.getDateTimeFormatterForDataset(timeSpec, zone);
Assert.assertEquals(dateTimeFormatter.print(dateTimeInMS), "2017011215");
// MINUTES bucket
timeGranularity = new TimeGranularity(1, TimeUnit.MINUTES);
timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
dateTimeFormatter = DataCompletenessTaskUtils.getDateTimeFormatterForDataset(timeSpec, zone);
Assert.assertEquals(dateTimeFormatter.print(dateTimeInMS), "201701121530");
// DEFAULT bucket
timeGranularity = new TimeGranularity(1, TimeUnit.MILLISECONDS);
timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
dateTimeFormatter = DataCompletenessTaskUtils.getDateTimeFormatterForDataset(timeSpec, zone);
Assert.assertEquals(dateTimeFormatter.print(dateTimeInMS), "2017011215");
}
use of com.linkedin.thirdeye.api.TimeSpec in project pinot by linkedin.
the class ContributorViewHandler method generateTimeOnTimeComparisonRequest.
private TimeOnTimeComparisonRequest generateTimeOnTimeComparisonRequest(ContributorViewRequest request) throws Exception {
TimeOnTimeComparisonRequest comparisonRequest = new TimeOnTimeComparisonRequest();
String collection = request.getCollection();
DateTime baselineStart = request.getBaselineStart();
DateTime baselineEnd = request.getBaselineEnd();
DateTime currentStart = request.getCurrentStart();
DateTime currentEnd = request.getCurrentEnd();
DatasetConfigDTO datasetConfig = CACHE_REGISTRY.getDatasetConfigCache().get(collection);
TimeSpec timespec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
if (!request.getTimeGranularity().getUnit().equals(TimeUnit.DAYS) || !StringUtils.isBlank(timespec.getFormat())) {
comparisonRequest.setEndDateInclusive(true);
}
Multimap<String, String> filters = request.getFilters();
List<String> dimensionsToGroupBy = request.getGroupByDimensions();
if (dimensionsToGroupBy == null || dimensionsToGroupBy.isEmpty()) {
List<String> allDimensions = Utils.getDimensionsToGroupBy(collection, filters);
dimensionsToGroupBy = Lists.newArrayList(allDimensions.get(0));
}
List<MetricExpression> metricExpressions = request.getMetricExpressions();
comparisonRequest.setCollectionName(collection);
comparisonRequest.setBaselineStart(baselineStart);
comparisonRequest.setBaselineEnd(baselineEnd);
comparisonRequest.setCurrentStart(currentStart);
comparisonRequest.setCurrentEnd(currentEnd);
comparisonRequest.setFilterSet(filters);
comparisonRequest.setMetricExpressions(metricExpressions);
comparisonRequest.setAggregationTimeGranularity(request.getTimeGranularity());
comparisonRequest.setGroupByDimensions(dimensionsToGroupBy);
return comparisonRequest;
}
Aggregations