Search in sources :

Example 1 with Cube

use of com.linkedin.thirdeye.client.diffsummary.Cube in project pinot by linkedin.

the class Summary method main.

public static void main(String[] argc) {
    String oFileName = "Cube.json";
    int answerSize = 10;
    boolean doOneSideError = true;
    int maxDimensionSize = 3;
    Cube cube = null;
    try {
        cube = Cube.fromJson(oFileName);
        System.out.println("Restored Cube:");
        System.out.println(cube);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    Summary summary = new Summary(cube);
    try {
        SummaryResponse response = summary.computeSummary(answerSize, doOneSideError, maxDimensionSize);
        System.out.print("JSon String: ");
        System.out.println(new ObjectMapper().writeValueAsString(response));
        System.out.println("Object String: ");
        System.out.println(response.toString());
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    summary.testCorrectnessOfWowValues();
}
Also used : Cube(com.linkedin.thirdeye.client.diffsummary.Cube) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Cube

use of com.linkedin.thirdeye.client.diffsummary.Cube in project pinot by linkedin.

the class SummaryResource method buildSummary.

@GET
@Path(value = "/summary/autoDimensionOrder")
@Produces(MediaType.APPLICATION_JSON)
public String buildSummary(@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("topDimensions") @DefaultValue(DEFAULT_TOP_DIMENSIONS) int topDimensions, @QueryParam("hierarchies") @DefaultValue(DEFAULT_HIERARCHIES) String hierarchiesPayload, @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)));
        Dimensions dimensions;
        if (groupByDimensions == null || groupByDimensions.length() == 0 || groupByDimensions.equals("undefined")) {
            dimensions = new Dimensions(Utils.getSchemaDimensionNames(collection));
        } else {
            dimensions = new Dimensions(Arrays.asList(groupByDimensions.trim().split(",")));
        }
        List<List<String>> hierarchies = OBJECT_MAPPER.readValue(hierarchiesPayload, new TypeReference<List<List<String>>>() {
        });
        Cube cube = new Cube();
        cube.buildWithAutoDimensionOrder(olapClient, dimensions, topDimensions, hierarchies);
        Summary summary = new Summary(cube);
        response = summary.computeSummary(summarySize, doOneSideError, topDimensions);
        response.setMetricName(metric);
    } catch (Exception e) {
        LOG.error("Exception while generating difference summary", e);
        response = SummaryResponse.buildNotAvailableResponse();
        response.setMetricName(metric);
    }
    return OBJECT_MAPPER.writeValueAsString(response);
}
Also used : OLAPDataBaseClient(com.linkedin.thirdeye.client.diffsummary.OLAPDataBaseClient) Dimensions(com.linkedin.thirdeye.client.diffsummary.Dimensions) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) SummaryResponse(com.linkedin.thirdeye.dashboard.views.diffsummary.SummaryResponse) Cube(com.linkedin.thirdeye.client.diffsummary.Cube) Summary(com.linkedin.thirdeye.dashboard.views.diffsummary.Summary) PinotThirdEyeSummaryClient(com.linkedin.thirdeye.client.diffsummary.PinotThirdEyeSummaryClient) List(java.util.List) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Cube

use of com.linkedin.thirdeye.client.diffsummary.Cube 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);
}
Also used : SummaryResponse(com.linkedin.thirdeye.dashboard.views.diffsummary.SummaryResponse) Cube(com.linkedin.thirdeye.client.diffsummary.Cube) OLAPDataBaseClient(com.linkedin.thirdeye.client.diffsummary.OLAPDataBaseClient) Dimensions(com.linkedin.thirdeye.client.diffsummary.Dimensions) Summary(com.linkedin.thirdeye.dashboard.views.diffsummary.Summary) PinotThirdEyeSummaryClient(com.linkedin.thirdeye.client.diffsummary.PinotThirdEyeSummaryClient) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Cube (com.linkedin.thirdeye.client.diffsummary.Cube)3 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)2 Dimensions (com.linkedin.thirdeye.client.diffsummary.Dimensions)2 OLAPDataBaseClient (com.linkedin.thirdeye.client.diffsummary.OLAPDataBaseClient)2 PinotThirdEyeSummaryClient (com.linkedin.thirdeye.client.diffsummary.PinotThirdEyeSummaryClient)2 Summary (com.linkedin.thirdeye.dashboard.views.diffsummary.Summary)2 SummaryResponse (com.linkedin.thirdeye.dashboard.views.diffsummary.SummaryResponse)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 List (java.util.List)1