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