use of com.linkedin.thirdeye.client.ThirdEyeResponse in project pinot by linkedin.
the class PinotThirdEyeSummaryClient method constructAggregatedValues.
/**
* @throws Exception Throws exceptions when no useful data is retrieved, i.e., time out, failed to connect
* to the backend database, no non-zero data returned from the database, etc.
*/
private List<List<Row>> constructAggregatedValues(Dimensions dimensions, List<ThirdEyeRequest> bulkRequests) throws Exception {
Map<ThirdEyeRequest, Future<ThirdEyeResponse>> queryResponses = queryCache.getQueryResultsAsync(bulkRequests);
List<List<Row>> res = new ArrayList<>();
for (int i = 0; i < bulkRequests.size(); ) {
ThirdEyeRequest baselineRequest = bulkRequests.get(i++);
ThirdEyeRequest currentRequest = bulkRequests.get(i++);
ThirdEyeResponse baselineResponses = queryResponses.get(baselineRequest).get(TIME_OUT_VALUE, TIME_OUT_UNIT);
ThirdEyeResponse currentResponses = queryResponses.get(currentRequest).get(TIME_OUT_VALUE, TIME_OUT_UNIT);
if (baselineResponses.getNumRows() == 0 || currentResponses.getNumRows() == 0) {
throw new Exception("Failed to retrieve results with this request: " + (baselineResponses.getNumRows() == 0 ? baselineRequest : currentRequest));
}
Map<List<String>, Row> rowTable = new HashMap<>();
buildMetricFunctionOrExpressionsRows(dimensions, baselineResponses, rowTable, true);
buildMetricFunctionOrExpressionsRows(dimensions, currentResponses, rowTable, false);
if (rowTable.size() == 0) {
throw new Exception("Failed to retrieve non-zero results with these requests: " + baselineRequest + ", " + currentRequest);
}
List<Row> rows = new ArrayList<>(rowTable.values());
res.add(rows);
}
return res;
}
use of com.linkedin.thirdeye.client.ThirdEyeResponse in project pinot by linkedin.
the class QueryCache method getQueryResultsAsyncAndWait.
public Map<ThirdEyeRequest, ThirdEyeResponse> getQueryResultsAsyncAndWait(final List<ThirdEyeRequest> requests, int timeoutSeconds) throws Exception {
Map<ThirdEyeRequest, ThirdEyeResponse> responseMap = new LinkedHashMap<>();
for (final ThirdEyeRequest request : requests) {
Future<ThirdEyeResponse> responseFuture = executorService.submit(new Callable<ThirdEyeResponse>() {
@Override
public ThirdEyeResponse call() throws Exception {
return getQueryResult(request);
}
});
responseMap.put(request, responseFuture.get(timeoutSeconds, TimeUnit.SECONDS));
}
return responseMap;
}
use of com.linkedin.thirdeye.client.ThirdEyeResponse in project pinot by linkedin.
the class QueryCache method getQueryResultsAsync.
public Map<ThirdEyeRequest, Future<ThirdEyeResponse>> getQueryResultsAsync(final List<ThirdEyeRequest> requests) throws Exception {
Map<ThirdEyeRequest, Future<ThirdEyeResponse>> responseFuturesMap = new LinkedHashMap<>();
for (final ThirdEyeRequest request : requests) {
Future<ThirdEyeResponse> responseFuture = executorService.submit(new Callable<ThirdEyeResponse>() {
@Override
public ThirdEyeResponse call() throws Exception {
return getQueryResult(request);
}
});
responseFuturesMap.put(request, responseFuture);
}
return responseFuturesMap;
}
use of com.linkedin.thirdeye.client.ThirdEyeResponse in project pinot by linkedin.
the class TimeOnTimeComparisonHandler method handle.
public TimeOnTimeComparisonResponse handle(TimeOnTimeComparisonRequest comparisonRequest) throws Exception {
ThirdEyeRequestBuilder builder = new ThirdEyeRequestBuilder();
builder.setCollection(comparisonRequest.getCollectionName());
List<Range<DateTime>> baselineTimeranges = new ArrayList<>();
List<Range<DateTime>> currentTimeranges = new ArrayList<>();
TimeGranularity aggregationTimeGranularity = comparisonRequest.getAggregationTimeGranularity();
// baseline time ranges
DateTime baselineStart = comparisonRequest.getBaselineStart();
DateTime baselineEnd = comparisonRequest.getBaselineEnd();
// current time ranges
DateTime currentStart = comparisonRequest.getCurrentStart();
DateTime currentEnd = comparisonRequest.getCurrentEnd();
if (comparisonRequest.isEndDateInclusive()) {
// ThirdEyeRequest is exclusive endpoint, so increment end by one bucket
currentEnd = TimeRangeUtils.increment(currentEnd, aggregationTimeGranularity);
baselineEnd = TimeRangeUtils.increment(baselineEnd, aggregationTimeGranularity);
}
baselineTimeranges = TimeRangeUtils.computeTimeRanges(aggregationTimeGranularity, baselineStart, baselineEnd);
currentTimeranges = TimeRangeUtils.computeTimeRanges(aggregationTimeGranularity, currentStart, currentEnd);
// create baseline request
ThirdEyeRequest baselineRequest = createThirdEyeRequest(BASELINE, comparisonRequest, baselineStart, baselineEnd);
// create current request
ThirdEyeRequest currentRequest = createThirdEyeRequest(CURRENT, comparisonRequest, currentStart, currentEnd);
List<ThirdEyeRequest> requests = new ArrayList<>();
requests.add(baselineRequest);
requests.add(currentRequest);
Map<ThirdEyeRequest, Future<ThirdEyeResponse>> futureResponseMap;
futureResponseMap = queryCache.getQueryResultsAsync(requests);
ThirdEyeResponse baselineResponse = null;
ThirdEyeResponse currentResponse = null;
for (Entry<ThirdEyeRequest, Future<ThirdEyeResponse>> entry : futureResponseMap.entrySet()) {
ThirdEyeRequest request = entry.getKey();
Future<ThirdEyeResponse> responseFuture = entry.getValue();
ThirdEyeResponse response = responseFuture.get(60000, TimeUnit.SECONDS);
if (BASELINE.equals(request.getRequestReference())) {
baselineResponse = response;
} else if (CURRENT.equals(request.getRequestReference())) {
currentResponse = response;
}
}
TimeOnTimeResponseParser timeOnTimeResponseParser = new TimeOnTimeResponseParser(baselineResponse, currentResponse, baselineTimeranges, currentTimeranges, comparisonRequest.getAggregationTimeGranularity(), comparisonRequest.getGroupByDimensions());
List<Row> rows = timeOnTimeResponseParser.parseResponse();
// compute the derived metrics
computeDerivedMetrics(comparisonRequest, rows);
return new TimeOnTimeComparisonResponse(rows);
}
use of com.linkedin.thirdeye.client.ThirdEyeResponse in project pinot by linkedin.
the class Utils method getFilters.
public static Map<String, List<String>> getFilters(QueryCache queryCache, String collection, String requestReference, List<String> dimensions, DateTime start, DateTime end) throws Exception {
MetricFunction metricFunction = new MetricFunction(MetricAggFunction.COUNT, "*");
List<ThirdEyeRequest> requests = generateRequests(collection, requestReference, metricFunction, dimensions, start, end);
Map<ThirdEyeRequest, Future<ThirdEyeResponse>> queryResultMap = queryCache.getQueryResultsAsync(requests);
Map<String, List<String>> result = new HashMap<>();
for (Map.Entry<ThirdEyeRequest, Future<ThirdEyeResponse>> entry : queryResultMap.entrySet()) {
ThirdEyeRequest request = entry.getKey();
String dimension = request.getGroupBy().get(0);
ThirdEyeResponse thirdEyeResponse = entry.getValue().get();
int n = thirdEyeResponse.getNumRowsFor(metricFunction);
List<String> values = new ArrayList<>();
for (int i = 0; i < n; i++) {
Map<String, String> row = thirdEyeResponse.getRow(metricFunction, i);
String dimensionValue = row.get(dimension);
values.add(dimensionValue);
}
result.put(dimension, values);
}
return result;
}
Aggregations