Java Code Examples for org.apache.hadoop.hbase.client.Delete#addColumns()

The following examples show how to use org.apache.hadoop.hbase.client.Delete#addColumns() . 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: EdgeIndexRemover.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
private Delete constructDelete(Direction direction, Map.Entry<String, Boolean> entry) {
    boolean isUnique = entry.getValue();
    Delete delete = new Delete(graph.getEdgeIndexModel().serializeForWrite(edge, direction, isUnique, entry.getKey()));
    if (ts != null) {
        delete.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.CREATED_AT_BYTES, ts);
    } else {
        delete.addColumns(Constants.DEFAULT_FAMILY_BYTES, Constants.CREATED_AT_BYTES);
    }
    if (isUnique) {
        if (ts != null) {
            delete.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.VERTEX_ID_BYTES, ts);
            delete.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.EDGE_ID_BYTES, ts);
        } else {
            delete.addColumns(Constants.DEFAULT_FAMILY_BYTES, Constants.VERTEX_ID_BYTES);
            delete.addColumns(Constants.DEFAULT_FAMILY_BYTES, Constants.EDGE_ID_BYTES);
        }
    }
    return delete;
}
 
Example 2
Source File: VertexIndexRemover.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
private Delete constructDelete(Map.Entry<String, Boolean> entry) {
    boolean isUnique = entry.getValue();
    Delete delete = new Delete(graph.getVertexIndexModel().serializeForWrite(vertex, entry.getValue(), entry.getKey()));
    if (ts != null) {
        delete.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.CREATED_AT_BYTES, ts);
    } else {
        delete.addColumns(Constants.DEFAULT_FAMILY_BYTES, Constants.CREATED_AT_BYTES);
    }
    if (isUnique) {
        if (ts != null) {
            delete.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.VERTEX_ID_BYTES, ts);
        } else {
            delete.addColumns(Constants.DEFAULT_FAMILY_BYTES, Constants.VERTEX_ID_BYTES);
        }
    }
    return delete;
}
 
Example 3
Source File: HbaseApplicationIndexDao.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteAgentId(String applicationName, String agentId) {
    if (StringUtils.isEmpty(applicationName)) {
        throw new IllegalArgumentException("applicationName cannot be empty");
    }
    if (StringUtils.isEmpty(agentId)) {
        throw new IllegalArgumentException("agentId cannot be empty");
    }
    byte[] rowKey = Bytes.toBytes(applicationName);
    Delete delete = new Delete(rowKey);
    byte[] qualifier = Bytes.toBytes(agentId);
    delete.addColumns(descriptor.getColumnFamilyName(), qualifier);

    TableName applicationIndexTableName = descriptor.getTableName();
    hbaseOperations2.delete(applicationIndexTableName, delete);
}
 
Example 4
Source File: QuotaTableUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of {@code Delete} to remove all entries returned by the passed scanner.
 * @param connection connection to re-use
 * @param scan the scanner to use to generate the list of deletes
 */
static List<Delete> createDeletesForExistingSnapshotsFromScan(Connection connection, Scan scan)
    throws IOException {
  List<Delete> deletes = new ArrayList<>();
  try (Table quotaTable = connection.getTable(QUOTA_TABLE_NAME);
      ResultScanner rs = quotaTable.getScanner(scan)) {
    for (Result r : rs) {
      CellScanner cs = r.cellScanner();
      while (cs.advance()) {
        Cell c = cs.current();
        byte[] family = Bytes.copy(c.getFamilyArray(), c.getFamilyOffset(), c.getFamilyLength());
        byte[] qual =
            Bytes.copy(c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength());
        Delete d = new Delete(r.getRow());
        d.addColumns(family, qual);
        deletes.add(d);
      }
    }
    return deletes;
  }
}
 
Example 5
Source File: ThriftHBaseServiceHandler.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteAllTs(ByteBuffer tableName,
    ByteBuffer row,
    ByteBuffer column,
    long timestamp, Map<ByteBuffer, ByteBuffer> attributes) throws IOError {
  Table table = null;
  try {
    table = getTable(tableName);
    Delete delete  = new Delete(getBytes(row));
    addAttributes(delete, attributes);
    byte [][] famAndQf = CellUtil.parseColumn(getBytes(column));
    if (famAndQf.length == 1) {
      delete.addFamily(famAndQf[0], timestamp);
    } else {
      delete.addColumns(famAndQf[0], famAndQf[1], timestamp);
    }
    table.delete(delete);

  } catch (IOException e) {
    LOG.warn(e.getMessage(), e);
    throw getIOError(e);
  } finally {
    closeTable(table);
  }
}
 
Example 6
Source File: HbaseApplicationIndexDao.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteAgentIds(Map<String, List<String>> applicationAgentIdMap) {
    if (MapUtils.isEmpty(applicationAgentIdMap)) {
        return;
    }

    List<Delete> deletes = new ArrayList<>(applicationAgentIdMap.size());

    for (Map.Entry<String, List<String>> entry : applicationAgentIdMap.entrySet()) {
        String applicationName = entry.getKey();
        List<String> agentIds = entry.getValue();
        if (StringUtils.isEmpty(applicationName) || CollectionUtils.isEmpty(agentIds)) {
            continue;
        }
        Delete delete = new Delete(Bytes.toBytes(applicationName));
        for (String agentId : agentIds) {
            if (!StringUtils.isEmpty(agentId)) {
                delete.addColumns(descriptor.getColumnFamilyName(), Bytes.toBytes(agentId));
            }
        }
        // don't delete if nothing has been specified except row
        if (!delete.getFamilyCellMap().isEmpty()) {
            deletes.add(delete);
        }
    }

    TableName applicationIndexTableName = descriptor.getTableName();
    hbaseOperations2.delete(applicationIndexTableName, deletes);
}
 
Example 7
Source File: QuotaTableUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of {@code Delete} to remove given namespace snapshot
 * entries to removefrom quota table
 * @param snapshotEntriesToRemove the entries to remove
 */
static List<Delete> createDeletesForExistingNamespaceSnapshotSizes(
    Set<String> snapshotEntriesToRemove) {
  List<Delete> deletes = new ArrayList<>();
  for (String snapshot : snapshotEntriesToRemove) {
    Delete d = new Delete(getNamespaceRowKey(snapshot));
    d.addColumns(QUOTA_FAMILY_USAGE, QUOTA_SNAPSHOT_SIZE_QUALIFIER);
    deletes.add(d);
  }
  return deletes;
}
 
Example 8
Source File: TestMinorCompaction.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testMinorCompactionWithDeleteColumn1() throws Exception {
  Delete dc = new Delete(secondRowBytes);
  /* delete all timestamps in the column */
  dc.addColumns(fam2, col2);
  testMinorCompactionWithDelete(dc);
}
 
Example 9
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 10
Source File: QuotaUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void deleteQuotas(final Connection connection, final byte[] rowKey,
    final byte[] qualifier) throws IOException {
  Delete delete = new Delete(rowKey);
  if (qualifier != null) {
    delete.addColumns(QUOTA_FAMILY_INFO, qualifier);
  }
  doDelete(connection, delete);
}
 
Example 11
Source File: HBCKMetaTableAccessor.java    From hbase-operator-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Remove state for table from meta
 * (Copied from MetaTableAccessor)
 * @param connection to use for deletion
 * @param table to delete state for
 */
public static void deleteTableState(Connection connection, TableName table)
  throws IOException {
  long time = EnvironmentEdgeManager.currentTime();
  Delete delete = new Delete(table.getName());
  delete.addColumns(TABLE_FAMILY, HConstants.TABLE_STATE_QUALIFIER, time);
  deleteFromMetaTable(connection, delete);
  LOG.info("Deleted table " + table + " state from META");
}
 
Example 12
Source File: MetaTableAccessor.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes merge qualifiers for the specified merge region.
 * @param connection connection we're using
 * @param mergeRegion the merged region
 */
public static void deleteMergeQualifiers(Connection connection, final RegionInfo mergeRegion)
  throws IOException {
  Delete delete = new Delete(mergeRegion.getRegionName());
  // NOTE: We are doing a new hbase:meta read here.
  Cell[] cells = getRegionResult(connection, mergeRegion.getRegionName()).rawCells();
  if (cells == null || cells.length == 0) {
    return;
  }
  List<byte[]> qualifiers = new ArrayList<>();
  for (Cell cell : cells) {
    if (!isMergeQualifierPrefix(cell)) {
      continue;
    }
    byte[] qualifier = CellUtil.cloneQualifier(cell);
    qualifiers.add(qualifier);
    delete.addColumns(HConstants.CATALOG_FAMILY, qualifier, HConstants.LATEST_TIMESTAMP);
  }

  // There will be race condition that a GCMultipleMergedRegionsProcedure is scheduled while
  // the previous GCMultipleMergedRegionsProcedure is still going on, in this case, the second
  // GCMultipleMergedRegionsProcedure could delete the merged region by accident!
  if (qualifiers.isEmpty()) {
    LOG.info("No merged qualifiers for region " + mergeRegion.getRegionNameAsString() +
      " in meta table, they are cleaned up already, Skip.");
    return;
  }

  deleteFromMetaTable(connection, delete);
  LOG.info("Deleted merge references in " + mergeRegion.getRegionNameAsString() +
    ", deleted qualifiers " +
    qualifiers.stream().map(Bytes::toStringBinary).collect(Collectors.joining(", ")));
}
 
Example 13
Source File: MetaTableAccessor.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Remove state for table from meta
 * @param connection to use for deletion
 * @param table to delete state for
 */
public static void deleteTableState(Connection connection, TableName table) throws IOException {
  long time = EnvironmentEdgeManager.currentTime();
  Delete delete = new Delete(table.getName());
  delete.addColumns(HConstants.TABLE_FAMILY, HConstants.TABLE_STATE_QUALIFIER, time);
  deleteFromMetaTable(connection, delete);
  LOG.info("Deleted table " + table + " state from META");
}
 
Example 14
Source File: QuotaTableUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of {@code Delete} to remove given table snapshot
 * entries to remove from quota table
 * @param snapshotEntriesToRemove the entries to remove
 */
static List<Delete> createDeletesForExistingTableSnapshotSizes(
    Multimap<TableName, String> snapshotEntriesToRemove) {
  List<Delete> deletes = new ArrayList<>();
  for (Map.Entry<TableName, Collection<String>> entry : snapshotEntriesToRemove.asMap()
      .entrySet()) {
    for (String snapshot : entry.getValue()) {
      Delete d = new Delete(getTableRowKey(entry.getKey()));
      d.addColumns(QUOTA_FAMILY_USAGE,
          Bytes.add(QUOTA_SNAPSHOT_SIZE_QUALIFIER, Bytes.toBytes(snapshot)));
      deletes.add(d);
    }
  }
  return deletes;
}
 
Example 15
Source File: PropertyRemover.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<Mutation> constructMutations() {
    byte[] idBytes = ValueUtils.serializeWithSalt(element.id());
    Delete delete = new Delete(idBytes);
    delete.addColumns(Constants.DEFAULT_FAMILY_BYTES, Bytes.toBytes(key));
    Put put = new Put(idBytes);
    put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.UPDATED_AT_BYTES,
            ValueUtils.serialize(((HBaseElement) element).updatedAt()));
    return IteratorUtils.of(delete, put);
}
 
Example 16
Source File: SnapshotScannerHDFSAclController.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static void deleteUserEntry(Table aclTable, String user, byte[] entry)
    throws IOException {
  Delete delete = new Delete(entry);
  delete.addColumns(HDFS_ACL_FAMILY, Bytes.toBytes(user));
  aclTable.delete(delete);
}
 
Example 17
Source File: TestVisibilityLabelsWithDeletes.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testVisibilityLabelsWithDeleteColumnsWithMultipleVersions() throws Exception {
  setAuths();
  final TableName tableName = TableName.valueOf(testName.getMethodName());
  try (Table table = doPuts(tableName)) {
    TEST_UTIL.getAdmin().flush(tableName);
    PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        try (Connection connection = ConnectionFactory.createConnection(conf);
          Table table = connection.getTable(tableName)) {
          Delete d = new Delete(row1);
          d.setCellVisibility(new CellVisibility(
              "(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + SECRET + "&" + TOPSECRET + ")"));
          d.addColumns(fam, qual, 125L);
          table.delete(d);
        } catch (Throwable t) {
          throw new IOException(t);
        }
        return null;
      }
    };
    SUPERUSER.runAs(actiona);

    TEST_UTIL.getAdmin().flush(tableName);
    Scan s = new Scan();
    s.readVersions(5);
    s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
    ResultScanner scanner = table.getScanner(s);
    Result[] next = scanner.next(3);
    assertTrue(next.length == 2);
    CellScanner cellScanner = next[0].cellScanner();
    cellScanner.advance();
    Cell current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row1, 0, row1.length));
    assertEquals(127L, current.getTimestamp());
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row1, 0, row1.length));
    assertEquals(126L, current.getTimestamp());
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row1, 0, row1.length));
    assertEquals(125L, current.getTimestamp());
    cellScanner = next[1].cellScanner();
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row2, 0, row2.length));
  }
}
 
Example 18
Source File: TestVisibilityLabelsWithDeletes.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteColumnswithMultipleColumnsWithMultipleVersions() throws Exception {
  setAuths();
  final TableName tableName = TableName.valueOf(testName.getMethodName());
  try (Table table = doPutsWithDiffCols(tableName)) {
    TEST_UTIL.getAdmin().flush(tableName);
    PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        Delete d = new Delete(row1);
        d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
        d.addColumns(fam, qual, 125L);
        try (Connection connection = ConnectionFactory.createConnection(conf);
          Table table = connection.getTable(tableName)) {
          table.delete(d);
        } catch (Throwable t) {
          throw new IOException(t);
        }
        return null;
      }
    };
    SUPERUSER.runAs(actiona);

    TEST_UTIL.getAdmin().flush(tableName);
    Scan s = new Scan();
    s.readVersions(5);
    s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
    ResultScanner scanner = table.getScanner(s);
    Result[] next = scanner.next(3);
    assertTrue(next.length == 1);
    CellScanner cellScanner = next[0].cellScanner();
    cellScanner.advance();
    Cell current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row1, 0, row1.length));
    assertEquals(124L, current.getTimestamp());
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row1, 0, row1.length));
    assertEquals(123L, current.getTimestamp());
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row1, 0, row1.length));
    assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(),
      current.getQualifierLength(), qual1, 0, qual1.length));
    assertEquals(126L, current.getTimestamp());
    cellScanner.advance();
    current = cellScanner.current();
    assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(),
      row1, 0, row1.length));
    assertEquals(127L, current.getTimestamp());
    assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(),
      current.getQualifierLength(), qual2, 0, qual2.length));
  }
}
 
Example 19
Source File: TransactionProcessorTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteFiltering() throws Exception {
  String tableName = "TestDeleteFiltering";
  byte[] familyBytes = Bytes.toBytes("f");
  byte[] columnBytes = Bytes.toBytes("c");
  HRegion region = createRegion(tableName, familyBytes, 0);
  try {
    region.initialize();
    TransactionStateCache cache = new TransactionStateCacheSupplier(conf).get();
    LOG.info("Coprocessor is using transaction state: " + waitForTransactionState(cache));

    byte[] row = Bytes.toBytes(1);
    for (int i = 4; i < V.length; i++) {
      Put p = new Put(row);
      p.addColumn(familyBytes, columnBytes, V[i], Bytes.toBytes(V[i]));
      region.put(p);
    }

    // delete from the third entry back
    // take that cell's timestamp + 1 to simulate a delete in a new tx
    long deleteTs = V[5] + 1;
    Delete d = new Delete(row, deleteTs);
    LOG.info("Issuing delete at timestamp " + deleteTs);
    // row deletes are not yet supported (TransactionAwareHTable normally handles this)
    d.addColumns(familyBytes, columnBytes);
    region.delete(d);

    List<Cell> results = Lists.newArrayList();

    // force a flush to clear the data
    // during flush, we should drop the deleted version, but not the others
    LOG.info("Flushing region " + region.getRegionInfo().getRegionNameAsString());
    region.flushcache(true, false, new FlushLifeCycleTracker() { });

    // now a normal scan should return row with versions at: V[8], V[6].
    // V[7] is invalid and V[5] and prior are deleted.
    Scan scan = new Scan();
    scan.setMaxVersions(10);
    RegionScanner regionScanner = region.getScanner(scan);
    // should be only one row
    assertFalse(regionScanner.next(results));
    assertKeyValueMatches(results, 1,
        new long[]{V[8], V[6], deleteTs},
        new byte[][]{Bytes.toBytes(V[8]), Bytes.toBytes(V[6]), new byte[0]});
  } finally {
    region.close();
  }
}
 
Example 20
Source File: TestDeletion.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
@Test(timeOut = 10_000)
public void runTestDeleteColumns(ITestContext context) throws Exception {

    TransactionManager tm = newTransactionManager(context);
    TTable tt = new TTable(connection, TEST_TABLE);

    Transaction t1 = tm.begin();
    LOG.info("Transaction created " + t1);

    int rowsWritten = 10;

    FamCol famColA = new FamCol(famA, colA);
    FamCol famColB = new FamCol(famA, colB);
    writeRows(tt, t1, rowsWritten, famColA, famColB);
    tm.commit(t1);

    Transaction t2 = tm.begin();
    Delete d = new Delete(modrow);
    d.addColumns(famA, colA);
    tt.delete(t2, d);

    Transaction tscan = tm.begin();
    ResultScanner rs = tt.getScanner(tscan, new Scan());

    Map<FamCol, Integer> count = countColsInRows(rs, famColA, famColB);
    assertEquals((int) count.get(famColA), rowsWritten, "ColA count should be equal to rowsWritten");
    assertEquals((int) count.get(famColB), rowsWritten, "ColB count should be equal to rowsWritten");
    if (getClient(context).isLowLatency()) {
        return;
    }
    tm.commit(t2);

    tscan = tm.begin();
    rs = tt.getScanner(tscan, new Scan());

    count = countColsInRows(rs, famColA, famColB);

    assertEquals((int) count.get(famColA), (rowsWritten - 1), "ColA count should be equal to rowsWritten - 1");
    assertEquals((int) count.get(famColB), rowsWritten, "ColB count should be equal to rowsWritten");

}