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


Java ClientProtos.Get方法代码示例

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


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

示例1: testAttributesSerialization

import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; //导入方法依赖的package包/类
@Test
public void testAttributesSerialization() throws IOException {
  Get get = new Get(Bytes.toBytes("row"));
  get.setAttribute("attribute1", Bytes.toBytes("value1"));
  get.setAttribute("attribute2", Bytes.toBytes("value2"));
  get.setAttribute("attribute3", Bytes.toBytes("value3"));

  ClientProtos.Get getProto = ProtobufUtil.toGet(get);

  Get get2 = ProtobufUtil.toGet(getProto);
  Assert.assertNull(get2.getAttribute("absent"));
  Assert.assertTrue(Arrays.equals(Bytes.toBytes("value1"), get2.getAttribute("attribute1")));
  Assert.assertTrue(Arrays.equals(Bytes.toBytes("value2"), get2.getAttribute("attribute2")));
  Assert.assertTrue(Arrays.equals(Bytes.toBytes("value3"), get2.getAttribute("attribute3")));
  Assert.assertEquals(3, get2.getAttributesMap().size());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:TestGet.java

示例2: testGet

import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; //导入方法依赖的package包/类
/**
 * Test basic Get conversions.
 *
 * @throws IOException
 */
@Test
public void testGet() throws IOException {
  ClientProtos.Get.Builder getBuilder = ClientProtos.Get.newBuilder();
  getBuilder.setRow(ByteString.copyFromUtf8("row"));
  Column.Builder columnBuilder = Column.newBuilder();
  columnBuilder.setFamily(ByteString.copyFromUtf8("f1"));
  columnBuilder.addQualifier(ByteString.copyFromUtf8("c1"));
  columnBuilder.addQualifier(ByteString.copyFromUtf8("c2"));
  getBuilder.addColumn(columnBuilder.build());

  columnBuilder.clear();
  columnBuilder.setFamily(ByteString.copyFromUtf8("f2"));
  getBuilder.addColumn(columnBuilder.build());

  ClientProtos.Get proto = getBuilder.build();
  // default fields
  assertEquals(1, proto.getMaxVersions());
  assertEquals(true, proto.getCacheBlocks());

  // set the default value for equal comparison
  getBuilder = ClientProtos.Get.newBuilder(proto);
  getBuilder.setMaxVersions(1);
  getBuilder.setCacheBlocks(true);

  Get get = ProtobufUtil.toGet(proto);
  assertEquals(getBuilder.build(), ProtobufUtil.toGet(get));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:33,代码来源:TestProtobufUtil.java

示例3: testGet

import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; //导入方法依赖的package包/类
@Test public void testGet() throws Exception{
  byte[] row = "row".getBytes();
  byte[] fam = "fam".getBytes();
  byte[] qf1 = "qf1".getBytes();

  long ts = System.currentTimeMillis();
  int maxVersions = 2;

  Get get = new Get(row);
  get.addColumn(fam, qf1);
  get.setTimeRange(ts, ts+1);
  get.setMaxVersions(maxVersions);

  ClientProtos.Get getProto = ProtobufUtil.toGet(get);
  Get desGet = ProtobufUtil.toGet(getProto);

  assertTrue(Bytes.equals(get.getRow(), desGet.getRow()));
  Set<byte[]> set = null;
  Set<byte[]> desSet = null;

  for(Map.Entry<byte[], NavigableSet<byte[]>> entry :
      get.getFamilyMap().entrySet()){
    assertTrue(desGet.getFamilyMap().containsKey(entry.getKey()));
    set = entry.getValue();
    desSet = desGet.getFamilyMap().get(entry.getKey());
    for(byte [] qualifier : set){
      assertTrue(desSet.contains(qualifier));
    }
  }

  assertEquals(get.getMaxVersions(), desGet.getMaxVersions());
  TimeRange tr = get.getTimeRange();
  TimeRange desTr = desGet.getTimeRange();
  assertEquals(tr.getMax(), desTr.getMax());
  assertEquals(tr.getMin(), desTr.getMin());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:37,代码来源:TestSerialization.java

示例4: toGet

import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; //导入方法依赖的package包/类
/**
 * Create a protocol buffer Get based on a client Get.
 *
 * @param get the client Get
 * @return a protocol buffer Get
 * @throws IOException
 */
public static ClientProtos.Get toGet(
    final Get get) throws IOException {
  ClientProtos.Get.Builder builder =
    ClientProtos.Get.newBuilder();
  builder.setRow(ByteStringer.wrap(get.getRow()));
  builder.setCacheBlocks(get.getCacheBlocks());
  builder.setMaxVersions(get.getMaxVersions());
  if (get.getFilter() != null) {
    builder.setFilter(ProtobufUtil.toFilter(get.getFilter()));
  }
  for (Entry<byte[], TimeRange> cftr : get.getColumnFamilyTimeRange().entrySet()) {
    HBaseProtos.ColumnFamilyTimeRange.Builder b = HBaseProtos.ColumnFamilyTimeRange.newBuilder();
    b.setColumnFamily(ByteString.copyFrom(cftr.getKey()));
    b.setTimeRange(timeRangeToProto(cftr.getValue()));
    builder.addCfTimeRange(b);
  }
  TimeRange timeRange = get.getTimeRange();
  if (!timeRange.isAllTime()) {
    HBaseProtos.TimeRange.Builder timeRangeBuilder =
      HBaseProtos.TimeRange.newBuilder();
    timeRangeBuilder.setFrom(timeRange.getMin());
    timeRangeBuilder.setTo(timeRange.getMax());
    builder.setTimeRange(timeRangeBuilder.build());
  }
  Map<String, byte[]> attributes = get.getAttributesMap();
  if (!attributes.isEmpty()) {
    NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder();
    for (Map.Entry<String, byte[]> attribute: attributes.entrySet()) {
      attributeBuilder.setName(attribute.getKey());
      attributeBuilder.setValue(ByteStringer.wrap(attribute.getValue()));
      builder.addAttribute(attributeBuilder.build());
    }
  }
  if (get.hasFamilies()) {
    Column.Builder columnBuilder = Column.newBuilder();
    Map<byte[], NavigableSet<byte[]>> families = get.getFamilyMap();
    for (Map.Entry<byte[], NavigableSet<byte[]>> family: families.entrySet()) {
      NavigableSet<byte[]> qualifiers = family.getValue();
      columnBuilder.setFamily(ByteStringer.wrap(family.getKey()));
      columnBuilder.clearQualifier();
      if (qualifiers != null && qualifiers.size() > 0) {
        for (byte[] qualifier: qualifiers) {
          columnBuilder.addQualifier(ByteStringer.wrap(qualifier));
        }
      }
      builder.addColumn(columnBuilder.build());
    }
  }
  if (get.getMaxResultsPerColumnFamily() >= 0) {
    builder.setStoreLimit(get.getMaxResultsPerColumnFamily());
  }
  if (get.getRowOffsetPerColumnFamily() > 0) {
    builder.setStoreOffset(get.getRowOffsetPerColumnFamily());
  }
  if (get.isCheckExistenceOnly()){
    builder.setExistenceOnly(true);
  }
  if (get.isClosestRowBefore()){
    builder.setClosestRowBefore(true);
  }
  if (get.getConsistency() != null && get.getConsistency() != Consistency.STRONG) {
    builder.setConsistency(toConsistency(get.getConsistency()));
  }

  return builder.build();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:74,代码来源:ProtobufUtil.java

示例5: toGet

import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; //导入方法依赖的package包/类
/**
 * Convert a protocol buffer Get to a client Get
 *
 * @param proto the protocol buffer Get to convert
 * @return the converted client Get
 * @throws IOException
 */
public static Get toGet(
    final ClientProtos.Get proto) throws IOException {
  if (proto == null) return null;
  byte[] row = proto.getRow().toByteArray();
  Get get = new Get(row);
  if (proto.hasCacheBlocks()) {
    get.setCacheBlocks(proto.getCacheBlocks());
  }
  if (proto.hasMaxVersions()) {
    get.setMaxVersions(proto.getMaxVersions());
  }
  if (proto.hasStoreLimit()) {
    get.setMaxResultsPerColumnFamily(proto.getStoreLimit());
  }
  if (proto.hasStoreOffset()) {
    get.setRowOffsetPerColumnFamily(proto.getStoreOffset());
  }
  if (proto.hasTimeRange()) {
    HBaseProtos.TimeRange timeRange = proto.getTimeRange();
    long minStamp = 0;
    long maxStamp = Long.MAX_VALUE;
    if (timeRange.hasFrom()) {
      minStamp = timeRange.getFrom();
    }
    if (timeRange.hasTo()) {
      maxStamp = timeRange.getTo();
    }
    get.setTimeRange(minStamp, maxStamp);
  }
  if (proto.hasFilter()) {
    FilterProtos.Filter filter = proto.getFilter();
    get.setFilter(ProtobufUtil.toFilter(filter));
  }
  for (NameBytesPair attribute: proto.getAttributeList()) {
    get.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
  }
  if (proto.getColumnCount() > 0) {
    for (Column column: proto.getColumnList()) {
      byte[] family = column.getFamily().toByteArray();
      if (column.getQualifierCount() > 0) {
        for (ByteString qualifier: column.getQualifierList()) {
          get.addColumn(family, qualifier.toByteArray());
        }
      } else {
        get.addFamily(family);
      }
    }
  }
  if (proto.hasExistenceOnly() && proto.getExistenceOnly()){
    get.setCheckExistenceOnly(true);
  }
  if (proto.hasClosestRowBefore() && proto.getClosestRowBefore()){
    get.setClosestRowBefore(true);
  }
  if (proto.hasConsistency()) {
    get.setConsistency(toConsistency(proto.getConsistency()));
  }
  return get;
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:67,代码来源:ProtobufUtil.java

示例6: toGet

import org.apache.hadoop.hbase.protobuf.generated.ClientProtos; //导入方法依赖的package包/类
/**
 * Convert a protocol buffer Get to a client Get
 *
 * @param proto the protocol buffer Get to convert
 * @return the converted client Get
 * @throws IOException
 */
public static Get toGet(
    final ClientProtos.Get proto) throws IOException {
  if (proto == null) return null;
  byte[] row = proto.getRow().toByteArray();
  Get get = new Get(row);
  if (proto.hasCacheBlocks()) {
    get.setCacheBlocks(proto.getCacheBlocks());
  }
  if (proto.hasMaxVersions()) {
    get.setMaxVersions(proto.getMaxVersions());
  }
  if (proto.hasStoreLimit()) {
    get.setMaxResultsPerColumnFamily(proto.getStoreLimit());
  }
  if (proto.hasStoreOffset()) {
    get.setRowOffsetPerColumnFamily(proto.getStoreOffset());
  }
  if (proto.hasTimeRange()) {
    HBaseProtos.TimeRange timeRange = proto.getTimeRange();
    long minStamp = 0;
    long maxStamp = Long.MAX_VALUE;
    if (timeRange.hasFrom()) {
      minStamp = timeRange.getFrom();
    }
    if (timeRange.hasTo()) {
      maxStamp = timeRange.getTo();
    }
    get.setTimeRange(minStamp, maxStamp);
  }
  if (proto.hasFilter()) {
    FilterProtos.Filter filter = proto.getFilter();
    get.setFilter(ProtobufUtil.toFilter(filter));
  }
  for (NameBytesPair attribute: proto.getAttributeList()) {
    get.setAttribute(attribute.getName(), attribute.getValue().toByteArray());
  }
  if (proto.getColumnCount() > 0) {
    for (Column column: proto.getColumnList()) {
      byte[] family = column.getFamily().toByteArray();
      if (column.getQualifierCount() > 0) {
        for (ByteString qualifier: column.getQualifierList()) {
          get.addColumn(family, qualifier.toByteArray());
        }
      } else {
        get.addFamily(family);
      }
    }
  }
  if (proto.hasExistenceOnly() && proto.getExistenceOnly()){
    get.setCheckExistenceOnly(true);
  }
  if (proto.hasClosestRowBefore() && proto.getClosestRowBefore()){
    get.setClosestRowBefore(true);
  }
  return get;
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:64,代码来源:ProtobufUtil.java


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