use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.
the class SummaryResource method buildSummaryManualDimensionOrder.
@GET
@Path(value = "/summary/manualDimensionOrder")
@Produces(MediaType.APPLICATION_JSON)
public String buildSummaryManualDimensionOrder(@QueryParam("dataset") String collection, @QueryParam("metric") String metric, @QueryParam("currentStart") Long currentStartInclusive, @QueryParam("currentEnd") Long currentEndExclusive, @QueryParam("baselineStart") Long baselineStartInclusive, @QueryParam("baselineEnd") Long baselineEndExclusive, @QueryParam("dimensions") String groupByDimensions, @QueryParam("summarySize") int summarySize, @QueryParam("oneSideError") @DefaultValue(DEFAULT_ONE_SIDE_ERROR) boolean doOneSideError, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone) throws Exception {
if (summarySize < 1)
summarySize = 1;
SummaryResponse response = null;
try {
List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metric, MetricAggFunction.SUM, collection);
OLAPDataBaseClient olapClient = new PinotThirdEyeSummaryClient(CACHE_REGISTRY_INSTANCE.getQueryCache());
olapClient.setCollection(collection);
olapClient.setMetricExpression(metricExpressions.get(0));
olapClient.setCurrentStartInclusive(new DateTime(currentStartInclusive, DateTimeZone.forID(timeZone)));
olapClient.setCurrentEndExclusive(new DateTime(currentEndExclusive, DateTimeZone.forID(timeZone)));
olapClient.setBaselineStartInclusive(new DateTime(baselineStartInclusive, DateTimeZone.forID(timeZone)));
olapClient.setBaselineEndExclusive(new DateTime(baselineEndExclusive, DateTimeZone.forID(timeZone)));
List<String> allDimensions;
if (groupByDimensions == null || groupByDimensions.length() == 0 || groupByDimensions.equals("undefined")) {
allDimensions = Utils.getSchemaDimensionNames(collection);
} else {
allDimensions = Arrays.asList(groupByDimensions.trim().split(","));
}
if (allDimensions.size() > Integer.parseInt(DEFAULT_TOP_DIMENSIONS)) {
allDimensions = allDimensions.subList(0, Integer.parseInt(DEFAULT_TOP_DIMENSIONS));
}
Dimensions dimensions = new Dimensions(allDimensions);
Cube cube = new Cube();
cube.buildWithManualDimensionOrder(olapClient, dimensions);
Summary summary = new Summary(cube);
response = summary.computeSummary(summarySize, doOneSideError);
response.setMetricName(metric);
} catch (Exception e) {
LOG.error("Exception while generating difference summary", e);
response = SummaryResponse.buildNotAvailableResponse();
}
return OBJECT_MAPPER.writeValueAsString(response);
}
use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.
the class DashboardResource method getTimeSeriesData.
@GET
@Path(value = "/data/timeseries")
@Produces(MediaType.APPLICATION_JSON)
public String getTimeSeriesData(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("currentStart") Long start, @QueryParam("currentEnd") Long end, @QueryParam("aggTimeGranularity") String aggTimeGranularity, @QueryParam("metrics") String metricsJson, @QueryParam("dimensions") String groupByDimensions) throws Exception {
TimeSeriesRequest request = new TimeSeriesRequest();
request.setCollectionName(collection);
// See {@link #getDashboardData} for the reason that the start and end time are stored in a
// DateTime object with data's timezone.
DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
request.setStart(new DateTime(start, timeZoneForCollection));
request.setEnd(new DateTime(end, timeZoneForCollection));
if (groupByDimensions != null && !groupByDimensions.isEmpty()) {
request.setGroupByDimensions(Arrays.asList(groupByDimensions.trim().split(",")));
}
if (filterJson != null && !filterJson.isEmpty()) {
filterJson = URLDecoder.decode(filterJson, "UTF-8");
request.setFilterSet(ThirdEyeUtils.convertToMultiMap(filterJson));
}
List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
request.setMetricExpressions(metricExpressions);
request.setAggregationTimeGranularity(Utils.getAggregationTimeGranularity(aggTimeGranularity, collection));
DatasetConfigDTO datasetConfig = CACHE_REGISTRY_INSTANCE.getDatasetConfigCache().get(collection);
TimeSpec timespec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
if (!request.getAggregationTimeGranularity().getUnit().equals(TimeUnit.DAYS) || !StringUtils.isBlank(timespec.getFormat())) {
request.setEndDateInclusive(true);
}
TimeSeriesHandler handler = new TimeSeriesHandler(queryCache);
String jsonResponse = "";
try {
TimeSeriesResponse response = handler.handle(request);
JSONObject timeseriesMap = new JSONObject();
JSONArray timeValueArray = new JSONArray();
TreeSet<String> keys = new TreeSet<>();
TreeSet<Long> times = new TreeSet<>();
for (int i = 0; i < response.getNumRows(); i++) {
TimeSeriesRow timeSeriesRow = response.getRow(i);
times.add(timeSeriesRow.getStart());
}
for (Long time : times) {
timeValueArray.put(time);
}
timeseriesMap.put("time", timeValueArray);
for (int i = 0; i < response.getNumRows(); i++) {
TimeSeriesRow timeSeriesRow = response.getRow(i);
for (TimeSeriesMetric metricTimeSeries : timeSeriesRow.getMetrics()) {
String key = metricTimeSeries.getMetricName();
if (timeSeriesRow.getDimensionNames() != null && timeSeriesRow.getDimensionNames().size() > 0) {
StringBuilder sb = new StringBuilder(key);
for (int idx = 0; idx < timeSeriesRow.getDimensionNames().size(); ++idx) {
sb.append("||").append(timeSeriesRow.getDimensionNames().get(idx));
sb.append("|").append(timeSeriesRow.getDimensionValues().get(idx));
}
key = sb.toString();
}
JSONArray valueArray;
if (!timeseriesMap.has(key)) {
valueArray = new JSONArray();
timeseriesMap.put(key, valueArray);
keys.add(key);
} else {
valueArray = timeseriesMap.getJSONArray(key);
}
valueArray.put(metricTimeSeries.getValue());
}
}
JSONObject summaryMap = new JSONObject();
summaryMap.put("currentStart", start);
summaryMap.put("currentEnd", end);
JSONObject jsonResponseObject = new JSONObject();
jsonResponseObject.put("timeSeriesData", timeseriesMap);
jsonResponseObject.put("keys", new JSONArray(keys));
jsonResponseObject.put("summary", summaryMap);
jsonResponse = jsonResponseObject.toString();
} catch (Exception e) {
throw e;
}
LOG.info("Response:{}", jsonResponse);
return jsonResponse;
}
use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.
the class DashboardResource method getHeatMap.
@GET
@Path(value = "/data/heatmap")
@Produces(MediaType.APPLICATION_JSON)
public String getHeatMap(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("baselineStart") Long baselineStart, @QueryParam("baselineEnd") Long baselineEnd, @QueryParam("currentStart") Long currentStart, @QueryParam("currentEnd") Long currentEnd, @QueryParam("compareMode") String compareMode, @QueryParam("metrics") String metricsJson) throws Exception {
HeatMapViewRequest request = new HeatMapViewRequest();
request.setCollection(collection);
List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
request.setMetricExpressions(metricExpressions);
long maxDataTime = collectionMaxDataTimeCache.get(collection);
if (currentEnd > maxDataTime) {
long delta = currentEnd - maxDataTime;
currentEnd = currentEnd - delta;
baselineEnd = baselineEnd - delta;
}
// See {@link #getDashboardData} for the reason that the start and end time are stored in a
// DateTime object with data's timezone.
DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
// filter
if (filterJson != null && !filterJson.isEmpty()) {
filterJson = URLDecoder.decode(filterJson, "UTF-8");
request.setFilters(ThirdEyeUtils.convertToMultiMap(filterJson));
}
HeatMapViewHandler handler = new HeatMapViewHandler(queryCache);
HeatMapViewResponse response;
String jsonResponse = null;
try {
response = handler.process(request);
jsonResponse = OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(response);
LOG.debug("Heatmap response {}", jsonResponse);
} catch (Exception e) {
LOG.error("Error generating heatmap response", e);
}
return jsonResponse;
}
use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.
the class DashboardResource method getContributorData.
@GET
@Path(value = "/data/contributor")
@Produces(MediaType.APPLICATION_JSON)
public String getContributorData(@QueryParam("dataset") String collection, @QueryParam("filters") String filterJson, @QueryParam("timeZone") @DefaultValue(DEFAULT_TIMEZONE_ID) String timeZone, @QueryParam("baselineStart") Long baselineStart, @QueryParam("baselineEnd") Long baselineEnd, @QueryParam("currentStart") Long currentStart, @QueryParam("currentEnd") Long currentEnd, @QueryParam("compareMode") String compareMode, @QueryParam("aggTimeGranularity") String aggTimeGranularity, @QueryParam("metrics") String metricsJson, @QueryParam("dimensions") String groupByDimensions) throws Exception {
ContributorViewRequest request = new ContributorViewRequest();
request.setCollection(collection);
List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricsJson, MetricAggFunction.SUM, collection);
request.setMetricExpressions(metricExpressions);
long maxDataTime = collectionMaxDataTimeCache.get(collection);
if (currentEnd > maxDataTime) {
long delta = currentEnd - maxDataTime;
currentEnd = currentEnd - delta;
baselineEnd = baselineEnd - delta;
}
// See {@link #getDashboardData} for the reason that the start and end time are stored in a
// DateTime object with data's timezone.
DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(collection);
request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
if (filterJson != null && !filterJson.isEmpty()) {
filterJson = URLDecoder.decode(filterJson, "UTF-8");
request.setFilters(ThirdEyeUtils.convertToMultiMap(filterJson));
}
request.setTimeGranularity(Utils.getAggregationTimeGranularity(aggTimeGranularity, collection));
if (groupByDimensions != null && !groupByDimensions.isEmpty()) {
request.setGroupByDimensions(Arrays.asList(groupByDimensions.trim().split(",")));
}
ContributorViewHandler handler = new ContributorViewHandler(queryCache);
String jsonResponse = null;
try {
ContributorViewResponse response = handler.process(request);
jsonResponse = OBJECT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT).writeValueAsString(response);
LOG.debug("Contributor response {}", jsonResponse);
} catch (Exception e) {
LOG.error("Exception while processing /data/tabular call", e);
}
return jsonResponse;
}
use of com.linkedin.thirdeye.client.MetricExpression in project pinot by linkedin.
the class ThirdEyeUtils method getMetricExpressionFromMetricConfig.
public static MetricExpression getMetricExpressionFromMetricConfig(MetricConfigDTO metricConfig) {
MetricExpression metricExpression = new MetricExpression();
metricExpression.setExpressionName(metricConfig.getName());
if (metricConfig.isDerived()) {
metricExpression.setExpression(metricConfig.getDerivedMetricExpression());
} else {
metricExpression.setExpression(MetricConfigBean.DERIVED_METRIC_ID_PREFIX + metricConfig.getId());
}
return metricExpression;
}
Aggregations