类org.apache.hadoop.hbase.CellBuilderType源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.CellBuilderType的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * Generates and returns a Put containing the region into for the catalog table
 */
public static Put makePutFromRegionInfo(RegionInfo region, long ts) throws IOException {
  Put put = new Put(region.getRegionName(), ts);
  //copied from MetaTableAccessor
  put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(put.getRow())
    .setFamily(HConstants.CATALOG_FAMILY)
    .setQualifier(HConstants.REGIONINFO_QUALIFIER)
    .setTimestamp(put.getTimestamp())
    .setType(Cell.Type.Put)
    // Serialize the Default Replica HRI otherwise scan of hbase:meta
    // shows an info:regioninfo value with encoded name and region
    // name that differs from that of the hbase;meta row.
    .setValue(RegionInfo.toByteArray(RegionReplicaUtil.getRegionInfoForDefaultReplica(region)))
    .build());
  return put;
}
 
源代码2 项目: hbase   文件: FavoredNodeAssignmentHelper.java
/**
 * Generates and returns a Put containing the region info for the catalog table and the servers
 * @return Put object
 */
private static Put makePutFromRegionInfo(RegionInfo regionInfo, List<ServerName> favoredNodeList)
    throws IOException {
  Put put = null;
  if (favoredNodeList != null) {
    long time = EnvironmentEdgeManager.currentTime();
    put = MetaTableAccessor.makePutFromRegionInfo(regionInfo, time);
    byte[] favoredNodes = getFavoredNodes(favoredNodeList);
    put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
        .setRow(put.getRow())
        .setFamily(HConstants.CATALOG_FAMILY)
        .setQualifier(FAVOREDNODES_QUALIFIER)
        .setTimestamp(time)
        .setType(Type.Put)
        .setValue(favoredNodes)
        .build());
    LOG.debug("Create the region {} with favored nodes {}", regionInfo.getRegionNameAsString(),
      favoredNodeList);
  }
  return put;
}
 
源代码3 项目: hbase   文件: DefaultVisibilityLabelServiceImpl.java
protected void addSystemLabel(Region region, Map<String, Integer> labels,
    Map<String, List<Integer>> userAuths) throws IOException {
  if (!labels.containsKey(SYSTEM_LABEL)) {
    byte[] row = Bytes.toBytes(SYSTEM_LABEL_ORDINAL);
    Put p = new Put(row);
    p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
                  .setRow(row)
                  .setFamily(LABELS_TABLE_FAMILY)
                  .setQualifier(LABEL_QUALIFIER)
                  .setTimestamp(p.getTimestamp())
                  .setType(Type.Put)
                  .setValue(Bytes.toBytes(SYSTEM_LABEL))
                  .build());
    region.put(p);
    labels.put(SYSTEM_LABEL, SYSTEM_LABEL_ORDINAL);
  }
}
 
源代码4 项目: hbase   文件: TestHStore.java
@Test
public void testNumberOfMemStoreScannersAfterFlush() throws IOException {
  long seqId = 100;
  long timestamp = System.currentTimeMillis();
  Cell cell0 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family)
      .setQualifier(qf1).setTimestamp(timestamp).setType(Cell.Type.Put)
      .setValue(qf1).build();
  PrivateCellUtil.setSequenceId(cell0, seqId);
  testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Collections.emptyList());

  Cell cell1 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family)
      .setQualifier(qf2).setTimestamp(timestamp).setType(Cell.Type.Put)
      .setValue(qf1).build();
  PrivateCellUtil.setSequenceId(cell1, seqId);
  testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Arrays.asList(cell1));

  seqId = 101;
  timestamp = System.currentTimeMillis();
  Cell cell2 = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row2).setFamily(family)
      .setQualifier(qf2).setTimestamp(timestamp).setType(Cell.Type.Put)
      .setValue(qf1).build();
  PrivateCellUtil.setSequenceId(cell2, seqId);
  testNumberOfMemStoreScannersAfterFlush(Arrays.asList(cell0), Arrays.asList(cell1, cell2));
}
 
源代码5 项目: hbase   文件: TestBulkLoad.java
private String createHFileForFamilies(byte[] family) throws IOException {
  HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(conf);
  // TODO We need a way to do this without creating files
  File hFileLocation = testFolder.newFile();
  FSDataOutputStream out = new FSDataOutputStream(new FileOutputStream(hFileLocation), null);
  try {
    hFileFactory.withOutputStream(out);
    hFileFactory.withFileContext(new HFileContextBuilder().build());
    HFile.Writer writer = hFileFactory.create();
    try {
      writer.append(new KeyValue(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
        .setRow(randomBytes)
        .setFamily(family)
        .setQualifier(randomBytes)
        .setTimestamp(0L)
        .setType(KeyValue.Type.Put.getCode())
        .setValue(randomBytes)
        .build()));
    } finally {
      writer.close();
    }
  } finally {
    out.close();
  }
  return hFileLocation.getAbsoluteFile().getAbsolutePath();
}
 
源代码6 项目: hbase   文件: TestHFile.java
@Test
public void testShortMidpointSameQual() {
  Cell left = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
    .setRow(Bytes.toBytes("a"))
    .setFamily(Bytes.toBytes("a"))
    .setQualifier(Bytes.toBytes("a"))
    .setTimestamp(11)
    .setType(Type.Maximum.getCode())
    .setValue(HConstants.EMPTY_BYTE_ARRAY)
    .build();
  Cell right = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
    .setRow(Bytes.toBytes("a"))
    .setFamily(Bytes.toBytes("a"))
    .setQualifier(Bytes.toBytes("a"))
    .setTimestamp(9)
    .setType(Type.Maximum.getCode())
    .setValue(HConstants.EMPTY_BYTE_ARRAY)
    .build();
  Cell mid = HFileWriterImpl.getMidpoint(CellComparatorImpl.COMPARATOR, left, right);
  assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, left, mid) <= 0);
  assertTrue(PrivateCellUtil.compareKeyIgnoresMvcc(CellComparatorImpl.COMPARATOR, mid, right) == 0);
}
 
源代码7 项目: hbase   文件: SyncTable.java
private Cell checkAndResetTimestamp(Cell sourceCell){
  if (ignoreTimestamp) {
    sourceCell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
      .setType(sourceCell.getType())
      .setRow(sourceCell.getRowArray(),
        sourceCell.getRowOffset(), sourceCell.getRowLength())
      .setFamily(sourceCell.getFamilyArray(),
        sourceCell.getFamilyOffset(), sourceCell.getFamilyLength())
      .setQualifier(sourceCell.getQualifierArray(),
        sourceCell.getQualifierOffset(), sourceCell.getQualifierLength())
      .setTimestamp(System.currentTimeMillis())
      .setValue(sourceCell.getValueArray(),
        sourceCell.getValueOffset(), sourceCell.getValueLength()).build();
  }
  return sourceCell;
}
 
源代码8 项目: hbase   文件: ProtobufUtil.java
/**
 * Convert a protocol buffer Result to a client Result
 *
 * @param proto the protocol buffer Result to convert
 * @return the converted client Result
 */
public static Result toResult(final ClientProtos.Result proto) {
  if (proto.hasExists()) {
    if (proto.getStale()) {
      return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE_STALE :EMPTY_RESULT_EXISTS_FALSE_STALE;
    }
    return proto.getExists() ? EMPTY_RESULT_EXISTS_TRUE : EMPTY_RESULT_EXISTS_FALSE;
  }

  List<CellProtos.Cell> values = proto.getCellList();
  if (values.isEmpty()){
    return proto.getStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT;
  }

  List<Cell> cells = new ArrayList<>(values.size());
  ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
  for (CellProtos.Cell c : values) {
    cells.add(toCell(builder, c));
  }
  return Result.create(cells, null, proto.getStale(), proto.getPartial());
}
 
源代码9 项目: hbase   文件: TestProtobufUtil.java
@Test
public void testToCell() {
  KeyValue kv1 =
      new KeyValue(Bytes.toBytes("aaa"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]);
  KeyValue kv2 =
      new KeyValue(Bytes.toBytes("bbb"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]);
  KeyValue kv3 =
      new KeyValue(Bytes.toBytes("ccc"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]);
  byte[] arr = new byte[kv1.getLength() + kv2.getLength() + kv3.getLength()];
  System.arraycopy(kv1.getBuffer(), kv1.getOffset(), arr, 0, kv1.getLength());
  System.arraycopy(kv2.getBuffer(), kv2.getOffset(), arr, kv1.getLength(), kv2.getLength());
  System.arraycopy(kv3.getBuffer(), kv3.getOffset(), arr, kv1.getLength() + kv2.getLength(),
    kv3.getLength());
  ByteBuffer dbb = ByteBuffer.allocateDirect(arr.length);
  dbb.put(arr);
  ByteBufferKeyValue offheapKV = new ByteBufferKeyValue(dbb, kv1.getLength(), kv2.getLength());
  CellProtos.Cell cell = ProtobufUtil.toCell(offheapKV);
  Cell newOffheapKV =
      ProtobufUtil.toCell(ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY), cell);
  assertTrue(CellComparatorImpl.COMPARATOR.compare(offheapKV, newOffheapKV) == 0);
}
 
源代码10 项目: hbase   文件: TestMutation.java
@Test
public void testAppendCopyConstructor() throws IOException {
  Append origin = new Append(Bytes.toBytes("ROW-01"));
  origin.setPriority(100);
  byte[] family = Bytes.toBytes("CF-01");

  origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(origin.getRow())
    .setFamily(family)
    .setQualifier(Bytes.toBytes("q"))
    .setType(Type.Put)
    .setValue(Bytes.toBytes(100))
    .build());
  origin.addColumn(family, Bytes.toBytes("q0"), Bytes.toBytes("value"));
  origin.setTimeRange(100, 1000);
  Append clone = new Append(origin);
  assertEquals(origin, clone);
  origin.addColumn(family, Bytes.toBytes("q1"), Bytes.toBytes("value"));

  //They should have different cell lists
  assertNotEquals(origin.getCellList(family), clone.getCellList(family));
}
 
源代码11 项目: hbase   文件: TestMutation.java
@Test
public void testIncrementCopyConstructor() throws IOException {
  Increment origin = new Increment(Bytes.toBytes("ROW-01"));
  origin.setPriority(100);
  byte[] family = Bytes.toBytes("CF-01");

  origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(origin.getRow())
    .setFamily(family)
    .setQualifier(Bytes.toBytes("q"))
    .setType(Cell.Type.Put)
    .setValue(Bytes.toBytes(100))
    .build());
  origin.addColumn(family, Bytes.toBytes("q0"), 4);
  origin.setTimeRange(100, 1000);
  Increment clone = new Increment(origin);
  assertEquals(origin, clone);
  origin.addColumn(family, Bytes.toBytes("q1"), 3);

  //They should have different cell lists
  assertNotEquals(origin.getCellList(family), clone.getCellList(family));
}
 
源代码12 项目: hbase   文件: TestMutation.java
@Test
public void testDeleteCopyConstructor() throws IOException {
  Delete origin = new Delete(Bytes.toBytes("ROW-01"));
  origin.setPriority(100);
  byte[] family = Bytes.toBytes("CF-01");

  origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(origin.getRow())
    .setFamily(family)
    .setQualifier(Bytes.toBytes("q"))
    .setType(Type.Delete)
    .build());
  origin.addColumn(family, Bytes.toBytes("q0"));
  origin.addColumns(family, Bytes.toBytes("q1"));
  origin.addFamily(family);
  origin.addColumns(family, Bytes.toBytes("q2"), 100);
  origin.addFamilyVersion(family, 1000);
  Delete clone = new Delete(origin);
  assertEquals(origin, clone);
  origin.addColumn(family, Bytes.toBytes("q3"));

  //They should have different cell lists
  assertNotEquals(origin.getCellList(family), clone.getCellList(family));
}
 
源代码13 项目: hbase   文件: TestMutation.java
@Test
public void testPutCopyConstructor() throws IOException {
  Put origin = new Put(Bytes.toBytes("ROW-01"));
  origin.setPriority(100);
  byte[] family = Bytes.toBytes("CF-01");

  origin.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(origin.getRow())
    .setFamily(family)
    .setQualifier(Bytes.toBytes("q"))
    .setType(Cell.Type.Put)
    .setValue(Bytes.toBytes("value"))
    .build());
  origin.addColumn(family, Bytes.toBytes("q0"), Bytes.toBytes("V-01"));
  origin.addColumn(family, Bytes.toBytes("q1"), 100, Bytes.toBytes("V-01"));
  Put clone = new Put(origin);
  assertEquals(origin, clone);
  origin.addColumn(family, Bytes.toBytes("q2"), Bytes.toBytes("V-02"));

  //They should have different cell lists
  assertNotEquals(origin.getCellList(family), clone.getCellList(family));
}
 
源代码14 项目: hbase   文件: MultiThreadedClientExample.java
@Override
public Boolean call() throws Exception {
  try (Table t = connection.getTable(tableName)) {

    byte[] value = Bytes.toBytes(Double.toString(ThreadLocalRandom.current().nextDouble()));
    byte[] rk = Bytes.toBytes(ThreadLocalRandom.current().nextLong());
    Put p = new Put(rk);
    p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
            .setRow(rk)
            .setFamily(FAMILY)
            .setQualifier(QUAL)
            .setTimestamp(p.getTimestamp())
            .setType(Type.Put)
            .setValue(value)
            .build());
    t.put(p);
  }
  return true;
}
 
源代码15 项目: hbase   文件: WriteHeavyIncrementObserver.java
@Override
public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment)
    throws IOException {
  byte[] row = increment.getRow();
  Put put = new Put(row);
  long ts = getUniqueTimestamp(row);
  for (Map.Entry<byte[], List<Cell>> entry : increment.getFamilyCellMap().entrySet()) {
    for (Cell cell : entry.getValue()) {
      put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row)
          .setFamily(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength())
          .setQualifier(cell.getQualifierArray(), cell.getQualifierOffset(),
            cell.getQualifierLength())
          .setValue(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())
          .setType(Cell.Type.Put).setTimestamp(ts).build());
    }
  }
  c.getEnvironment().getRegion().put(put);
  c.bypass();
  return Result.EMPTY_RESULT;
}
 
源代码16 项目: phoenix   文件: IndexedKeyValue.java
private static Cell adaptFirstCellFromMutation(Mutation m) {
    if (m != null && m.getFamilyCellMap() != null &&
        m.getFamilyCellMap().firstEntry() != null &&
        m.getFamilyCellMap().firstEntry().getValue() != null
        && m.getFamilyCellMap().firstEntry().getValue().get(0) != null) {
        //have to replace the column family with WALEdit.METAFAMILY to make sure
        //that IndexedKeyValues don't get replicated. The superclass KeyValue fields
        //like row, qualifier and value are placeholders to prevent NPEs
        // when using the KeyValue APIs. See PHOENIX-5188 / 5455
        Cell mutationCell = m.getFamilyCellMap().firstEntry().getValue().get(0);
        CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
        return builder.setFamily(WALEdit.METAFAMILY).
            setQualifier(mutationCell.getQualifierArray()).
            setRow(m.getRow()).
            setTimestamp(mutationCell.getTimestamp()).
            setValue(mutationCell.getValueArray()).setType(Cell.Type.Put).build();
    } else {
        throw new IllegalArgumentException("Tried to create an IndexedKeyValue with a " +
            "Mutation with no Cells!");
    }

}
 
public static Put addLocation(Put p, ServerName sn, long openSeqNum, int replicaId)
  throws IOException {
  CellBuilder builder = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
  return p.add(builder.clear()
    .setRow(p.getRow())
    .setFamily(CATALOG_FAMILY)
    .setQualifier(getServerColumn(replicaId))
    .setTimestamp(p.getTimestamp())
    .setType(Cell.Type.Put)
    .setValue(Bytes.toBytes(sn.getAddress().toString()))
    .build())
    .add(builder.clear()
      .setRow(p.getRow())
      .setFamily(CATALOG_FAMILY)
      .setQualifier(getStartCodeColumn(replicaId))
      .setTimestamp(p.getTimestamp())
      .setType(Cell.Type.Put)
      .setValue(Bytes.toBytes(sn.getStartcode()))
      .build())
    .add(builder.clear()
      .setRow(p.getRow())
      .setFamily(CATALOG_FAMILY)
      .setQualifier(getSeqNumColumn(replicaId))
      .setTimestamp(p.getTimestamp())
      .setType(Cell.Type.Put)
      .setValue(Bytes.toBytes(openSeqNum))
      .build());
}
 
private static void addRegionStateToPut(Put put, RegionState.State state) throws IOException {
  put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(put.getRow())
    .setFamily(HConstants.CATALOG_FAMILY)
    .setQualifier(HConstants.STATE_QUALIFIER)
    .setTimestamp(put.getTimestamp())
    .setType(Cell.Type.Put)
    .setValue(Bytes.toBytes(state.name()))
    .build());
}
 
private Cell createCellForRegionInfo(RegionInfo info){
  byte[] regionInfoValue = ProtobufUtil.prependPBMagic(ProtobufUtil.toRegionInfo(info)
    .toByteArray());
  Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(info.getRegionName())
    .setFamily(Bytes.toBytes("info"))
    .setQualifier(Bytes.toBytes("regioninfo"))
    .setType(Cell.Type.Put)
    .setValue(regionInfoValue)
    .build();
  return cell;
}
 
private Cell createCellForTableState(TableName tableName){
  Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
    .setRow(tableName.getName())
    .setFamily(Bytes.toBytes("table"))
    .setQualifier(Bytes.toBytes("state"))
    .setType(Cell.Type.Put)
    .setValue(HBaseProtos.TableState.newBuilder()
      .setState(TableState.State.ENABLED.convert()).build().toByteArray())
    .build();
  return cell;
}
 
源代码21 项目: hbase-operator-tools   文件: TestTableReporter.java
private List<Cell> makeCells(byte [] row, int columns, int versions) {
  List<Cell> cells = new ArrayList<Cell>(columns);
  for (int j = 0; j < columns; j++) {
    for (int k = versions; k > 0; k--) {
      Cell cell = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).
          setRow(row).setFamily(CF).
          setQualifier(Bytes.toBytes(j)).
          setType(Cell.Type.Put).
          setTimestamp(k).
          setValue(row).build();
      cells.add(cell);
    }
  }
  return cells;
}
 
源代码22 项目: hbase   文件: ThriftUtilities.java
public static Result resultFromThrift(TResult in) {
  if (in == null) {
    return null;
  }
  if (!in.isSetColumnValues() || in.getColumnValues().isEmpty()){
    return in.isStale() ? EMPTY_RESULT_STALE : EMPTY_RESULT;
  }
  List<Cell> cells = new ArrayList<>(in.getColumnValues().size());
  ExtendedCellBuilder builder = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
  for (TColumnValue columnValue : in.getColumnValues()) {
    cells.add(toCell(builder, in.getRow(), columnValue));
  }
  return Result.create(cells, null, in.isStale(), in.isPartial());
}
 
源代码23 项目: hbase   文件: CompressionTest.java
public static void doSmokeTest(FileSystem fs, Path path, String codec)
throws Exception {
  Configuration conf = HBaseConfiguration.create();
  HFileContext context = new HFileContextBuilder()
                         .withCompression(HFileWriterImpl.compressionByName(codec)).build();
  HFile.Writer writer = HFile.getWriterFactoryNoCache(conf)
      .withPath(fs, path)
      .withFileContext(context)
      .create();
  // Write any-old Cell...
  final byte [] rowKey = Bytes.toBytes("compressiontestkey");
  Cell c = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
    .setRow(rowKey)
    .setFamily(HConstants.EMPTY_BYTE_ARRAY)
    .setQualifier(HConstants.EMPTY_BYTE_ARRAY)
    .setTimestamp(HConstants.LATEST_TIMESTAMP)
    .setType(KeyValue.Type.Maximum.getCode())
    .setValue(Bytes.toBytes("compressiontestval"))
    .build();
  writer.append(c);
  writer.appendFileInfo(Bytes.toBytes("compressioninfokey"), Bytes.toBytes("compressioninfoval"));
  writer.close();
  Cell cc = null;
  HFile.Reader reader = HFile.createReader(fs, path, CacheConfig.DISABLED, true, conf);
  try {
    HFileScanner scanner = reader.getScanner(false, true);
    scanner.seekTo(); // position to the start of file
    // Scanner does not do Cells yet. Do below for now till fixed.
    cc = scanner.getCell();
    if (CellComparator.getInstance().compareRows(c, cc) != 0) {
      throw new Exception("Read back incorrect result: " + c.toString() + " vs " + cc.toString());
    }
  } finally {
    reader.close();
  }
}
 
源代码24 项目: hbase   文件: RowPrefixFixedLengthBloomContext.java
/**
 * @param cell the cell
 * @return the new cell created by row prefix
 */
private Cell getRowPrefixCell(Cell cell) {
  byte[] row = CellUtil.copyRow(cell);
  return ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
      .setRow(row, 0, Math.min(prefixLength, row.length))
      .setType(Cell.Type.Put)
      .build();
}
 
源代码25 项目: hbase   文件: HMobStore.java
/**
 * Reads the cell from the mob file.
 * @param reference The cell found in the HBase, its value is a path to a mob file.
 * @param cacheBlocks Whether the scanner should cache blocks.
 * @param readPt the read point.
 * @param readEmptyValueOnMobCellMiss Whether return null value when the mob file is missing or
 *          corrupt.
 * @return The cell found in the mob file.
 * @throws IOException
 */
public MobCell resolve(Cell reference, boolean cacheBlocks, long readPt,
    boolean readEmptyValueOnMobCellMiss) throws IOException {
  MobCell mobCell = null;
  if (MobUtils.hasValidMobRefCellValue(reference)) {
    String fileName = MobUtils.getMobFileName(reference);
    Optional<TableName> tableName = MobUtils.getTableName(reference);
    if (tableName.isPresent()) {
      List<Path> locations = getLocations(tableName.get());
      mobCell = readCell(locations, fileName, reference, cacheBlocks, readPt,
        readEmptyValueOnMobCellMiss);
    }
  }
  if (mobCell == null) {
    LOG.warn("The Cell result is null, assemble a new Cell with the same row,family,"
        + "qualifier,timestamp,type and tags but with an empty value to return.");
    Cell cell = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
        .setRow(reference.getRowArray(), reference.getRowOffset(), reference.getRowLength())
        .setFamily(reference.getFamilyArray(), reference.getFamilyOffset(),
          reference.getFamilyLength())
        .setQualifier(reference.getQualifierArray(), reference.getQualifierOffset(),
          reference.getQualifierLength())
        .setTimestamp(reference.getTimestamp()).setType(reference.getTypeByte())
        .setValue(HConstants.EMPTY_BYTE_ARRAY)
        .setTags(reference.getTagsArray(), reference.getTagsOffset(), reference.getTagsLength())
        .build();
    mobCell = new MobCell(cell);
  }
  return mobCell;
}
 
源代码26 项目: hbase   文件: TestIncrementsFromClientSide.java
@Test
public void testIncrementWithCustomTimestamp() throws IOException {
  TableName TABLENAME = TableName.valueOf(name.getMethodName());
  Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
  long timestamp = 999;
  Increment increment = new Increment(ROW);
  increment.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
    .setRow(ROW)
    .setFamily(FAMILY)
    .setQualifier(QUALIFIER)
    .setTimestamp(timestamp)
    .setType(KeyValue.Type.Put.getCode())
    .setValue(Bytes.toBytes(100L))
    .build());
  Result r = table.increment(increment);
  assertEquals(1, r.size());
  assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.get(new Get(ROW));
  assertEquals(1, r.size());
  assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.increment(increment);
  assertEquals(1, r.size());
  assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.get(new Get(ROW));
  assertEquals(1, r.size());
  assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
}
 
源代码27 项目: hbase   文件: TestAppendFromClientSide.java
@Test
public void testAppendWithCustomTimestamp() throws IOException {
  TableName TABLENAME = TableName.valueOf(name.getMethodName());
  Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
  long timestamp = 999;
  Append append = new Append(ROW);
  append.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY)
    .setRow(ROW)
    .setFamily(FAMILY)
    .setQualifier(QUALIFIER)
    .setTimestamp(timestamp)
    .setType(KeyValue.Type.Put.getCode())
    .setValue(Bytes.toBytes(100L))
    .build());
  Result r = table.append(append);
  assertEquals(1, r.size());
  assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.get(new Get(ROW));
  assertEquals(1, r.size());
  assertEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.append(append);
  assertEquals(1, r.size());
  assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
  r = table.get(new Get(ROW));
  assertEquals(1, r.size());
  assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
}
 
private Cell newCellWithDifferentColumnFamily(Cell cell) {
  return ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
      .setRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())
      .setFamily(CF2_BYTES, 0, CF2_BYTES.length).setQualifier(CellUtil.cloneQualifier(cell))
      .setTimestamp(cell.getTimestamp()).setType(cell.getType().getCode())
      .setValue(CellUtil.cloneValue(cell)).build();
}
 
private Cell newCellWithNotExistColumnFamily(Cell cell) {
  return ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY)
      .setRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength())
      .setFamily(CF_NOT_EXIST_BYTES, 0, CF_NOT_EXIST_BYTES.length)
      .setQualifier(CellUtil.cloneQualifier(cell)).setTimestamp(cell.getTimestamp())
      .setType(cell.getType().getCode()).setValue(CellUtil.cloneValue(cell)).build();
}
 
源代码30 项目: hbase   文件: TestHStore.java
private Cell createCell(byte[] row, byte[] qualifier, long ts, long sequenceId, byte[] value)
    throws IOException {
  Cell c = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family)
      .setQualifier(qualifier).setTimestamp(ts).setType(Cell.Type.Put)
      .setValue(value).build();
  PrivateCellUtil.setSequenceId(c, sequenceId);
  return c;
}
 
 类所在包
 类方法
 同包方法