Java Code Examples for org.apache.hadoop.hbase.client.Put#getTimestamp()

The following examples show how to use org.apache.hadoop.hbase.client.Put#getTimestamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static TPut putFromHBase(Put in) {
  TPut out = new TPut();
  out.setRow(in.getRow());
  if (in.getTimestamp() != HConstants.LATEST_TIMESTAMP) {
    out.setTimestamp(in.getTimestamp());
  }
  if (in.getDurability() != Durability.USE_DEFAULT) {
    out.setDurability(durabilityFromHBase(in.getDurability()));
  }
  for (Map.Entry<byte [], List<Cell>> entry : in.getFamilyCellMap().entrySet()) {
    byte[] family = entry.getKey();
    for (Cell cell : entry.getValue()) {
      TColumnValue columnValue = new TColumnValue();
      columnValue.setFamily(family)
          .setQualifier(CellUtil.cloneQualifier(cell))
          .setType(cell.getType().getCode())
          .setTimestamp(cell.getTimestamp())
          .setValue(CellUtil.cloneValue(cell));
      if (cell.getTagsLength() != 0) {
        columnValue.setTags(PrivateCellUtil.cloneTags(cell));
      }
      out.addToColumnValues(columnValue);
    }
  }
  for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
    out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())),
        ByteBuffer.wrap(attribute.getValue()));
  }
  try {
    CellVisibility cellVisibility = in.getCellVisibility();
    if (cellVisibility != null) {
      TCellVisibility tCellVisibility = new TCellVisibility();
      tCellVisibility.setExpression(cellVisibility.getExpression());
      out.setCellVisibility(tCellVisibility);
    }
  } catch (DeserializationException e) {
    throw new RuntimeException(e);
  }
  return out;
}
 
Example 2
Source File: RemoteHTable.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected CellSetModel buildModelFromPut(Put put) {
  RowModel row = new RowModel(put.getRow());
  long ts = put.getTimestamp();
  for (List<Cell> cells : put.getFamilyCellMap().values()) {
    for (Cell cell : cells) {
      row.addCell(new CellModel(CellUtil.cloneFamily(cell), CellUtil.cloneQualifier(cell),
        ts != HConstants.LATEST_TIMESTAMP ? ts : cell.getTimestamp(), CellUtil.cloneValue(cell)));
    }
  }
  CellSetModel model = new CellSetModel();
  model.addRow(row);
  return model;
}
 
Example 3
Source File: TestProtobufUtil.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test Put Mutate conversions.
 *
 * @throws IOException if the conversion to a {@link Put} or a
 *                     {@link org.apache.hadoop.hbase.client.Mutation} fails
 */
@Test
public void testPut() throws IOException {
  MutationProto.Builder mutateBuilder = MutationProto.newBuilder();
  mutateBuilder.setRow(ByteString.copyFromUtf8("row"));
  mutateBuilder.setMutateType(MutationType.PUT);
  mutateBuilder.setTimestamp(111111);
  ColumnValue.Builder valueBuilder = ColumnValue.newBuilder();
  valueBuilder.setFamily(ByteString.copyFromUtf8("f1"));
  QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder();
  qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1"));
  qualifierBuilder.setValue(ByteString.copyFromUtf8("v1"));
  valueBuilder.addQualifierValue(qualifierBuilder.build());
  qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c2"));
  qualifierBuilder.setValue(ByteString.copyFromUtf8("v2"));
  qualifierBuilder.setTimestamp(222222);
  valueBuilder.addQualifierValue(qualifierBuilder.build());
  mutateBuilder.addColumnValue(valueBuilder.build());

  MutationProto proto = mutateBuilder.build();
  // default fields
  assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability());

  // set the default value for equal comparison
  mutateBuilder = MutationProto.newBuilder(proto);
  mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT);

  Put put = ProtobufUtil.toPut(proto);

  // put value always use the default timestamp if no
  // value level timestamp specified,
  // add the timestamp to the original mutate
  long timestamp = put.getTimestamp();
  for (ColumnValue.Builder column:
      mutateBuilder.getColumnValueBuilderList()) {
    for (QualifierValue.Builder qualifier:
        column.getQualifierValueBuilderList()) {
      if (!qualifier.hasTimestamp()) {
        qualifier.setTimestamp(timestamp);
      }
    }
  }
  assertEquals(mutateBuilder.build(),
    ProtobufUtil.toMutation(MutationType.PUT, put));
}