private RowMutations makeRowMutationsWithColumnCDeleted() throws IOException { RowMutations rm = new RowMutations(ROWKEY, 2); Put put = new Put(ROWKEY); put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")); put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")); rm.add(put); Delete del = new Delete(ROWKEY); del.addColumn(FAMILY, Bytes.toBytes("C")); rm.add(del); return rm; }
@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)); }
private boolean doCheckAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value, Delete delete) throws IOException { Put put = new Put(row); put.setFamilyCellMap(delete.getFamilyCellMap()); put.add(new KeyValue(row, family, qualifier, value)); CellSetModel model = buildModelFromPut(put); StringBuilder sb = new StringBuilder(); sb.append('/'); sb.append(Bytes.toString(name)); sb.append('/'); sb.append(toURLEncodedBytes(row));
/** * Prepare a delete for a row mutation processor * @param delete The passed delete is modified by this method. WARNING! * @throws IOException */ public void prepareDelete(Delete delete) throws IOException { // Check to see if this is a deleteRow insert if(delete.getFamilyCellMap().isEmpty()){ for(byte [] family : this.htableDescriptor.getColumnFamilyNames()){ // Don't eat the timestamp delete.addFamily(family, delete.getTimestamp()); } } else { for(byte [] family : delete.getFamilyCellMap().keySet()) { if(family == null) { throw new NoSuchColumnFamilyException("Empty family is invalid"); } checkFamily(family, delete.getDurability()); } } }
@Override public void delete(Delete delete) throws IOException { String spec = buildRowSpec(delete.getRow(), delete.getFamilyCellMap(), delete.getTimestamp(), delete.getTimestamp(), 1); for (int i = 0; i < maxRetries; i++) { Response response = client.delete(spec); int code = response.getCode(); switch (code) { case 200: return; case 509: try { Thread.sleep(sleepTime); } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); } break; default: throw new IOException("delete request failed with " + code); } } throw new IOException("delete request timed out"); }
@Test public void testPutAndDeleteVersions() throws IOException { try (Table t = createTable()) { t.put(new Put(ROW).addColumn(FAMILY, col1, 1000001, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000002, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000003, value)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000004, value)); t.delete(new Delete(ROW).addColumns(FAMILY, col1, 2000000)); t.put(new Put(ROW).addColumn(FAMILY, col1, 1000000, value)); TEST_UTIL.getAdmin().flush(t.getName()); Result r = t.get(new Get(ROW).setMaxVersions(3)); assertEquals(1, r.size()); assertEquals(1000000, r.rawCells()[0].getTimestamp()); } }
@Test public void testDeleteWithNoVisibilitiesForPutsAndDeletes() throws Exception { TableName tableName = createTable(5); Put p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual, value); Table table = TEST_UTIL.getConnection().getTable(tableName); table.put(p); p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual1, value); table.put(p); p = new Put(Bytes.toBytes("row2")); p.addColumn(fam, qual, value); table.put(p); p = new Put(Bytes.toBytes("row2")); p.addColumn(fam, qual1, value); table.put(p); Delete d = new Delete(Bytes.toBytes("row1")); table.delete(d); Get g = new Get(Bytes.toBytes("row1")); g.readAllVersions(); g.setAuthorizations(new Authorizations(SECRET, PRIVATE)); Result result = table.get(g); assertEquals(0, result.rawCells().length); p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual, value); table.put(p); result = table.get(g); assertEquals(1, result.rawCells().length); }
@Override public Object run() throws Exception { Delete d = new Delete(TEST_ROW); d.addColumn(family1, qualifier); // d.deleteFamily(family1); try (Connection conn = ConnectionFactory.createConnection(conf); Table t = conn.getTable(tableName)) { t.delete(d); } return null; } };
@Test public void testBatchWithIncrementAndAppend() throws Exception { LOG.info("test=testBatchWithIncrementAndAppend"); final byte[] QUAL1 = Bytes.toBytes("qual1"); final byte[] QUAL2 = Bytes.toBytes("qual2"); final byte[] QUAL3 = Bytes.toBytes("qual3"); final byte[] QUAL4 = Bytes.toBytes("qual4"); Table table = UTIL.getConnection().getTable(TEST_TABLE); Delete d = new Delete(ONE_ROW); table.delete(d); Put put = new Put(ONE_ROW); put.addColumn(BYTES_FAMILY, QUAL1, Bytes.toBytes("abc")); put.addColumn(BYTES_FAMILY, QUAL2, Bytes.toBytes(1L)); table.put(put); table.batch(actions, multiRes); validateResult(multiRes[1], QUAL1, Bytes.toBytes("abcdef")); validateResult(multiRes[1], QUAL4, Bytes.toBytes("xyz"));
private void fillTable() throws IOException, InterruptedException { Table table = TEST_UTIL.createTable(TABLE_NAME, FAMILIES, 3, Bytes.toBytes("row0"), Bytes.toBytes("row99"), NUM_RS); Random rand = new Random(19387129L); for (int iStoreFile = 0; iStoreFile < 4; ++iStoreFile) { for (int iRow = 0; iRow < 100; ++iRow) { final byte[] row = Bytes.toBytes("row" + iRow); Put put = new Put(row); Delete del = new Delete(row); for (int iCol = 0; iCol < 10; ++iCol) { final byte[] cf = rand.nextBoolean() ? CF1 : CF2; final long ts = Math.abs(rand.nextInt()); final byte[] qual = Bytes.toBytes("col" + iCol); if (rand.nextBoolean()) { final byte[] value = Bytes.toBytes("value_for_row_" + iRow + "_cf_" + Bytes.toStringBinary(cf) + "_col_" + iCol + "_ts_" + ts + "_random_" + rand.nextLong()); put.addColumn(cf, qual, ts, value); } else if (rand.nextDouble() < 0.8) { del.addColumn(cf, qual, ts); } else { del.addColumn(cf, qual, ts); } } table.put(put); table.delete(del); } } TEST_UTIL.waitUntilAllRegionsAssigned(TABLE_NAME); }
@Test public void testMultiPut() throws Exception { List<Put> puts = IntStream.range(0, 10) .mapToObj(i -> new Put(ROW).addColumn(FAMILY, Bytes.toBytes(i), VALUE)) .collect(Collectors.toList()); table.put(puts); assertResult(table.get(new Get(ROW)), VALUE); assertObserverHasExecuted(); List<Delete> deletes = IntStream.range(0, 10) .mapToObj(i -> new Delete(ROW).addColumn(FAMILY, Bytes.toBytes(i))) .collect(Collectors.toList()); table.delete(deletes); assertTrue(table.get(new Get(ROW)).isEmpty()); assertObserverHasExecuted(); }
@Test public void testCheckAndDeleteHooks() throws IOException { final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName()); Table table = util.createTable(tableName, new byte[][] { A, B, C }); try { Put p = new Put(Bytes.toBytes(0)); p.addColumn(A, A, A); table.put(p); Delete d = new Delete(Bytes.toBytes(0)); table.delete(d); verifyMethodResult( SimpleRegionObserver.class, new String[] { "hadPreCheckAndDelete", "hadPreCheckAndDeleteAfterRowLock", "hadPostCheckAndDelete" }, tableName, new Boolean[] { false, false, false }); table.checkAndMutate(Bytes.toBytes(0), A).qualifier(A).ifEquals(A).thenDelete(d); verifyMethodResult( SimpleRegionObserver.class, new String[] { "hadPreCheckAndDelete", "hadPreCheckAndDeleteAfterRowLock", "hadPostCheckAndDelete" }, tableName, new Boolean[] { true, true, true }); } finally { util.deleteTable(tableName); table.close(); } }
@Test public void testDeleteCell() throws Exception { createTable(TestDeleteCellCoprocessor.class.getName()); try (Table t = util.getConnection().getTable(tableName)) { t.put(Lists.newArrayList( new Put(row1).addColumn(test, dummy, dummy), new Put(row2).addColumn(test, dummy, dummy), new Put(row3).addColumn(test, dummy, dummy) )); assertRowCount(t, 3); t.delete(new Delete(test).addColumn(test, dummy)); // delete non-existing row assertRowCount(t, 1); } }
@Test public void testCheckAndDelete() throws IOException { final byte [] value1 = Bytes.toBytes("aaaa"); Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY); Put put = new Put(ROW); put.addColumn(FAMILY, QUALIFIER, value1); table.put(put); Delete delete = new Delete(ROW); delete.addColumns(FAMILY, QUALIFIER); boolean ok = table.checkAndMutate(ROW, FAMILY).qualifier(QUALIFIER) .ifEquals(value1).thenDelete(delete); assertTrue(ok); }
Put put = new Put(Bytes.toBytes("row1")); put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), Bytes.toBytes("val1")); put.add(Bytes.toBytes("colfam2"), Bytes.toBytes("qual2"), Bytes.toBytes("val2")); table.put(put); System.out.println("Value only: " + Bytes.toString(val)); Delete delete = new Delete(Bytes.toBytes("row1")); delete.deleteColumns(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1")); table.delete(delete);
Delete d = new Delete(key); compat.setTimestamp(d, delTimestamp); commands.setSecond(d); commands.getSecond().deleteColumns(cfName, b.as(StaticBuffer.ARRAY_FACTORY), delTimestamp); Put p = new Put(key, putTimestamp); commands.setFirst(p); commands.getFirst().add(cfName, e.getColumnAs(StaticBuffer.ARRAY_FACTORY), putTimestamp,
Put p = new Put(PK); byte[] v1 = Bytes.toBytes("v1"); KeyValue kv = new KeyValue(PK, FAMILY, QUAL, 1, v1); kvs.add(kv); p.add(kv); byte[] v2 = Bytes.toBytes("v2"); kv = new KeyValue(PK, Bytes.toBytes("family2"), QUAL, 1, v2); kvs.add(kv); p.add(kv); Delete d = new Delete(PK, 2); d.deleteFamily(FAMILY, 2); assertArrayEquals("Didn't get expected index value", expected, m.getRow()); d = new Delete(PK, 2); d.deleteColumns(FAMILY, QUAL, 2); ensureNoUpdatesWhenCoveredByDelete(env, codec, kvs, d); d = new Delete(PK, 1); d.deleteColumn(FAMILY, QUAL, 1); ensureNoUpdatesWhenCoveredByDelete(env, codec, kvs, d);
public void testCheckAndDelete(Connection connection, String tableName) throws IOException { createTable(thriftAdmin, tableName); try (Table table = connection.getTable(TableName.valueOf(tableName))){ Get get = new Get(ROW_1); Result result = table.get(get); byte[] value1 = result.getValue(FAMILYA, QUALIFIER_1); byte[] value2 = result.getValue(FAMILYB, QUALIFIER_2); assertNotNull(value1); assertTrue(Bytes.equals(VALUE_1, value1)); assertNull(value2); assertTrue(table.exists(get)); assertEquals(1, table.existsAll(Collections.singletonList(get)).length); Delete delete = new Delete(ROW_1); table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenDelete(delete); assertFalse(table.exists(get)); Put put = new Put(ROW_1); put.addColumn(FAMILYA, QUALIFIER_1, VALUE_1); table.put(put); assertTrue(table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1) .ifEquals(VALUE_1).thenPut(put)); assertFalse(table.checkAndMutate(ROW_1, FAMILYA).qualifier(QUALIFIER_1) .ifEquals(VALUE_2).thenPut(put)); } }