Search in sources :

Example 6 with TimeSpec

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;
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Example 7 with TimeSpec

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;
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) TimeOnTimeComparisonRequest(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Example 8 with TimeSpec

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;
}
Also used : DimensionSpec(com.linkedin.thirdeye.api.DimensionSpec) TimeGranularitySpec(com.linkedin.pinot.common.data.TimeGranularitySpec) Schema(com.linkedin.pinot.common.data.Schema) CollectionSchema(com.linkedin.thirdeye.api.CollectionSchema) MetricSpec(com.linkedin.thirdeye.api.MetricSpec) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) TimeFieldSpec(com.linkedin.pinot.common.data.TimeFieldSpec) FieldSpec(com.linkedin.pinot.common.data.FieldSpec) MetricFieldSpec(com.linkedin.pinot.common.data.MetricFieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec) DimensionFieldSpec(com.linkedin.pinot.common.data.DimensionFieldSpec) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Example 9 with TimeSpec

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");
}
Also used : TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) TimeSpec(com.linkedin.thirdeye.api.TimeSpec) Test(org.testng.annotations.Test)

Example 10 with TimeSpec

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;
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) TimeOnTimeComparisonRequest(com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Aggregations

TimeSpec (com.linkedin.thirdeye.api.TimeSpec)26 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)14 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)13 DateTime (org.joda.time.DateTime)11 DateTimeZone (org.joda.time.DateTimeZone)8 TimeUnit (java.util.concurrent.TimeUnit)6 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)6 ExecutionException (java.util.concurrent.ExecutionException)5 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)3 JSONException (org.json.JSONException)3 ResultSet (com.linkedin.pinot.client.ResultSet)2 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)2 TimeOnTimeComparisonRequest (com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest)2 TimeSeriesHandler (com.linkedin.thirdeye.client.timeseries.TimeSeriesHandler)2 TimeSeriesRequest (com.linkedin.thirdeye.client.timeseries.TimeSeriesRequest)2 TimeSeriesResponse (com.linkedin.thirdeye.client.timeseries.TimeSeriesResponse)2