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

The following examples show how to use org.apache.hadoop.hbase.client.RowMutations. 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: HBaseDataIndexWriter.java    From geowave with 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 #2
Source File: ThriftUtilities.java    From hbase with 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 #3
Source File: RequestConverter.java    From hbase with 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 #4
Source File: RequestConverter.java    From hbase with 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 #5
Source File: HBaseFsck.java    From hbase with 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 #6
Source File: TestVisibilityLabels.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testFlushedFileWithVisibilityTags() 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);
  }
  TEST_UTIL.getAdmin().flush(tableName);
  List<HRegion> regions = TEST_UTIL.getHBaseCluster().getRegions(tableName);
  HStore store = regions.get(0).getStore(fam);
  Collection<HStoreFile> storefiles = store.getStorefiles();
  assertTrue(storefiles.size() > 0);
  for (HStoreFile storeFile : storefiles) {
    assertTrue(storeFile.getReader().getHFileReader().getFileContext().isIncludesTags());
  }
}
 
Example #7
Source File: MockHTable.java    From kylin with 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 #8
Source File: ThriftUtilities.java    From hbase with 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 #9
Source File: ThriftTable.java    From hbase with 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 #10
Source File: ThriftTable.java    From hbase with 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 #11
Source File: ThriftTable.java    From hbase with 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 #12
Source File: MockHTable.java    From kylin-on-parquet-v2 with 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 #13
Source File: TestVisibilityLabels.java    From hbase with 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));
  }
}
 
Example #14
Source File: ThriftTable.java    From hbase with 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 #15
Source File: TestRegionObserverInterface.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRowMutation() throws IOException {
  final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
  Table table = util.createTable(tableName, new byte[][] { A, B, C });
  try {
    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "hadPreGet", "hadPostGet", "hadPrePut", "hadPostPut", "hadDeleted" },
      tableName, new Boolean[] { false, false, false, false, false });
    Put put = new Put(ROW);
    put.addColumn(A, A, A);
    put.addColumn(B, B, B);
    put.addColumn(C, C, C);

    Delete delete = new Delete(ROW);
    delete.addColumn(A, A);
    delete.addColumn(B, B);
    delete.addColumn(C, C);

    RowMutations arm = new RowMutations(ROW);
    arm.add(put);
    arm.add(delete);
    table.mutateRow(arm);

    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "hadPreGet", "hadPostGet", "hadPrePut", "hadPostPut", "hadDeleted" },
      tableName, new Boolean[] { false, false, true, true, true });
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
 
Example #16
Source File: PerformanceEvaluation.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
boolean testRow(final int i) throws IOException {
  final byte [] bytes = format(i);
  // checkAndXXX tests operate on only a single value
  // Put a known value so when we go to check it, it is there.
  Put put = new Put(bytes);
  put.addColumn(FAMILY_ZERO, getQualifier(), bytes);
  this.table.put(put);
  RowMutations mutations = new RowMutations(bytes);
  mutations.add(put);
  this.table.checkAndMutate(bytes, FAMILY_ZERO).qualifier(getQualifier())
      .ifEquals(bytes).thenMutate(mutations);
  return true;
}
 
Example #17
Source File: RequestConverter.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Create a protocol buffer MutateRequest for conditioned row mutations
 *
 * @return a mutate request
 * @throws IOException
 */
public static ClientProtos.MultiRequest buildMutateRequest(final byte[] regionName,
  final byte[] row, final byte[] family, final byte[] qualifier,
  final CompareOperator op, final byte[] value, final Filter filter, final TimeRange timeRange,
  final RowMutations rowMutations) throws IOException {
  RegionAction.Builder builder =
      getRegionActionBuilderWithRegion(RegionAction.newBuilder(), regionName);
  builder.setAtomic(true);
  ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
  MutationProto.Builder mutationBuilder = MutationProto.newBuilder();
  for (Mutation mutation: rowMutations.getMutations()) {
    MutationType mutateType;
    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 ClientProtos.MultiRequest.newBuilder().addRegionAction(builder.setCondition(
    buildCondition(row, family, qualifier, op, value, filter, timeRange)).build()).build();
}
 
Example #18
Source File: HBaseDataIndexWriter.java    From geowave with Apache License 2.0 5 votes vote down vote up
private void writeMutations(final RowMutations rowMutation) {
  try {
    mutator.mutate(rowMutation.getMutations());
  } catch (final IOException e) {
    LOGGER.error("Unable to write mutation.", e);
  }
}
 
Example #19
Source File: HBaseWriter.java    From geowave with Apache License 2.0 5 votes vote down vote up
private void writeMutations(final RowMutations rowMutation) {
  try {
    synchronized (duplicateRowTracker) {
      mutator.mutate(rowMutation.getMutations());
    }
  } catch (final IOException e) {
    LOGGER.error("Unable to write mutation.", e);
  }
}
 
Example #20
Source File: HBaseUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static RowMutations getDeleteMutations(
    final byte[] rowId,
    final byte[] columnFamily,
    final byte[] columnQualifier,
    final String[] authorizations) throws IOException {
  final RowMutations m = new RowMutations(rowId);
  final Delete d = new Delete(rowId);
  d.addColumns(columnFamily, columnQualifier);
  m.add(d);
  return m;
}
 
Example #21
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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 File: TransactionAwareHTable.java    From phoenix-tephra with 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 File: TransactionAwareHTable.java    From phoenix-tephra with 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 #24
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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 #25
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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 #26
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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 #27
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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 #28
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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 #29
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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 #30
Source File: TransactionAwareHTable.java    From phoenix-tephra with 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");
}