public AggregationGroupByOperatorPlanNode(
     IndexSegment indexSegment,
     BrokerRequest query,
     AggregationGroupByImplementationType aggregationGroupByImplementationType) {
   _indexSegment = indexSegment;
   _brokerRequest = query;
   _aggregationGroupByImplementationType = aggregationGroupByImplementationType;
   _projectionPlanNode =
       new ProjectionPlanNode(
           _indexSegment,
           getAggregationGroupByRelatedColumns(),
           new DocIdSetPlanNode(_indexSegment, _brokerRequest));
   for (int i = 0; i < _brokerRequest.getAggregationsInfo().size(); ++i) {
     AggregationInfo aggregationInfo = _brokerRequest.getAggregationsInfo().get(i);
     AggregationFunctionUtils.ensureAggregationColumnsAreSingleValued(
         aggregationInfo, _indexSegment);
     boolean hasDictionary =
         AggregationFunctionUtils.isAggregationFunctionWithDictionary(
             aggregationInfo, _indexSegment);
     _aggregationFunctionGroupByPlanNodes.add(
         new AggregationFunctionGroupByPlanNode(
             aggregationInfo,
             _brokerRequest.getGroupBy(),
             _projectionPlanNode,
             _aggregationGroupByImplementationType,
             hasDictionary));
   }
 }
  private void logJsonResult(BrokerRequest brokerRequest, IntermediateResultsBlock resultBlock)
      throws Exception {
    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.info("Result: {}", jsonResult);
  }
 private String[] getAggregationGroupByRelatedColumns() {
   Set<String> aggregationGroupByRelatedColumns = new HashSet<String>();
   for (AggregationInfo aggregationInfo : _brokerRequest.getAggregationsInfo()) {
     if (aggregationInfo.getAggregationType().equalsIgnoreCase("count")) {
       continue;
     }
     String columns = aggregationInfo.getAggregationParams().get("column").trim();
     aggregationGroupByRelatedColumns.addAll(Arrays.asList(columns.split(",")));
   }
   aggregationGroupByRelatedColumns.addAll(_brokerRequest.getGroupBy().getColumns());
   return aggregationGroupByRelatedColumns.toArray(new String[0]);
 }
Exemple #4
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));
     }
   }
 }
  @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);
  }
 @Override
 public Operator run() {
   List<AggregationFunctionGroupByOperator> aggregationFunctionOperatorList =
       new ArrayList<AggregationFunctionGroupByOperator>();
   for (AggregationFunctionGroupByPlanNode aggregationFunctionGroupByPlanNode :
       _aggregationFunctionGroupByPlanNodes) {
     aggregationFunctionOperatorList.add(
         (AggregationFunctionGroupByOperator) aggregationFunctionGroupByPlanNode.run());
   }
   return new MAggregationGroupByOperator(
       _indexSegment,
       _brokerRequest.getAggregationsInfo(),
       _brokerRequest.getGroupBy(),
       _projectionPlanNode.run(),
       aggregationFunctionOperatorList);
 }