Java Code Examples for org.apache.hadoop.hbase.client.RowMutations

The following examples show how to use org.apache.hadoop.hbase.client.RowMutations. These examples are extracted from open source projects. 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 Project: hbase   Source File: ThriftUtilities.java    License: Apache License 2.0 6 votes vote down vote up
public static TRowMutations rowMutationsFromHBase(RowMutations in) {
  TRowMutations tRowMutations = new TRowMutations();
  tRowMutations.setRow(in.getRow());
  for (Mutation mutation : in.getMutations()) {
    TMutation tMutation = new TMutation();
    if (mutation instanceof Put) {
      tMutation.setPut(ThriftUtilities.putFromHBase((Put)mutation));
    } else if (mutation instanceof Delete) {
      tMutation.setDeleteSingle(ThriftUtilities.deleteFromHBase((Delete)mutation));
    } else {
      throw new IllegalArgumentException(
          "Only Put and Delete is supported in mutateRow, but muation=" + mutation);
    }
    tRowMutations.addToMutations(tMutation);
  }
  return tRowMutations;
}
 
Example 2
Source Project: hbase   Source File: HBaseFsck.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reset the split parent region info in meta table
 */
private void resetSplitParent(HbckRegionInfo hi) throws IOException {
  RowMutations mutations = new RowMutations(hi.getMetaEntry().getRegionInfo().getRegionName());
  Delete d = new Delete(hi.getMetaEntry().getRegionInfo().getRegionName());
  d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER);
  d.addColumn(HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER);
  mutations.add(d);

  RegionInfo hri = RegionInfoBuilder.newBuilder(hi.getMetaEntry().getRegionInfo())
    .setOffline(false).setSplit(false).build();
  Put p = MetaTableAccessor.makePutFromRegionInfo(hri, EnvironmentEdgeManager.currentTime());
  mutations.add(p);

  meta.mutateRow(mutations);
  LOG.info("Reset split parent " + hi.getMetaEntry().getRegionInfo().getRegionNameAsString() +
    " in META");
}
 
Example 3
Source Project: hbase   Source File: RequestConverter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a protocol buffer MultiRequest for row mutations.
 * Does not propagate Action absolute position.  Does not set atomic action on the created
 * RegionAtomic.  Caller should do that if wanted.
 * @param regionName
 * @param rowMutations
 * @return a data-laden RegionMutation.Builder
 * @throws IOException
 */
public static RegionAction.Builder buildRegionAction(final byte [] regionName,
    final RowMutations rowMutations)
throws IOException {
  RegionAction.Builder builder =
    getRegionActionBuilderWithRegion(RegionAction.newBuilder(), regionName);
  ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
  MutationProto.Builder mutationBuilder = MutationProto.newBuilder();
  for (Mutation mutation: rowMutations.getMutations()) {
    MutationType mutateType = null;
    if (mutation instanceof Put) {
      mutateType = MutationType.PUT;
    } else if (mutation instanceof Delete) {
      mutateType = MutationType.DELETE;
    } else {
      throw new DoNotRetryIOException("RowMutations supports only put and delete, not " +
        mutation.getClass().getName());
    }
    mutationBuilder.clear();
    MutationProto mp = ProtobufUtil.toMutation(mutateType, mutation, mutationBuilder);
    actionBuilder.clear();
    actionBuilder.setMutation(mp);
    builder.addAction(actionBuilder.build());
  }
  return builder;
}
 
Example 4
Source Project: hbase   Source File: RequestConverter.java    License: Apache License 2.0 6 votes vote down vote up
private static void buildNoDataRegionAction(final RowMutations rowMutations,
  final List<CellScannable> cells, final RegionAction.Builder regionActionBuilder,
  final ClientProtos.Action.Builder actionBuilder, final MutationProto.Builder mutationBuilder)
  throws IOException {
  for (Mutation mutation: rowMutations.getMutations()) {
    MutationType type;
    if (mutation instanceof Put) {
      type = MutationType.PUT;
    } else if (mutation instanceof Delete) {
      type = MutationType.DELETE;
    } else {
      throw new DoNotRetryIOException("RowMutations supports only put and delete, not " +
        mutation.getClass().getName());
    }
    mutationBuilder.clear();
    MutationProto mp = ProtobufUtil.toMutationNoData(type, mutation, mutationBuilder);
    cells.add(mutation);
    actionBuilder.clear();
    regionActionBuilder.addAction(actionBuilder.setMutation(mp).build());
  }
}
 
Example 5
Source Project: geowave   Source File: HBaseDataIndexWriter.java    License: Apache License 2.0 6 votes vote down vote up
private RowMutations rowToMutation(final GeoWaveRow row) {
  final RowMutations mutation = new RowMutations(row.getDataId());
  for (final GeoWaveValue value : row.getFieldValues()) {
    final Put put = new Put(row.getDataId());
    // visibility is in the visibility column so no need to serialize it with the value
    put.addColumn(
        StringUtils.stringToBinary(ByteArrayUtils.shortToString(row.getAdapterId())),
        new byte[0],
        DataIndexUtils.serializeDataIndexValue(value, false));
    if ((value.getVisibility() != null) && (value.getVisibility().length > 0)) {
      put.setCellVisibility(
          new CellVisibility(StringUtils.stringFromBinary(value.getVisibility())));
    }
    try {
      mutation.add(put);
    } catch (final IOException e) {
      LOGGER.error("Error creating HBase row mutation: " + e.getMessage());
    }
  }

  return mutation;
}
 
Example 6
Source Project: kylin-on-parquet-v2   Source File: MockHTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void mutateRow(RowMutations rm) throws IOException {
    // currently only support Put and Delete
    for (Mutation mutation : rm.getMutations()) {
        if (mutation instanceof Put) {
            put((Put) mutation);
        } else if (mutation instanceof Delete) {
            delete((Delete) mutation);
        }
    }
}
 
Example 7
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
                              CompareFilter.CompareOp compareOp, byte[] value, RowMutations rowMutations)
    throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, compareOp, value, rowMutations);
  }

  throw new UnsupportedOperationException("checkAndMutate operation is not supported transactionally");
}
 
Example 8
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations();
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 9
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations();
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 10
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
                              CompareFilter.CompareOp compareOp, byte[] value, RowMutations rowMutations)
    throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, compareOp, value, rowMutations);
  }

  throw new UnsupportedOperationException("checkAndMutate operation is not supported transactionally");
}
 
Example 11
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations();
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 12
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
    CompareFilter.CompareOp compareOp, byte[] value, RowMutations rowMutations)
    throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, compareOp, value, rowMutations);
  }

  throw new UnsupportedOperationException(
      "checkAndMutate operation is not supported transactionally");
}
 
Example 13
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareOperator op,
    byte[] value, RowMutations mutation) throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, op, value, mutation);
  } else {
    throw new UnsupportedOperationException("Operation is not supported transactionally");
  }
}
 
Example 14
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations(rm.getRow());
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 15
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
                              CompareFilter.CompareOp compareOp, byte[] value, RowMutations rowMutations)
    throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, compareOp, value, rowMutations);
  }

  throw new UnsupportedOperationException("checkAndMutate operation is not supported transactionally");
}
 
Example 16
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations();
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 17
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
                              CompareFilter.CompareOp compareOp, byte[] value, RowMutations rowMutations)
    throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, compareOp, value, rowMutations);
  }

  throw new UnsupportedOperationException("checkAndMutate operation is not supported transactionally");
}
 
Example 18
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations();
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 19
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
                              CompareFilter.CompareOp compareOp, byte[] value, RowMutations rowMutations)
    throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, compareOp, value, rowMutations);
  }

  throw new UnsupportedOperationException("checkAndMutate operation is not supported transactionally");
}
 
Example 20
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations();
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 21
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier,
                              CompareFilter.CompareOp compareOp, byte[] value, RowMutations rowMutations)
    throws IOException {
  if (allowNonTransactional) {
    return hTable.checkAndMutate(row, family, qualifier, compareOp, value, rowMutations);
  }

  throw new UnsupportedOperationException("checkAndMutate operation is not supported transactionally");
}
 
Example 22
Source Project: phoenix-tephra   Source File: TransactionAwareHTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  if (tx == null) {
    throw new IOException("Transaction not started");
  }
  RowMutations transactionalMutations = new RowMutations();
  for (Mutation mutation : rm.getMutations()) {
    if (mutation instanceof Put) {
      transactionalMutations.add(transactionalizeAction((Put) mutation));
    } else if (mutation instanceof Delete) {
      transactionalMutations.add(transactionalizeAction((Delete) mutation));
    }
  }
  hTable.mutateRow(transactionalMutations);
}
 
Example 23
Source Project: java-docs-samples   Source File: WriteConditionally.java    License: Apache License 2.0 5 votes vote down vote up
public static void writeConditionally(String projectId, String instanceId, String tableId) {
  // String projectId = "my-project-id";
  // String instanceId = "my-instance-id";
  // String tableId = "mobile-time-series";

  try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) {
    Table table = connection.getTable(TableName.valueOf(Bytes.toBytes(tableId)));
    long timestamp = System.currentTimeMillis();

    String rowKey = "phone#4c410523#20190501";
    RowMutations mutations = new RowMutations(Bytes.toBytes(rowKey));

    Put put = new Put(Bytes.toBytes(rowKey));
    put.addColumn(
        COLUMN_FAMILY_NAME, Bytes.toBytes("os_name"), timestamp, Bytes.toBytes("android"));
    mutations.add(put);

    table.checkAndMutate(
        Bytes.toBytes(rowKey),
        COLUMN_FAMILY_NAME,
        Bytes.toBytes("os_build"),
        CompareOp.GREATER_OR_EQUAL,
        Bytes.toBytes("PQ2A.190405"),
        mutations);

    System.out.print("Successfully updated row's os_name");

  } catch (Exception e) {
    System.out.println("Error during WriteConditionally: \n" + e.toString());
    e.printStackTrace();
  }
}
 
Example 24
Source Project: kylin   Source File: MockHTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void mutateRow(RowMutations rm) throws IOException {
    // currently only support Put and Delete
    for (Mutation mutation : rm.getMutations()) {
        if (mutation instanceof Put) {
            put((Put) mutation);
        } else if (mutation instanceof Delete) {
            delete((Delete) mutation);
        }
    }
}
 
Example 25
Source Project: hbase   Source File: ThriftUtilities.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link RowMutations} (HBase) from a {@link TRowMutations} (Thrift)
 *
 * @param in the <code>TRowMutations</code> to convert
 *
 * @return converted <code>RowMutations</code>
 */
public static RowMutations rowMutationsFromThrift(TRowMutations in) throws IOException {
  List<TMutation> mutations = in.getMutations();
  RowMutations out = new RowMutations(in.getRow(), mutations.size());
  for (TMutation mutation : mutations) {
    if (mutation.isSetPut()) {
      out.add(putFromThrift(mutation.getPut()));
    }
    if (mutation.isSetDeleteSingle()) {
      out.add(deleteFromThrift(mutation.getDeleteSingle()));
    }
  }
  return out;
}
 
Example 26
Source Project: hbase   Source File: ThriftTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean thenPut(Put put) throws IOException {
  preCheck();
  RowMutations rowMutations = new RowMutations(put.getRow());
  rowMutations.add(put);
  return checkAndMutate(row, family, qualifier, op, value, rowMutations);
}
 
Example 27
Source Project: hbase   Source File: ThriftTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean thenDelete(Delete delete) throws IOException {
  preCheck();
  RowMutations rowMutations = new RowMutations(delete.getRow());
  rowMutations.add(delete);
  return checkAndMutate(row, family, qualifier, op, value, rowMutations);
}
 
Example 28
Source Project: hbase   Source File: ThriftTable.java    License: Apache License 2.0 5 votes vote down vote up
private boolean checkAndMutate(byte[] row, byte[] family, byte[] qualifier, CompareOperator op,
    byte[] value, RowMutations mutation) throws IOException {
  try {
    ByteBuffer valueBuffer = value == null ? null : ByteBuffer.wrap(value);
    return client.checkAndMutate(tableNameInBytes, ByteBuffer.wrap(row), ByteBuffer.wrap(family),
      ByteBuffer.wrap(qualifier), ThriftUtilities.compareOpFromHBase(op), valueBuffer,
      ThriftUtilities.rowMutationsFromHBase(mutation));
  } catch (TException e) {
    throw new IOException(e);
  }
}
 
Example 29
Source Project: hbase   Source File: ThriftTable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mutateRow(RowMutations rm) throws IOException {
  TRowMutations tRowMutations = ThriftUtilities.rowMutationsFromHBase(rm);
  try {
    client.mutateRow(tableNameInBytes, tRowMutations);
  }  catch (TException e) {
    throw new IOException(e);
  }
}
 
Example 30
Source Project: hbase   Source File: TestVisibilityLabels.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testMutateRow() throws Exception {
  final byte[] qual2 = Bytes.toBytes("qual2");
  TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(fam);
  tableDescriptor.setColumnFamily(familyDescriptor);
  TEST_UTIL.getAdmin().createTable(tableDescriptor);
  try (Table table = TEST_UTIL.getConnection().getTable(tableName)){
    Put p1 = new Put(row1);
    p1.addColumn(fam, qual, value);
    p1.setCellVisibility(new CellVisibility(CONFIDENTIAL));

    Put p2 = new Put(row1);
    p2.addColumn(fam, qual2, value);
    p2.setCellVisibility(new CellVisibility(SECRET));

    RowMutations rm = new RowMutations(row1);
    rm.add(p1);
    rm.add(p2);

    table.mutateRow(rm);

    Get get = new Get(row1);
    get.setAuthorizations(new Authorizations(CONFIDENTIAL));
    Result result = table.get(get);
    assertTrue(result.containsColumn(fam, qual));
    assertFalse(result.containsColumn(fam, qual2));

    get.setAuthorizations(new Authorizations(SECRET));
    result = table.get(get);
    assertFalse(result.containsColumn(fam, qual));
    assertTrue(result.containsColumn(fam, qual2));
  }
}