use of org.apache.hadoop.hbase.filter.TimestampsFilter in project hbase by apache.
the class TestAsyncTable method testCheckAndMutateWithTimestampFilter.
@Test
public void testCheckAndMutateWithTimestampFilter() throws Throwable {
AsyncTable<?> table = getTable.get();
// Put with specifying the timestamp
table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();
// Put with success
CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))).build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();
assertTrue(result.isSuccess());
assertNull(result.getResult());
Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure
result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))).build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))).get();
assertFalse(result.isSuccess());
assertNull(result.getResult());
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
}
use of org.apache.hadoop.hbase.filter.TimestampsFilter in project hbase by apache.
the class TestTimestampsFilter method getNVersions.
/**
* Uses the TimestampFilter on a Get to request a specified list of
* versions for the row/column specified by rowIdx & colIdx.
*/
private Cell[] getNVersions(Table ht, byte[] cf, int rowIdx, int colIdx, List<Long> versions) throws IOException {
byte[] row = Bytes.toBytes("row:" + rowIdx);
byte[] column = Bytes.toBytes("column:" + colIdx);
Filter filter = new TimestampsFilter(versions);
Get get = new Get(row);
get.addColumn(cf, column);
get.setFilter(filter);
get.readAllVersions();
Result result = ht.get(get);
return result.rawCells();
}
use of org.apache.hadoop.hbase.filter.TimestampsFilter in project hbase by apache.
the class TestMinVersions method testFilters.
/**
* Verify that basic filters still behave correctly with
* minimum versions enabled.
*/
@Test
public void testFilters() throws Exception {
final byte[] c1 = COLUMNS[1];
ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(c0).setMinVersions(2).setMaxVersions(1000).setTimeToLive(1).setKeepDeletedCells(KeepDeletedCells.FALSE).build();
ColumnFamilyDescriptor cfd2 = ColumnFamilyDescriptorBuilder.newBuilder(c1).setMinVersions(2).setMaxVersions(1000).setTimeToLive(1).setKeepDeletedCells(KeepDeletedCells.FALSE).build();
List<ColumnFamilyDescriptor> cfdList = new ArrayList();
cfdList.add(cfd);
cfdList.add(cfd2);
TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setColumnFamilies(cfdList).build();
HRegion region = hbu.createLocalHRegion(htd, null, null);
// 2s in the past
long ts = EnvironmentEdgeManager.currentTime() - 2000;
try {
Put p = new Put(T1, ts - 3);
p.addColumn(c0, c0, T0);
p.addColumn(c1, c1, T0);
region.put(p);
p = new Put(T1, ts - 2);
p.addColumn(c0, c0, T1);
p.addColumn(c1, c1, T1);
region.put(p);
p = new Put(T1, ts - 1);
p.addColumn(c0, c0, T2);
p.addColumn(c1, c1, T2);
region.put(p);
p = new Put(T1, ts);
p.addColumn(c0, c0, T3);
p.addColumn(c1, c1, T3);
region.put(p);
List<Long> tss = new ArrayList<>();
tss.add(ts - 1);
tss.add(ts - 2);
// Sholud only get T2, versions is 2, so T1 is gone from user view.
Get g = new Get(T1);
g.addColumn(c1, c1);
g.setFilter(new TimestampsFilter(tss));
g.readAllVersions();
Result r = region.get(g);
checkResult(r, c1, T2);
// Sholud only get T2, versions is 2, so T1 is gone from user view.
g = new Get(T1);
g.addColumn(c0, c0);
g.setFilter(new TimestampsFilter(tss));
g.readAllVersions();
r = region.get(g);
checkResult(r, c0, T2);
// now flush/compact
region.flush(true);
region.compact(true);
// After flush/compact, the result should be consistent with previous result
g = new Get(T1);
g.addColumn(c1, c1);
g.setFilter(new TimestampsFilter(tss));
g.readAllVersions();
r = region.get(g);
checkResult(r, c1, T2);
// After flush/compact, the result should be consistent with previous result
g = new Get(T1);
g.addColumn(c0, c0);
g.setFilter(new TimestampsFilter(tss));
g.readAllVersions();
r = region.get(g);
checkResult(r, c0, T2);
} finally {
HBaseTestingUtil.closeRegionAndWAL(region);
}
}
use of org.apache.hadoop.hbase.filter.TimestampsFilter in project hbase by apache.
the class TestAsyncTable method testCheckAndMutateWithTimestampFilterForOldApi.
@Test
@Deprecated
public void testCheckAndMutateWithTimestampFilterForOldApi() throws Throwable {
AsyncTable<?> table = getTable.get();
// Put with specifying the timestamp
table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();
// Put with success
boolean ok = table.checkAndMutate(row, new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))).get();
assertTrue(ok);
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure
ok = table.checkAndMutate(row, new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))).get();
assertFalse(ok);
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
}
use of org.apache.hadoop.hbase.filter.TimestampsFilter in project hbase by apache.
the class TestTimestampsFilter method scanNVersions.
/**
* Uses the TimestampFilter on a Scan to request a specified list of
* versions for the rows from startRowIdx to endRowIdx (both inclusive).
*/
private Result[] scanNVersions(Table ht, byte[] cf, int startRowIdx, int endRowIdx, List<Long> versions) throws IOException {
byte[] startRow = Bytes.toBytes("row:" + startRowIdx);
// exclusive
byte[] endRow = Bytes.toBytes("row:" + endRowIdx + 1);
Filter filter = new TimestampsFilter(versions);
Scan scan = new Scan().withStartRow(startRow).withStopRow(endRow);
scan.setFilter(filter);
scan.readAllVersions();
ResultScanner scanner = ht.getScanner(scan);
return scanner.next(endRowIdx - startRowIdx + 1);
}
Aggregations