当前位置: 首页>>代码示例>>Java>>正文


Java AggregateResponse.newBuilder方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse.newBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java AggregateResponse.newBuilder方法的具体用法?Java AggregateResponse.newBuilder怎么用?Java AggregateResponse.newBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse的用法示例。


在下文中一共展示了AggregateResponse.newBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMax

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives the maximum for a given combination of column qualifier and column
 * family, in the given row range as defined in the Scan object. In its
 * current implementation, it takes one column family and one column qualifier
 * (if provided). In case of null column qualifier, maximum value for the
 * entire column family will be returned.
 */
@Override
public void getMax(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  T max = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    T temp;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    List<Cell> results = new ArrayList<Cell>();
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    // qualifier can be null.
    boolean hasMoreRows = false;
    do {
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        temp = ci.getValue(colFamily, qualifier, results.get(i));
        max = (max == null || (temp != null && ci.compare(temp, max) > 0)) ? temp : max;
      }
      results.clear();
    } while (hasMoreRows);
    if (max != null) {
      AggregateResponse.Builder builder = AggregateResponse.newBuilder();
      builder.addFirstPart(ci.getProtoForCellType(max).toByteString());
      response = builder.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  log.info("Maximum from this region is "
      + env.getRegion().getRegionInfo().getRegionNameAsString() + ": " + max);
  done.run(response);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:55,代码来源:AggregateImplementation.java

示例2: getAvg

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a Pair with first object as Sum and second object as row count,
 * computed for a given combination of column qualifier and column family in
 * the given row range as defined in the Scan object. In its current
 * implementation, it takes one column family and one column qualifier (if
 * provided). In case of null column qualifier, an aggregate sum over all the
 * entire column family will be returned.
 * <p>
 * The average is computed in
 * AggregationClient#avg(byte[], ColumnInterpreter, Scan) by
 * processing results from all regions, so its "ok" to pass sum and a Long
 * type.
 */
@Override
public void getAvg(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null;
    Long rowCountVal = 0l;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<Cell> results = new ArrayList<Cell>();
    boolean hasMoreRows = false;
  
    do {
      results.clear();
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily,
            qualifier, results.get(i))));
      }
      rowCountVal++;
    } while (hasMoreRows);
    if (sumVal != null) {
      ByteString first = ci.getProtoForPromotedType(sumVal).toByteString();
      AggregateResponse.Builder pair = AggregateResponse.newBuilder();
      pair.addFirstPart(first);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
      bb.rewind();
      pair.setSecondPart(ByteString.copyFrom(bb));
      response = pair.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:64,代码来源:AggregateImplementation.java

示例3: getStd

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a Pair with first object a List containing Sum and sum of squares,
 * and the second object as row count. It is computed for a given combination of
 * column qualifier and column family in the given row range as defined in the
 * Scan object. In its current implementation, it takes one column family and
 * one column qualifier (if provided). The idea is get the value of variance first:
 * the average of the squares less the square of the average a standard
 * deviation is square root of variance.
 */
@Override
public void getStd(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null, sumSqVal = null, tempVal = null;
    long rowCountVal = 0l;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<Cell> results = new ArrayList<Cell>();

    boolean hasMoreRows = false;
  
    do {
      tempVal = null;
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
            qualifier, results.get(i))));
      }
      results.clear();
      sumVal = ci.add(sumVal, tempVal);
      sumSqVal = ci.add(sumSqVal, ci.multiply(tempVal, tempVal));
      rowCountVal++;
    } while (hasMoreRows);
    if (sumVal != null) {
      ByteString first_sumVal = ci.getProtoForPromotedType(sumVal).toByteString();
      ByteString first_sumSqVal = ci.getProtoForPromotedType(sumSqVal).toByteString();
      AggregateResponse.Builder pair = AggregateResponse.newBuilder();
      pair.addFirstPart(first_sumVal);
      pair.addFirstPart(first_sumSqVal);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
      bb.rewind();
      pair.setSecondPart(ByteString.copyFrom(bb));
      response = pair.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:66,代码来源:AggregateImplementation.java

示例4: getMedian

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a List containing sum of values and sum of weights.
 * It is computed for the combination of column
 * family and column qualifier(s) in the given row range as defined in the
 * Scan object. In its current implementation, it takes one column family and
 * two column qualifiers. The first qualifier is for values column and 
 * the second qualifier (optional) is for weight column.
 */
@Override
public void getMedian(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null, sumWeights = null, tempVal = null, tempWeight = null;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] valQualifier = null, weightQualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      valQualifier = qualifiers.pollFirst();
      // if weighted median is requested, get qualifier for the weight column
      weightQualifier = qualifiers.pollLast();
    }
    List<Cell> results = new ArrayList<Cell>();

    boolean hasMoreRows = false;
  
    do {
      tempVal = null;
      tempWeight = null;
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        Cell kv = results.get(i);
        tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
            valQualifier, kv)));
        if (weightQualifier != null) {
          tempWeight = ci.add(tempWeight,
              ci.castToReturnType(ci.getValue(colFamily, weightQualifier, kv)));
        }
      }
      results.clear();
      sumVal = ci.add(sumVal, tempVal);
      sumWeights = ci.add(sumWeights, tempWeight);
    } while (hasMoreRows);
    ByteString first_sumVal = ci.getProtoForPromotedType(sumVal).toByteString();
    S s = sumWeights == null ? ci.castToReturnType(ci.getMinValue()) : sumWeights;
    ByteString first_sumWeights = ci.getProtoForPromotedType(s).toByteString();
    AggregateResponse.Builder pair = AggregateResponse.newBuilder();
    pair.addFirstPart(first_sumVal);
    pair.addFirstPart(first_sumWeights); 
    response = pair.build();
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:67,代码来源:AggregateImplementation.java

示例5: getMax

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives the maximum for a given combination of column qualifier and column
 * family, in the given row range as defined in the Scan object. In its
 * current implementation, it takes one column family and one column qualifier
 * (if provided). In case of null column qualifier, maximum value for the
 * entire column family will be returned.
 */
@Override
public void getMax(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  T max = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    T temp;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    List<Cell> results = new ArrayList<Cell>();
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    // qualifier can be null.
    boolean hasMoreRows = false;
    do {
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        temp = ci.getValue(colFamily, qualifier, results.get(i));
        max = (max == null || (temp != null && ci.compare(temp, max) > 0)) ? temp : max;
      }
      results.clear();
    } while (hasMoreRows);
    if (max != null) {
      AggregateResponse.Builder builder = AggregateResponse.newBuilder();
      builder.addFirstPart(ci.getProtoForCellType(max).toByteString());
      response = builder.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  log.info("Maximum from this region is "
      + env.getRegion().getRegionNameAsString() + ": " + max);
  done.run(response);
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:55,代码来源:AggregateImplementation.java

示例6: getMax

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives the maximum for a given combination of column qualifier and column
 * family, in the given row range as defined in the Scan object. In its
 * current implementation, it takes one column family and one column qualifier
 * (if provided). In case of null column qualifier, maximum value for the
 * entire column family will be returned.
 */
@Override
public void getMax(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  T max = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    T temp;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    List<Cell> results = new ArrayList<Cell>();
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    // qualifier can be null.
    boolean hasMoreRows = false;
    do {
      hasMoreRows = scanner.next(results);
      for (Cell kv : results) {
        temp = ci.getValue(colFamily, qualifier, kv);
        max = (max == null || (temp != null && ci.compare(temp, max) > 0)) ? temp : max;
      }
      results.clear();
    } while (hasMoreRows);
    if (max != null) {
      AggregateResponse.Builder builder = AggregateResponse.newBuilder();
      builder.addFirstPart(ci.getProtoForCellType(max).toByteString());
      response = builder.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  log.info("Maximum from this region is "
      + env.getRegion().getRegionNameAsString() + ": " + max);
  done.run(response);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:54,代码来源:AggregateImplementation.java

示例7: getAvg

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a Pair with first object as Sum and second object as row count,
 * computed for a given combination of column qualifier and column family in
 * the given row range as defined in the Scan object. In its current
 * implementation, it takes one column family and one column qualifier (if
 * provided). In case of null column qualifier, an aggregate sum over all the
 * entire column family will be returned.
 * <p>
 * The average is computed in
 * AggregationClient#avg(byte[], ColumnInterpreter, Scan) by
 * processing results from all regions, so its "ok" to pass sum and a Long
 * type.
 */
@Override
public void getAvg(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null;
    Long rowCountVal = 0l;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<Cell> results = new ArrayList<Cell>();
    boolean hasMoreRows = false;
  
    do {
      results.clear();
      hasMoreRows = scanner.next(results);
      for (Cell kv : results) {
        sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily,
            qualifier, kv)));
      }
      rowCountVal++;
    } while (hasMoreRows);
    if (sumVal != null) {
      ByteString first = ci.getProtoForPromotedType(sumVal).toByteString();
      AggregateResponse.Builder pair = AggregateResponse.newBuilder();
      pair.addFirstPart(first);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
      bb.rewind();
      pair.setSecondPart(ByteString.copyFrom(bb));
      response = pair.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:63,代码来源:AggregateImplementation.java

示例8: getStd

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a Pair with first object a List containing Sum and sum of squares,
 * and the second object as row count. It is computed for a given combination of
 * column qualifier and column family in the given row range as defined in the
 * Scan object. In its current implementation, it takes one column family and
 * one column qualifier (if provided). The idea is get the value of variance first:
 * the average of the squares less the square of the average a standard
 * deviation is square root of variance.
 */
@Override
public void getStd(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null, sumSqVal = null, tempVal = null;
    long rowCountVal = 0l;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<Cell> results = new ArrayList<Cell>();

    boolean hasMoreRows = false;
  
    do {
      tempVal = null;
      hasMoreRows = scanner.next(results);
      for (Cell kv : results) {
        tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
            qualifier, kv)));
      }
      results.clear();
      sumVal = ci.add(sumVal, tempVal);
      sumSqVal = ci.add(sumSqVal, ci.multiply(tempVal, tempVal));
      rowCountVal++;
    } while (hasMoreRows);
    if (sumVal != null) {
      ByteString first_sumVal = ci.getProtoForPromotedType(sumVal).toByteString();
      ByteString first_sumSqVal = ci.getProtoForPromotedType(sumSqVal).toByteString();
      AggregateResponse.Builder pair = AggregateResponse.newBuilder();
      pair.addFirstPart(first_sumVal);
      pair.addFirstPart(first_sumSqVal);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
      bb.rewind();
      pair.setSecondPart(ByteString.copyFrom(bb));
      response = pair.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:65,代码来源:AggregateImplementation.java

示例9: getMedian

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a List containing sum of values and sum of weights.
 * It is computed for the combination of column
 * family and column qualifier(s) in the given row range as defined in the
 * Scan object. In its current implementation, it takes one column family and
 * two column qualifiers. The first qualifier is for values column and 
 * the second qualifier (optional) is for weight column.
 */
@Override
public void getMedian(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null, sumWeights = null, tempVal = null, tempWeight = null;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] valQualifier = null, weightQualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      valQualifier = qualifiers.pollFirst();
      // if weighted median is requested, get qualifier for the weight column
      weightQualifier = qualifiers.pollLast();
    }
    List<Cell> results = new ArrayList<Cell>();

    boolean hasMoreRows = false;
  
    do {
      tempVal = null;
      tempWeight = null;
      hasMoreRows = scanner.next(results);
      for (Cell kv : results) {
        tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
            valQualifier, kv)));
        if (weightQualifier != null) {
          tempWeight = ci.add(tempWeight,
              ci.castToReturnType(ci.getValue(colFamily, weightQualifier, kv)));
        }
      }
      results.clear();
      sumVal = ci.add(sumVal, tempVal);
      sumWeights = ci.add(sumWeights, tempWeight);
    } while (hasMoreRows);
    ByteString first_sumVal = ci.getProtoForPromotedType(sumVal).toByteString();
    S s = sumWeights == null ? ci.castToReturnType(ci.getMinValue()) : sumWeights;
    ByteString first_sumWeights = ci.getProtoForPromotedType(s).toByteString();
    AggregateResponse.Builder pair = AggregateResponse.newBuilder();
    pair.addFirstPart(first_sumVal);
    pair.addFirstPart(first_sumWeights); 
    response = pair.build();
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:65,代码来源:AggregateImplementation.java

示例10: getMax

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives the maximum for a given combination of column qualifier and column
 * family, in the given row range as defined in the Scan object. In its
 * current implementation, it takes one column family and one column qualifier
 * (if provided). In case of null column qualifier, maximum value for the
 * entire column family will be returned.
 */
@Override
public void getMax(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  T max = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    T temp;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    List<Cell> results = new ArrayList<>();
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    // qualifier can be null.
    boolean hasMoreRows = false;
    do {
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        temp = ci.getValue(colFamily, qualifier, results.get(i));
        max = (max == null || (temp != null && ci.compare(temp, max) > 0)) ? temp : max;
      }
      results.clear();
    } while (hasMoreRows);
    if (max != null) {
      AggregateResponse.Builder builder = AggregateResponse.newBuilder();
      builder.addFirstPart(ci.getProtoForCellType(max).toByteString());
      response = builder.build();
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  log.info("Maximum from this region is "
      + env.getRegion().getRegionInfo().getRegionNameAsString() + ": " + max);
  done.run(response);
}
 
开发者ID:apache,项目名称:hbase,代码行数:55,代码来源:AggregateImplementation.java

示例11: getAvg

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a Pair with first object as Sum and second object as row count,
 * computed for a given combination of column qualifier and column family in
 * the given row range as defined in the Scan object. In its current
 * implementation, it takes one column family and one column qualifier (if
 * provided). In case of null column qualifier, an aggregate sum over all the
 * entire column family will be returned.
 * <p>
 * The average is computed in
 * AggregationClient#avg(byte[], ColumnInterpreter, Scan) by
 * processing results from all regions, so its "ok" to pass sum and a Long
 * type.
 */
@Override
public void getAvg(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null;
    Long rowCountVal = 0l;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<Cell> results = new ArrayList<>();
    boolean hasMoreRows = false;

    do {
      results.clear();
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily,
            qualifier, results.get(i))));
      }
      rowCountVal++;
    } while (hasMoreRows);
    if (sumVal != null) {
      ByteString first = ci.getProtoForPromotedType(sumVal).toByteString();
      AggregateResponse.Builder pair = AggregateResponse.newBuilder();
      pair.addFirstPart(first);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
      bb.rewind();
      pair.setSecondPart(ByteString.copyFrom(bb));
      response = pair.build();
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:apache,项目名称:hbase,代码行数:64,代码来源:AggregateImplementation.java

示例12: getStd

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a Pair with first object a List containing Sum and sum of squares,
 * and the second object as row count. It is computed for a given combination of
 * column qualifier and column family in the given row range as defined in the
 * Scan object. In its current implementation, it takes one column family and
 * one column qualifier (if provided). The idea is get the value of variance first:
 * the average of the squares less the square of the average a standard
 * deviation is square root of variance.
 */
@Override
public void getStd(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null, sumSqVal = null, tempVal = null;
    long rowCountVal = 0l;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<Cell> results = new ArrayList<>();

    boolean hasMoreRows = false;

    do {
      tempVal = null;
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
            qualifier, results.get(i))));
      }
      results.clear();
      sumVal = ci.add(sumVal, tempVal);
      sumSqVal = ci.add(sumSqVal, ci.multiply(tempVal, tempVal));
      rowCountVal++;
    } while (hasMoreRows);
    if (sumVal != null) {
      ByteString first_sumVal = ci.getProtoForPromotedType(sumVal).toByteString();
      ByteString first_sumSqVal = ci.getProtoForPromotedType(sumSqVal).toByteString();
      AggregateResponse.Builder pair = AggregateResponse.newBuilder();
      pair.addFirstPart(first_sumVal);
      pair.addFirstPart(first_sumSqVal);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
      bb.rewind();
      pair.setSecondPart(ByteString.copyFrom(bb));
      response = pair.build();
    }
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:apache,项目名称:hbase,代码行数:66,代码来源:AggregateImplementation.java

示例13: getMedian

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a List containing sum of values and sum of weights.
 * It is computed for the combination of column
 * family and column qualifier(s) in the given row range as defined in the
 * Scan object. In its current implementation, it takes one column family and
 * two column qualifiers. The first qualifier is for values column and
 * the second qualifier (optional) is for weight column.
 */
@Override
public void getMedian(RpcController controller, AggregateRequest request,
    RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null, sumWeights = null, tempVal = null, tempWeight = null;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] valQualifier = null, weightQualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      valQualifier = qualifiers.pollFirst();
      // if weighted median is requested, get qualifier for the weight column
      weightQualifier = qualifiers.pollLast();
    }
    List<Cell> results = new ArrayList<>();

    boolean hasMoreRows = false;

    do {
      tempVal = null;
      tempWeight = null;
      hasMoreRows = scanner.next(results);
      int listSize = results.size();
      for (int i = 0; i < listSize; i++) {
        Cell kv = results.get(i);
        tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
            valQualifier, kv)));
        if (weightQualifier != null) {
          tempWeight = ci.add(tempWeight,
              ci.castToReturnType(ci.getValue(colFamily, weightQualifier, kv)));
        }
      }
      results.clear();
      sumVal = ci.add(sumVal, tempVal);
      sumWeights = ci.add(sumWeights, tempWeight);
    } while (hasMoreRows);
    ByteString first_sumVal = ci.getProtoForPromotedType(sumVal).toByteString();
    S s = sumWeights == null ? ci.castToReturnType(ci.getMinValue()) : sumWeights;
    ByteString first_sumWeights = ci.getProtoForPromotedType(s).toByteString();
    AggregateResponse.Builder pair = AggregateResponse.newBuilder();
    pair.addFirstPart(first_sumVal);
    pair.addFirstPart(first_sumWeights);
    response = pair.build();
  } catch (IOException e) {
    CoprocessorRpcUtils.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:apache,项目名称:hbase,代码行数:67,代码来源:AggregateImplementation.java

示例14: getMax

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives the maximum for a given combination of column qualifier and column
 * family, in the given row range as defined in the Scan object. In its
 * current implementation, it takes one column family and one column qualifier
 * (if provided). In case of null column qualifier, maximum value for the
 * entire column family will be returned.
 */
@Override
public void getMax(RpcController controller, AggregateArgument request,
    RpcCallback<AggregateResponse> done) {
  InternalScanner scanner = null;
  AggregateResponse response = null;
  T max = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    T temp;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    List<KeyValue> results = new ArrayList<KeyValue>();
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    // qualifier can be null.
    boolean hasMoreRows = false;
    do {
      hasMoreRows = scanner.next(results);
      for (KeyValue kv : results) {
        temp = ci.getValue(colFamily, qualifier, kv);
        max = (max == null || (temp != null && ci.compare(temp, max) > 0)) ? temp : max;
      }
      results.clear();
    } while (hasMoreRows);
    if (max != null) {
      AggregateResponse.Builder builder = AggregateResponse.newBuilder();
      builder.addFirstPart(ci.getProtoForCellType(max).toByteString());
      response = builder.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  log.info("Maximum from this region is "
      + env.getRegion().getRegionNameAsString() + ": " + max);
  done.run(response);
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:54,代码来源:AggregateImplementation.java

示例15: getAvg

import org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse; //导入方法依赖的package包/类
/**
 * Gives a Pair with first object as Sum and second object as row count,
 * computed for a given combination of column qualifier and column family in
 * the given row range as defined in the Scan object. In its current
 * implementation, it takes one column family and one column qualifier (if
 * provided). In case of null column qualifier, an aggregate sum over all the
 * entire column family will be returned.
 * <p>
 * The average is computed in
 * {@link AggregationClient#avg(byte[], ColumnInterpreter, Scan)} by
 * processing results from all regions, so its "ok" to pass sum and a Long
 * type.
 */
@Override
public void getAvg(RpcController controller, AggregateArgument request,
    RpcCallback<AggregateResponse> done) {
  AggregateResponse response = null;
  InternalScanner scanner = null;
  try {
    ColumnInterpreter<T, S, P, Q, R> ci = constructColumnInterpreterFromRequest(request);
    S sumVal = null;
    Long rowCountVal = 0l;
    Scan scan = ProtobufUtil.toScan(request.getScan());
    scanner = env.getRegion().getScanner(scan);
    byte[] colFamily = scan.getFamilies()[0];
    NavigableSet<byte[]> qualifiers = scan.getFamilyMap().get(colFamily);
    byte[] qualifier = null;
    if (qualifiers != null && !qualifiers.isEmpty()) {
      qualifier = qualifiers.pollFirst();
    }
    List<KeyValue> results = new ArrayList<KeyValue>();
    boolean hasMoreRows = false;
  
    do {
      results.clear();
      hasMoreRows = scanner.next(results);
      for (KeyValue kv : results) {
        sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily,
            qualifier, kv)));
      }
      rowCountVal++;
    } while (hasMoreRows);
    if (sumVal != null) {
      ByteString first = ci.getProtoForPromotedType(sumVal).toByteString();
      AggregateResponse.Builder pair = AggregateResponse.newBuilder();
      pair.addFirstPart(first);
      ByteBuffer bb = ByteBuffer.allocate(8).putLong(rowCountVal);
      bb.rewind();
      pair.setSecondPart(ByteString.copyFrom(bb));
      response = pair.build();
    }
  } catch (IOException e) {
    ResponseConverter.setControllerException(controller, e);
  } finally {
    if (scanner != null) {
      try {
        scanner.close();
      } catch (IOException ignored) {}
    }
  }
  done.run(response);
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:63,代码来源:AggregateImplementation.java


注:本文中的org.apache.hadoop.hbase.protobuf.generated.AggregateProtos.AggregateResponse.newBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。