use of org.apache.hadoop.hbase.Cell in project hbase by apache.
the class TestVisibilityLabelsWithDeletes method testDiffDeleteTypesForTheSameCellUsingMultipleVersions.
@Test
public void testDiffDeleteTypesForTheSameCellUsingMultipleVersions() throws Exception {
setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
try (Table table = doPuts(tableName)) {
// Do not flush here.
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 + ")|(" + TOPSECRET + "&" + SECRET + ")"));
d.addColumns(fam, qual, 125l);
table.delete(d);
} catch (Throwable t) {
throw new IOException(t);
}
return null;
}
};
SUPERUSER.runAs(actiona);
Scan s = new Scan();
s.setMaxVersions(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(current.getTimestamp(), 127l);
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 126l);
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 125l);
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 123l);
cellScanner = next[1].cellScanner();
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length));
// Issue 2nd delete
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("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" + TOPSECRET + "&" + SECRET + ")"));
d.addColumn(fam, qual, 127l);
table.delete(d);
} catch (Throwable t) {
throw new IOException(t);
}
return null;
}
};
SUPERUSER.runAs(actiona);
s = new Scan();
s.setMaxVersions(5);
s.setAuthorizations(new Authorizations(SECRET, PRIVATE, CONFIDENTIAL, TOPSECRET));
scanner = table.getScanner(s);
next = scanner.next(3);
assertTrue(next.length == 2);
cellScanner = next[0].cellScanner();
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 126l);
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 125l);
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 123l);
cellScanner = next[1].cellScanner();
cellScanner.advance();
current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length));
}
}
use of org.apache.hadoop.hbase.Cell in project hbase by apache.
the class TestPutDeleteEtcCellIteration method testAppendIteration.
@Test
public void testAppendIteration() throws IOException {
Append a = new Append(ROW);
for (int i = 0; i < COUNT; i++) {
byte[] bytes = Bytes.toBytes(i);
a.add(bytes, bytes, bytes);
}
int index = 0;
for (CellScanner cellScanner = a.cellScanner(); cellScanner.advance(); ) {
Cell cell = cellScanner.current();
byte[] bytes = Bytes.toBytes(index++);
KeyValue kv = (KeyValue) cell;
assertTrue(Bytes.equals(CellUtil.cloneFamily(kv), bytes));
assertTrue(Bytes.equals(CellUtil.cloneValue(kv), bytes));
}
assertEquals(COUNT, index);
}
use of org.apache.hadoop.hbase.Cell in project hbase by apache.
the class TestPutDeleteEtcCellIteration method testResultIteration.
@Test
public void testResultIteration() throws IOException {
Cell[] cells = new Cell[COUNT];
for (int i = 0; i < COUNT; i++) {
byte[] bytes = Bytes.toBytes(i);
cells[i] = new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes);
}
Result r = Result.create(Arrays.asList(cells));
int index = 0;
for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance(); ) {
Cell cell = cellScanner.current();
byte[] bytes = Bytes.toBytes(index++);
cell.equals(new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes));
}
assertEquals(COUNT, index);
}
use of org.apache.hadoop.hbase.Cell in project hbase by apache.
the class TestFilter method testFilterListWithPrefixFilter.
// HBASE-9747
@Test
public void testFilterListWithPrefixFilter() throws IOException {
byte[] family = Bytes.toBytes("f1");
byte[] qualifier = Bytes.toBytes("q1");
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
htd.addFamily(new HColumnDescriptor(family));
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
Region testRegion = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(), TEST_UTIL.getConfiguration(), htd);
for (int i = 0; i < 5; i++) {
Put p = new Put(Bytes.toBytes((char) ('a' + i) + "row"));
p.setDurability(Durability.SKIP_WAL);
p.addColumn(family, qualifier, Bytes.toBytes(String.valueOf(111 + i)));
testRegion.put(p);
}
testRegion.flush(true);
// rows starting with "b"
PrefixFilter pf = new PrefixFilter(new byte[] { 'b' });
// rows with value of column 'q1' set to '113'
SingleColumnValueFilter scvf = new SingleColumnValueFilter(family, qualifier, CompareOp.EQUAL, Bytes.toBytes("113"));
// combine these two with OR in a FilterList
FilterList filterList = new FilterList(Operator.MUST_PASS_ONE, pf, scvf);
Scan s1 = new Scan();
s1.setFilter(filterList);
InternalScanner scanner = testRegion.getScanner(s1);
List<Cell> results = new ArrayList<>();
int resultCount = 0;
while (scanner.next(results)) {
resultCount++;
byte[] row = CellUtil.cloneRow(results.get(0));
LOG.debug("Found row: " + Bytes.toStringBinary(row));
assertTrue(Bytes.equals(row, Bytes.toBytes("brow")) || Bytes.equals(row, Bytes.toBytes("crow")));
results.clear();
}
assertEquals(2, resultCount);
scanner.close();
WAL wal = ((HRegion) testRegion).getWAL();
((HRegion) testRegion).close();
wal.close();
}
use of org.apache.hadoop.hbase.Cell in project hbase by apache.
the class TestFilter method verifyScanNoEarlyOut.
private void verifyScanNoEarlyOut(Scan s, long expectedRows, long expectedKeys) throws IOException {
InternalScanner scanner = this.region.getScanner(s);
List<Cell> results = new ArrayList<>();
int i = 0;
for (boolean done = true; done; i++) {
done = scanner.next(results);
Arrays.sort(results.toArray(new Cell[results.size()]), CellComparator.COMPARATOR);
LOG.info("counter=" + i + ", " + results);
if (results.isEmpty())
break;
assertTrue("Scanned too many rows! Only expected " + expectedRows + " total but already scanned " + (i + 1), expectedRows > i);
assertEquals("Expected " + expectedKeys + " keys per row but " + "returned " + results.size(), expectedKeys, results.size());
results.clear();
}
assertEquals("Expected " + expectedRows + " rows but scanned " + i + " rows", expectedRows, i);
}
Aggregations