Search in sources :

Example 11 with MetricFunction

use of com.linkedin.thirdeye.client.MetricFunction in project pinot by linkedin.

the class TimeSeriesTest method generateGroupByTimeRequest.

private static TimeSeriesRequest generateGroupByTimeRequest() {
    TimeSeriesRequest timeSeriesRequest = new TimeSeriesRequest();
    timeSeriesRequest.setCollectionName(THIRDEYE_ABOOK);
    timeSeriesRequest.setStart(START);
    timeSeriesRequest.setEnd(START.plusDays(1));
    List<MetricFunction> metricFunctions = new ArrayList<>();
    metricFunctions.add(DEFAULT_METRIC_FUNCTION);
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricFunctions);
    metricExpressions.add(SUBMIT_RATE_EXPRESSION);
    timeSeriesRequest.setMetricExpressions(metricExpressions);
    timeSeriesRequest.setAggregationTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS));
    return timeSeriesRequest;
}
Also used : MetricFunction(com.linkedin.thirdeye.client.MetricFunction) ArrayList(java.util.ArrayList) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) MetricExpression(com.linkedin.thirdeye.client.MetricExpression)

Example 12 with MetricFunction

use of com.linkedin.thirdeye.client.MetricFunction in project pinot by linkedin.

the class PinotThirdEyeClient method execute.

@Override
public PinotThirdEyeResponse execute(ThirdEyeRequest request) throws Exception {
    DatasetConfigDTO datasetConfig = CACHE_REGISTRY_INSTANCE.getDatasetConfigCache().get(request.getCollection());
    TimeSpec dataTimeSpec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
    List<MetricFunction> metricFunctions = request.getMetricFunctions();
    List<String> dimensionNames = datasetConfig.getDimensions();
    List<ResultSetGroup> resultSetGroups = new ArrayList<>();
    // By default, query only offline, unless dataset has been marked as realtime
    String tableName = ThirdEyeUtils.computeTableName(request.getCollection());
    if (datasetConfig.isMetricAsDimension()) {
        List<String> pqls = PqlUtils.getMetricAsDimensionPqls(request, dataTimeSpec, datasetConfig);
        for (String pql : pqls) {
            LOG.debug("PQL isMetricAsDimension : {}", pql);
            ResultSetGroup result = CACHE_REGISTRY_INSTANCE.getResultSetGroupCache().get(new PinotQuery(pql, tableName));
            resultSetGroups.add(result);
        }
    } else {
        String sql = PqlUtils.getPql(request, dataTimeSpec);
        LOG.debug("PQL: {}", sql);
        ResultSetGroup result = CACHE_REGISTRY_INSTANCE.getResultSetGroupCache().get(new PinotQuery(sql, tableName));
        resultSetGroups.add(result);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Result for: {} {}", sql, format(result));
        }
    }
    List<ResultSet> resultSets = getResultSets(resultSetGroups);
    List<String[]> resultRows = parseResultSets(request, resultSets, metricFunctions, dimensionNames, datasetConfig);
    PinotThirdEyeResponse resp = new PinotThirdEyeResponse(request, resultRows, dataTimeSpec);
    return resp;
}
Also used : ArrayList(java.util.ArrayList) ResultSetGroup(com.linkedin.pinot.client.ResultSetGroup) TimeSpec(com.linkedin.thirdeye.api.TimeSpec) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) MetricFunction(com.linkedin.thirdeye.client.MetricFunction) ResultSet(com.linkedin.pinot.client.ResultSet)

Example 13 with MetricFunction

use of com.linkedin.thirdeye.client.MetricFunction in project pinot by linkedin.

the class ThirdEyeRequestGenerator method generateRequest.

public static ThirdEyeRequest generateRequest(String name, TimeOnTimeComparisonRequest comparisonRequest, DateTime start, DateTime end, String groupByDimension, TimeGranularity aggTimeGranularity) {
    ThirdEyeRequestBuilder requestBuilder = new ThirdEyeRequestBuilder();
    // COMMON to ALL REQUESTS
    requestBuilder.setCollection(comparisonRequest.getCollectionName());
    requestBuilder.setFilterSet(comparisonRequest.getFilterSet());
    requestBuilder.setFilterClause(comparisonRequest.getFilterClause());
    List<MetricFunction> metricFunctionsFromExpressions = Utils.computeMetricFunctionsFromExpressions(comparisonRequest.getMetricExpressions());
    requestBuilder.setMetricFunctions(metricFunctionsFromExpressions);
    // REQUEST to get total value with out break down.
    requestBuilder.setStartTimeInclusive(start);
    requestBuilder.setEndTimeExclusive(end);
    if (groupByDimension != null) {
        requestBuilder.setGroupBy(groupByDimension);
    }
    if (aggTimeGranularity != null) {
        requestBuilder.setGroupByTimeGranularity(aggTimeGranularity);
    }
    ThirdEyeRequest request = requestBuilder.build(name);
    return request;
}
Also used : ThirdEyeRequestBuilder(com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder) MetricFunction(com.linkedin.thirdeye.client.MetricFunction) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest)

Example 14 with MetricFunction

use of com.linkedin.thirdeye.client.MetricFunction in project pinot by linkedin.

the class TimeOnTimeComparisonHandler method createThirdEyeRequest.

private static ThirdEyeRequest createThirdEyeRequest(String requestReference, TimeOnTimeComparisonRequest comparisonRequest, DateTime start, DateTime end) {
    ThirdEyeRequestBuilder requestBuilder = ThirdEyeRequest.newBuilder();
    requestBuilder.setCollection(comparisonRequest.getCollectionName());
    requestBuilder.setStartTimeInclusive(start);
    requestBuilder.setEndTimeExclusive(end);
    requestBuilder.setFilterSet(comparisonRequest.getFilterSet());
    requestBuilder.addGroupBy(comparisonRequest.getGroupByDimensions());
    requestBuilder.setGroupByTimeGranularity(comparisonRequest.getAggregationTimeGranularity());
    List<MetricExpression> metricExpressions = comparisonRequest.getMetricExpressions();
    List<MetricFunction> metricFunctionsFromExpressions = Utils.computeMetricFunctionsFromExpressions(metricExpressions);
    requestBuilder.setMetricFunctions(metricFunctionsFromExpressions);
    return requestBuilder.build(requestReference);
}
Also used : ThirdEyeRequestBuilder(com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder) MetricFunction(com.linkedin.thirdeye.client.MetricFunction) MetricExpression(com.linkedin.thirdeye.client.MetricExpression)

Example 15 with MetricFunction

use of com.linkedin.thirdeye.client.MetricFunction in project pinot by linkedin.

the class ThirdEyeUtils method getMetricThresholdsMap.

public static Map<String, Double> getMetricThresholdsMap(List<MetricFunction> metricFunctions) {
    Map<String, Double> metricThresholds = new HashMap<>();
    for (MetricFunction metricFunction : metricFunctions) {
        String derivedMetricExpression = metricFunction.getMetricName();
        String metricId = derivedMetricExpression.replaceAll(MetricConfigBean.DERIVED_METRIC_ID_PREFIX, "");
        MetricConfigDTO metricConfig = DAO_REGISTRY.getMetricConfigDAO().findById(Long.valueOf(metricId));
        metricThresholds.put(derivedMetricExpression, metricConfig.getRollupThreshold());
    }
    return metricThresholds;
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) HashMap(java.util.HashMap) MetricFunction(com.linkedin.thirdeye.client.MetricFunction)

Aggregations

MetricFunction (com.linkedin.thirdeye.client.MetricFunction)20 ArrayList (java.util.ArrayList)13 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)8 HashMap (java.util.HashMap)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 ThirdEyeRequestBuilder (com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder)4 DateTime (org.joda.time.DateTime)4 ThirdEyeRequest (com.linkedin.thirdeye.client.ThirdEyeRequest)3 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)3 HashSet (java.util.HashSet)3 Metric (com.linkedin.thirdeye.client.comparison.Row.Metric)2 TimeSeriesMetric (com.linkedin.thirdeye.client.timeseries.TimeSeriesRow.TimeSeriesMetric)2 Map (java.util.Map)2 Future (java.util.concurrent.Future)2 ResultSet (com.linkedin.pinot.client.ResultSet)1 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)1 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)1 ThirdEyeResponse (com.linkedin.thirdeye.client.ThirdEyeResponse)1 MetricDataset (com.linkedin.thirdeye.client.cache.MetricDataset)1 Row (com.linkedin.thirdeye.client.comparison.Row)1