コード例 #1
0
  public ReduceOperator(Grouping<IN> input, ReduceFunction<IN> function) {
    super(input.getDataSet(), input.getDataSet().getType());

    if (function == null) throw new NullPointerException("Reduce function must not be null.");

    this.function = function;
    this.grouper = input;
  }
コード例 #2
0
  @Override
  protected UnaryNodeTranslation translateToDataFlow() {

    String name = getName() != null ? getName() : function.getClass().getName();

    // distinguish between grouped reduce and non-grouped reduce
    if (grouper == null) {
      // non grouped reduce
      return new UnaryNodeTranslation(
          new PlanReduceOperator<IN>(function, new int[0], name, getInputType()));
    }

    if (grouper.getKeys() instanceof Keys.SelectorFunctionKeys) {

      @SuppressWarnings("unchecked")
      Keys.SelectorFunctionKeys<IN, ?> selectorKeys =
          (Keys.SelectorFunctionKeys<IN, ?>) grouper.getKeys();

      return translateSelectorFunctionReducer(selectorKeys, function, getInputType(), name);
    } else if (grouper.getKeys() instanceof Keys.FieldPositionKeys) {
      int[] logicalKeyPositions = grouper.getKeys().computeLogicalKeyPositions();
      PlanReduceOperator<IN> reduceOp =
          new PlanReduceOperator<IN>(function, logicalKeyPositions, name, getInputType());

      // set group order
      if (grouper.getGroupSortKeyPositions() != null) {

        int[] sortKeyPositions = grouper.getGroupSortKeyPositions();
        Order[] sortOrders = grouper.getGroupSortOrders();

        Ordering o = new Ordering();
        for (int i = 0; i < sortKeyPositions.length; i++) {
          o.appendOrdering(sortKeyPositions[i], null, sortOrders[i]);
        }
        reduceOp.setGroupOrder(o);
      }

      return new UnaryNodeTranslation(reduceOp);
    } else {
      throw new UnsupportedOperationException("Unrecognized key type.");
    }
  }
コード例 #3
0
  protected int searchGrouped(
      AbstractSearchRequest req,
      Map<String, ArtifactInfoGroup> result,
      Grouping grouping,
      IndexingContext context,
      Query query)
      throws IOException {
    Hits hits =
        context
            .getIndexSearcher()
            .search(query, new Sort(new SortField(ArtifactInfo.UINFO, SortField.STRING)));

    if (hits != null && hits.length() != 0) {
      int hitCount = hits.length();

      for (int i = 0; i < hits.length(); i++) {
        ArtifactInfo artifactInfo = IndexUtils.constructArtifactInfo(hits.doc(i), context);

        if (artifactInfo != null) {
          artifactInfo.repository = context.getRepositoryId();

          artifactInfo.context = context.getId();

          if (!grouping.addArtifactInfo(result, artifactInfo)) {
            // fix the hitCount accordingly
            hitCount--;
          }
        }
      }

      if (req.isHitLimited() && hits.length() > req.getResultHitLimit()) {
        return AbstractSearchResponse.LIMIT_EXCEEDED;
      }

      return hitCount;
    } else {
      return 0;
    }
  }
コード例 #4
0
ファイル: Group.java プロジェクト: ThrawnCA/boon
 @Override
 public int hashCode() {
   int result = expressions == null ? 0 : expressions.hashCode();
   if (grouping != null) result += grouping.hashCode();
   return result;
 }