Exemple #1
0
 @Test
 public void testInnerSegmentPlanMakerForSelectionWithFilter() {
   BrokerRequest brokerRequest = getSelectionWithFilterBrokerRequest();
   PlanMaker instancePlanMaker = new InstancePlanMakerImplV2();
   PlanNode rootPlanNode = instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
   rootPlanNode.showTree("");
 }
  @Test
  public void testInnerSegmentPlanMakerForAggregationGroupByOperatorWithFilter() throws Exception {
    final BrokerRequest brokerRequest = getAggregationGroupByWithFilterBrokerRequest();
    final PlanMaker instancePlanMaker = new InstancePlanMakerImplV1();
    final PlanNode rootPlanNode =
        instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
    rootPlanNode.showTree("");
    final MAggregationGroupByOperator operator = (MAggregationGroupByOperator) rootPlanNode.run();
    final IntermediateResultsBlock resultBlock = (IntermediateResultsBlock) operator.nextBlock();
    LOGGER.debug("RunningTime : {}", resultBlock.getTimeUsedMs());
    LOGGER.debug("NumDocsScanned : {}", resultBlock.getNumDocsScanned());
    LOGGER.debug("TotalDocs : {}", resultBlock.getTotalRawDocs());
    LOGGER.debug("Result: {}", resultBlock.getAggregationGroupByResultDataTable());
    Assert.assertEquals(resultBlock.getNumDocsScanned(), 582);
    Assert.assertEquals(resultBlock.getTotalRawDocs(), 10001);

    final AggregationGroupByOperatorService aggregationGroupByOperatorService =
        new AggregationGroupByOperatorService(_aggregationInfos, brokerRequest.getGroupBy());

    final Map<ServerInstance, DataTable> instanceResponseMap =
        new HashMap<ServerInstance, DataTable>();
    instanceResponseMap.put(
        new ServerInstance("localhost:0000"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:1111"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:2222"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:3333"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:4444"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:5555"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:6666"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:7777"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:8888"), resultBlock.getAggregationGroupByResultDataTable());
    instanceResponseMap.put(
        new ServerInstance("localhost:9999"), resultBlock.getAggregationGroupByResultDataTable());
    final List<Map<String, Serializable>> reducedResults =
        aggregationGroupByOperatorService.reduceGroupByOperators(instanceResponseMap);

    final List<JSONObject> jsonResult =
        aggregationGroupByOperatorService.renderGroupByOperators(reducedResults);
    LOGGER.debug("Result: {}", jsonResult);
  }
Exemple #3
0
 @Test
 public void testInnerSegmentPlanMakerForSelectionNoFilter() {
   BrokerRequest brokerRequest = getSelectionNoFilterBrokerRequest();
   PlanMaker instancePlanMaker = new InstancePlanMakerImplV2();
   PlanNode rootPlanNode = instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
   rootPlanNode.showTree("");
   IntermediateResultsBlock resultBlock =
       (IntermediateResultsBlock) rootPlanNode.run().nextBlock();
   PriorityQueue<Serializable[]> retPriorityQueue =
       (PriorityQueue<Serializable[]>) resultBlock.getSelectionResult();
   while (!retPriorityQueue.isEmpty()) {
     Serializable[] row = retPriorityQueue.poll();
     LOGGER.debug(Arrays.toString(row));
     assertEquals(row[0], 9);
     assertEquals(row[1], 99);
   }
 }
  @Test
  public void testInnerSegmentPlanMakerForAggregationGroupByOperatorWithFilter() throws Exception {
    final BrokerRequest brokerRequest = getAggregationGroupByWithFilterBrokerRequest();
    final PlanMaker instancePlanMaker = new InstancePlanMakerImplV0();
    final PlanNode rootPlanNode =
        instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
    rootPlanNode.showTree("");
    // UAggregationGroupByOperator operator = (UAggregationGroupByOperator) rootPlanNode.run();
    final MAggregationGroupByOperator operator = (MAggregationGroupByOperator) rootPlanNode.run();
    final IntermediateResultsBlock resultBlock = (IntermediateResultsBlock) operator.nextBlock();
    LOGGER.info("RunningTime : {}", resultBlock.getTimeUsedMs());
    LOGGER.info("NumDocsScanned : {}", resultBlock.getNumDocsScanned());
    LOGGER.info("TotalDocs : {}", resultBlock.getTotalDocs());
    Assert.assertEquals(resultBlock.getNumDocsScanned(), 582);
    Assert.assertEquals(resultBlock.getTotalDocs(), 10001);

    logJsonResult(brokerRequest, resultBlock);
  }
Exemple #5
0
 @Test
 public void testInnerSegmentPlanMakerForAggregationNoFilter() {
   BrokerRequest brokerRequest = getAggregationNoFilterBrokerRequest();
   PlanMaker instancePlanMaker = new InstancePlanMakerImplV2();
   PlanNode rootPlanNode = instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
   rootPlanNode.showTree("");
   IntermediateResultsBlock resultBlock =
       (IntermediateResultsBlock) rootPlanNode.run().nextBlock();
   for (int i = 0; i < 7; i++) {
     LOGGER.debug(resultBlock.getAggregationResult().get(i).toString());
   }
   assertEquals(((Number) resultBlock.getAggregationResult().get(0)).longValue(), 2000001L);
   assertEquals(resultBlock.getAggregationResult().get(1), 2000001000000.0);
   assertEquals(resultBlock.getAggregationResult().get(2), 2000000.0);
   assertEquals(resultBlock.getAggregationResult().get(3), 0.0);
   assertEquals(
       Double.parseDouble(resultBlock.getAggregationResult().get(4).toString()), 1000000.0);
   assertEquals(((IntOpenHashSet) resultBlock.getAggregationResult().get(5)).size(), 10);
   assertEquals(((IntOpenHashSet) resultBlock.getAggregationResult().get(6)).size(), 100);
 }
Exemple #6
0
 @Test
 public void testInnerSegmentPlanMakerForSelectionNoFilterNoOrdering() {
   BrokerRequest brokerRequest = getSelectionNoFilterBrokerRequest();
   brokerRequest.getSelections().setSelectionSortSequence(null);
   PlanMaker instancePlanMaker = new InstancePlanMakerImplV2();
   PlanNode rootPlanNode = instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
   rootPlanNode.showTree("");
   // USelectionOperator operator = (USelectionOperator) rootPlanNode.run();
   MSelectionOnlyOperator operator = (MSelectionOnlyOperator) rootPlanNode.run();
   IntermediateResultsBlock resultBlock = (IntermediateResultsBlock) operator.nextBlock();
   ArrayList<Serializable[]> retList =
       (ArrayList<Serializable[]>) resultBlock.getSelectionResult();
   int i = 0;
   for (Serializable[] row : retList) {
     LOGGER.debug(Arrays.toString(row));
     assertEquals(row[0], (i % 10));
     assertEquals(row[1], i);
     assertEquals(row[2], i);
     i++;
   }
 }
Exemple #7
0
 @Test
 public void testInnerSegmentPlanMakerForAggregationGroupByWithFilter() {
   BrokerRequest brokerRequest = getAggregationGroupByWithFilterBrokerRequest();
   brokerRequest.getGroupBy().getColumns().clear();
   brokerRequest.getGroupBy().getColumns().add("dim0");
   brokerRequest.getGroupBy().getColumns().add("dim1");
   PlanMaker instancePlanMaker = new InstancePlanMakerImplV2();
   PlanNode rootPlanNode = instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
   rootPlanNode.showTree("");
   IntermediateResultsBlock resultBlock =
       (IntermediateResultsBlock) rootPlanNode.run().nextBlock();
   LOGGER.debug("RunningTime: {}", resultBlock.getTimeUsedMs());
   LOGGER.debug("NumDocsScanned: {}", resultBlock.getNumDocsScanned());
   LOGGER.debug("TotalDocs: {}", resultBlock.getTotalRawDocs());
   List<Map<String, Serializable>> combinedGroupByResult =
       resultBlock.getAggregationGroupByOperatorResult();
   for (int i = 0; i < combinedGroupByResult.size(); ++i) {
     LOGGER.debug("function: {}", brokerRequest.getAggregationsInfo().get(i));
     for (String keyString : combinedGroupByResult.get(i).keySet()) {
       LOGGER.debug(
           "grouped key: {}, value: {}", keyString, combinedGroupByResult.get(i).get(keyString));
     }
   }
 }
Exemple #8
0
  @Test
  public void testInnerSegmentPlanMakerForAggregationGroupByNoFilter() {
    BrokerRequest brokerRequest = getAggregationGroupByNoFilterBrokerRequest();
    PlanMaker instancePlanMaker = new InstancePlanMakerImplV2();
    PlanNode rootPlanNode = instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest);
    rootPlanNode.showTree("");
    IntermediateResultsBlock resultBlock =
        (IntermediateResultsBlock) rootPlanNode.run().nextBlock();
    LOGGER.debug("RunningTime: {}", resultBlock.getTimeUsedMs());
    LOGGER.debug("NumDocsScanned: {}", resultBlock.getNumDocsScanned());
    LOGGER.debug("TotalDocs: {}", resultBlock.getTotalRawDocs());
    List<Map<String, Serializable>> combinedGroupByResult =
        resultBlock.getAggregationGroupByOperatorResult();

    Map<String, Serializable> singleGroupByResult =
        combinedGroupByResult.get(COUNT_AGGREGATION_INDEX);
    for (String keyString : singleGroupByResult.keySet()) {
      if (keyString.equals("0")) {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        assertEquals(200001, ((Number) resultList).longValue());
      } else {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        assertEquals(200000, ((Number) resultList).longValue());
      }
    }

    singleGroupByResult = combinedGroupByResult.get(SUM_AGGREGATION_INDEX);
    for (String keyString : singleGroupByResult.keySet()) {
      if (keyString.equals("0")) {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        double expectedSumValue =
            ((Double.parseDouble(keyString) + 2000000 + Double.parseDouble(keyString)) * 200001)
                / 2;
        assertEquals(expectedSumValue, ((Double) resultList).doubleValue());
      } else {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        double expectedSumValue =
            (((Double.parseDouble(keyString) + 2000000) - 10) + Double.parseDouble(keyString))
                * 100000;
        assertEquals(expectedSumValue, ((Double) resultList).doubleValue());
      }
    }

    singleGroupByResult = combinedGroupByResult.get(MAX_AGGREGATION_INDEX);
    for (String keyString : singleGroupByResult.keySet()) {
      if (keyString.equals("0")) {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        assertEquals(2000000 + Double.parseDouble(keyString), ((Double) resultList).doubleValue());
      } else {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        assertEquals(
            (2000000 - 10) + Double.parseDouble(keyString), ((Double) resultList).doubleValue());
      }
    }

    singleGroupByResult = combinedGroupByResult.get(MIN_AGGREGATION_INDEX);
    for (String keyString : singleGroupByResult.keySet()) {
      if (keyString.equals("0")) {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        assertEquals(Double.parseDouble(keyString), ((Double) resultList).doubleValue());
      } else {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        assertEquals(Double.parseDouble(keyString), ((Double) resultList).doubleValue());
      }
    }

    singleGroupByResult = combinedGroupByResult.get(AVG_AGGREGATION_INDEX);
    for (String keyString : singleGroupByResult.keySet()) {
      if (keyString.equals("0")) {
        Serializable resultList = singleGroupByResult.get(keyString);

        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        double expectedAvgValue =
            ((Double.parseDouble(keyString) + 2000000 + Double.parseDouble(keyString)) * 200001)
                / 2
                / 200001;
        assertEquals(expectedAvgValue, Double.parseDouble((resultList.toString())));
      } else {
        Serializable resultList = singleGroupByResult.get(keyString);
        LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
        double expectedAvgValue =
            ((((Double.parseDouble(keyString) + 2000000) - 10) + Double.parseDouble(keyString))
                    * 100000)
                / 200000;
        assertEquals(expectedAvgValue, Double.parseDouble((resultList.toString())));
      }
    }

    singleGroupByResult = combinedGroupByResult.get(DISTINCT_DIM0_AGGREGATION_INDEX);
    for (String keyString : singleGroupByResult.keySet()) {
      Serializable resultList = singleGroupByResult.get(keyString);
      LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
      assertEquals(1, ((IntOpenHashSet) resultList).size());
    }

    singleGroupByResult = combinedGroupByResult.get(DISTINCT_DIM1_AGGREGATION_INDEX);
    for (String keyString : singleGroupByResult.keySet()) {
      Serializable resultList = singleGroupByResult.get(keyString);
      LOGGER.debug("grouped key: {}, value: {}", keyString, resultList);
      assertEquals(10, ((IntOpenHashSet) resultList).size());
    }
  }