Search in sources :

Example 16 with MetricFunction

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

the class TimeSeriesResponseParser method addMetric.

/* Helper functions */
private void addMetric(ThirdEyeResponseRow row, TimeSeriesRow.Builder builder) {
    List<MetricFunction> metricFunctions = response.getMetricFunctions();
    for (int i = 0; i < metricFunctions.size(); i++) {
        MetricFunction metricFunction = metricFunctions.get(i);
        double value = 0;
        if (row != null) {
            value = row.getMetrics().get(i);
        }
        builder.addMetric(metricFunction.getMetricName(), value);
    }
}
Also used : MetricFunction(com.linkedin.thirdeye.client.MetricFunction)

Example 17 with MetricFunction

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

the class PqlUtils method getMetricAsDimensionPqls.

static List<String> getMetricAsDimensionPqls(String collection, List<MetricFunction> metricFunctions, DateTime startTime, DateTime endTimeExclusive, Multimap<String, String> filterSet, List<String> groupBy, TimeGranularity timeGranularity, TimeSpec dataTimeSpec, String metricValuesColumn, String metricNamesColumn) throws ExecutionException {
    List<String> metricAsDimensionPqls = new ArrayList<>();
    for (MetricFunction metricFunction : metricFunctions) {
        String metricAsDimensionPql = getMetricAsDimensionPql(collection, metricFunction, startTime, endTimeExclusive, filterSet, groupBy, timeGranularity, dataTimeSpec, metricValuesColumn, metricNamesColumn);
        metricAsDimensionPqls.add(metricAsDimensionPql);
    }
    return metricAsDimensionPqls;
}
Also used : MetricFunction(com.linkedin.thirdeye.client.MetricFunction) ArrayList(java.util.ArrayList)

Example 18 with MetricFunction

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

the class PqlUtils method getSelectionClause.

/**
   * SUM each metric over the current time bucket.
   */
static String getSelectionClause(List<MetricFunction> metricFunctions) {
    StringBuilder builder = new StringBuilder();
    String delim = "";
    for (MetricFunction function : metricFunctions) {
        builder.append(delim);
        String metricName = null;
        if (function.getMetricName().equals("*")) {
            metricName = "*";
        } else {
            String metricId = function.getMetricName().replaceAll(MetricConfigBean.DERIVED_METRIC_ID_PREFIX, "");
            MetricConfigDTO metricConfig = DAO_REGISTRY.getMetricConfigDAO().findById(Long.valueOf(metricId));
            metricName = metricConfig.getName();
        }
        builder.append(function.getFunctionName()).append("(").append(metricName).append(")");
        delim = ", ";
    }
    return builder.toString();
}
Also used : MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) MetricFunction(com.linkedin.thirdeye.client.MetricFunction)

Example 19 with MetricFunction

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

the class TimeSeriesHandler method computeDerivedMetrics.

private void computeDerivedMetrics(TimeSeriesRequest timeSeriesRequest, List<TimeSeriesRow> rows) throws Exception {
    // compute list of derived expressions
    List<MetricFunction> metricFunctionsFromExpressions = Utils.computeMetricFunctionsFromExpressions(timeSeriesRequest.getMetricExpressions());
    Set<String> metricNameSet = new HashSet<>();
    for (MetricFunction function : metricFunctionsFromExpressions) {
        metricNameSet.add(function.getMetricName());
    }
    List<MetricExpression> derivedMetricExpressions = new ArrayList<>();
    for (MetricExpression expression : timeSeriesRequest.getMetricExpressions()) {
        if (!metricNameSet.contains(expression.getExpressionName())) {
            derivedMetricExpressions.add(expression);
        }
    }
    // add metric expressions
    if (derivedMetricExpressions.size() > 0) {
        Map<String, Double> valueContext = new HashMap<>();
        for (TimeSeriesRow row : rows) {
            valueContext.clear();
            List<TimeSeriesMetric> metrics = row.getMetrics();
            // baseline value
            for (TimeSeriesMetric metric : metrics) {
                valueContext.put(metric.getMetricName(), metric.getValue());
            }
            for (MetricExpression expression : derivedMetricExpressions) {
                String derivedMetricExpression = expression.getExpression();
                double derivedMetricValue = MetricExpression.evaluateExpression(derivedMetricExpression, valueContext);
                if (Double.isInfinite(derivedMetricValue) || Double.isNaN(derivedMetricValue)) {
                    derivedMetricValue = 0;
                }
                row.getMetrics().add(new TimeSeriesMetric(expression.getExpressionName(), derivedMetricValue));
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) MetricFunction(com.linkedin.thirdeye.client.MetricFunction) TimeSeriesMetric(com.linkedin.thirdeye.client.timeseries.TimeSeriesRow.TimeSeriesMetric) HashSet(java.util.HashSet)

Example 20 with MetricFunction

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

the class TimeSeriesHandler method createThirdEyeRequest.

private static ThirdEyeRequest createThirdEyeRequest(String requestReference, TimeSeriesRequest timeSeriesRequest, DateTime start, DateTime end) {
    ThirdEyeRequestBuilder requestBuilder = ThirdEyeRequest.newBuilder();
    requestBuilder.setCollection(timeSeriesRequest.getCollectionName());
    requestBuilder.setStartTimeInclusive(start);
    requestBuilder.setEndTimeExclusive(end);
    requestBuilder.setFilterSet(timeSeriesRequest.getFilterSet());
    requestBuilder.addGroupBy(timeSeriesRequest.getGroupByDimensions());
    requestBuilder.setGroupByTimeGranularity(timeSeriesRequest.getAggregationTimeGranularity());
    List<MetricExpression> metricExpressions = timeSeriesRequest.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)

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