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);
}
}
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;
}
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();
}
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));
}
}
}
}
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);
}
Aggregations