Exemplo n.º 1
0
  private static List<Serializable> combineAggregationResults(
      BrokerRequest brokerRequest,
      List<Serializable> aggregationResult1,
      List<Serializable> aggregationResult2) {
    if (aggregationResult1 == null) {
      return aggregationResult2;
    }
    if (aggregationResult2 == null) {
      return aggregationResult1;
    }
    List<List<Serializable>> aggregationResultsList = new ArrayList<List<Serializable>>();

    for (int i = 0; i < brokerRequest.getAggregationsInfoSize(); ++i) {
      aggregationResultsList.add(new ArrayList<Serializable>());
      if (aggregationResult1.get(i) != null) {
        aggregationResultsList.get(i).add(aggregationResult1.get(i));
      }
      if (aggregationResult2.get(i) != null) {
        aggregationResultsList.get(i).add(aggregationResult2.get(i));
      }
    }

    List<Serializable> retAggregationResults = new ArrayList<Serializable>();
    List<AggregationFunction> aggregationFunctions =
        AggregationFunctionFactory.getAggregationFunction(brokerRequest);
    for (int i = 0; i < aggregationFunctions.size(); ++i) {
      retAggregationResults.add(
          (Serializable)
              aggregationFunctions
                  .get(i)
                  .combine(aggregationResultsList.get(i), CombineLevel.INSTANCE)
                  .get(0));
    }
    return retAggregationResults;
  }
Exemplo n.º 2
0
  private static Map<String, Serializable> mergeTwoGroupedResults(
      AggregationInfo aggregationInfo,
      Map<String, Serializable> map1,
      Map<String, Serializable> map2) {
    if (map1 == null) {
      return map2;
    }
    if (map2 == null) {
      return map1;
    }

    AggregationFunction aggregationFunction = AggregationFunctionFactory.get(aggregationInfo, true);
    for (String key : map2.keySet()) {
      if (map1.containsKey(key)) {
        map1.put(key, aggregationFunction.combineTwoValues(map1.get(key), map2.get(key)));
      } else {
        map1.put(key, map2.get(key));
      }
    }
    return map1;
  }
Exemplo n.º 3
0
  public static void mergeTwoBlocks(
      BrokerRequest brokerRequest,
      IntermediateResultsBlock mergedBlock,
      IntermediateResultsBlock blockToMerge) {
    // Sanity check
    if (blockToMerge == null) {
      return;
    }
    if (mergedBlock == null) {
      mergedBlock = blockToMerge;
      return;
    }
    // Combine NumDocsScanned
    mergedBlock.setNumDocsScanned(
        mergedBlock.getNumDocsScanned() + blockToMerge.getNumDocsScanned());
    // Combine TotalDocs
    mergedBlock.setTotalDocs(mergedBlock.getTotalDocs() + blockToMerge.getTotalDocs());
    // Debug mode enable : Combine SegmentStatistics and TraceInfo
    if (brokerRequest.isEnableTrace()) {
      mergedBlock.getSegmentStatistics().addAll(blockToMerge.getSegmentStatistics());
      mergedBlock.getTraceInfo().putAll(blockToMerge.getTraceInfo());
    }
    // Combine Exceptions
    mergedBlock.setExceptionsList(
        combineExceptions(mergedBlock.getExceptions(), blockToMerge.getExceptions()));

    if (brokerRequest.isSetAggregationsInfo()) {
      if (brokerRequest.isSetGroupBy()) {
        // Combine AggregationGroupBy
        mergedBlock.setAggregationGroupByResult1(
            combineAggregationGroupByResults1(
                brokerRequest,
                mergedBlock.getAggregationGroupByOperatorResult(),
                blockToMerge.getAggregationGroupByOperatorResult()));
      } else {
        // Combine Aggregations
        List<AggregationFunction> aggregationFunctions =
            AggregationFunctionFactory.getAggregationFunction(brokerRequest);
        mergedBlock.setAggregationFunctions(aggregationFunctions);
        mergedBlock.setAggregationResults(
            combineAggregationResults(
                brokerRequest,
                mergedBlock.getAggregationResult(),
                blockToMerge.getAggregationResult()));
      }
    } else {
      // Combine Selections
      if (brokerRequest.getSelections().isSetSelectionSortSequence()) {
        SelectionOperatorService selectionService =
            new SelectionOperatorService(
                brokerRequest.getSelections(), mergedBlock.getSelectionDataSchema());
        mergedBlock.setSelectionResult(
            selectionService.merge(
                mergedBlock.getSelectionResult(), blockToMerge.getSelectionResult()));
      } else {
        mergedBlock.setSelectionResult(
            SelectionOperatorUtils.merge(
                mergedBlock.getSelectionResult(),
                blockToMerge.getSelectionResult(),
                brokerRequest.getSelections().getSize()));
      }
    }
  }