use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestVisibilityLabelsWithDeletes method testVisibilityLabelsWithDeleteColumnWithSpecificVersionWithPutsReAppearing.
@Test
public void testVisibilityLabelsWithDeleteColumnWithSpecificVersionWithPutsReAppearing() throws Exception {
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Admin hBaseAdmin = TEST_UTIL.getAdmin();
HColumnDescriptor colDesc = new HColumnDescriptor(fam);
colDesc.setMaxVersions(5);
HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(colDesc);
hBaseAdmin.createTable(desc);
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
Put put1 = new Put(Bytes.toBytes("row1"));
put1.addColumn(fam, qual, 123l, value);
put1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
Put put2 = new Put(Bytes.toBytes("row1"));
put2.addColumn(fam, qual, 123l, value1);
put2.setCellVisibility(new CellVisibility(SECRET));
table.put(createList(put1, put2));
Scan s = new Scan();
s.setMaxVersions(5);
s.setAuthorizations(new Authorizations(CONFIDENTIAL, SECRET));
ResultScanner scanner = table.getScanner(s);
assertEquals(scanner.next(3).length, 1);
scanner.close();
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(CONFIDENTIAL));
d.addColumn(fam, qual, 123l);
table.delete(d);
}
try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET));
d.addColumn(fam, qual, 123l);
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(CONFIDENTIAL));
scanner = table.getScanner(s);
assertEquals(scanner.next(3).length, 0);
scanner.close();
}
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestFilterListOrOperatorWithBlkCnt method getScanResult.
private List<Cell> getScanResult(byte[] startRow, byte[] stopRow, Table ht) throws IOException {
Scan scan = new Scan();
scan.setMaxVersions();
if (!Bytes.toString(startRow).isEmpty()) {
scan.setStartRow(startRow);
}
if (!Bytes.toString(stopRow).isEmpty()) {
scan.setStopRow(stopRow);
}
ResultScanner scanner = ht.getScanner(scan);
List<Cell> kvList = new ArrayList<>();
Result r;
while ((r = scanner.next()) != null) {
for (Cell kv : r.listCells()) {
kvList.add(kv);
}
}
return kvList;
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestFilterWrapper method testFilterWrapper.
@Test
public void testFilterWrapper() {
int kv_number = 0;
int row_number = 0;
try {
Scan scan = new Scan();
List<Filter> fs = new ArrayList<>();
DependentColumnFilter f1 = new DependentColumnFilter(Bytes.toBytes("f1"), Bytes.toBytes("c5"), true, CompareFilter.CompareOp.EQUAL, new SubstringComparator("c5"));
PageFilter f2 = new PageFilter(2);
fs.add(f1);
fs.add(f2);
FilterList filter = new FilterList(fs);
scan.setFilter(filter);
Table table = connection.getTable(name);
ResultScanner scanner = table.getScanner(scan);
// row2 (c1-c4) and row3(c1-c4) are returned
for (Result result : scanner) {
row_number++;
for (Cell kv : result.listCells()) {
LOG.debug(kv_number + ". kv: " + kv);
kv_number++;
assertEquals("Returned row is not correct", new String(CellUtil.cloneRow(kv)), "row" + (row_number + 1));
}
}
scanner.close();
table.close();
} catch (Exception e) {
// no correct result is expected
assertNull("Exception happens in scan", e);
}
LOG.debug("check the fetched kv number");
assertEquals("We should get 8 results returned.", 8, kv_number);
assertEquals("We should get 2 rows returned", 2, row_number);
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestColumnRangeFilter method TestColumnRangeFilterClient.
@Test
public void TestColumnRangeFilterClient() throws Exception {
String family = "Family";
Table ht = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()), Bytes.toBytes(family), Integer.MAX_VALUE);
List<String> rows = generateRandomWords(10, 8);
long maxTimestamp = 2;
List<String> columns = generateRandomWords(20000, 8);
List<KeyValue> kvList = new ArrayList<>();
Map<StringRange, List<KeyValue>> rangeMap = new HashMap<>();
rangeMap.put(new StringRange(null, true, "b", false), new ArrayList<>());
rangeMap.put(new StringRange("p", true, "q", false), new ArrayList<>());
rangeMap.put(new StringRange("r", false, "s", true), new ArrayList<>());
rangeMap.put(new StringRange("z", false, null, false), new ArrayList<>());
String valueString = "ValueString";
for (String row : rows) {
Put p = new Put(Bytes.toBytes(row));
p.setDurability(Durability.SKIP_WAL);
for (String column : columns) {
for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
KeyValue kv = KeyValueTestUtil.create(row, family, column, timestamp, valueString);
p.add(kv);
kvList.add(kv);
for (StringRange s : rangeMap.keySet()) {
if (s.inRange(column)) {
rangeMap.get(s).add(kv);
}
}
}
}
ht.put(p);
}
TEST_UTIL.flush();
ColumnRangeFilter filter;
Scan scan = new Scan();
scan.setMaxVersions();
for (StringRange s : rangeMap.keySet()) {
filter = new ColumnRangeFilter(s.getStart() == null ? null : Bytes.toBytes(s.getStart()), s.isStartInclusive(), s.getEnd() == null ? null : Bytes.toBytes(s.getEnd()), s.isEndInclusive());
scan.setFilter(filter);
ResultScanner scanner = ht.getScanner(scan);
List<Cell> results = new ArrayList<>();
LOG.info("scan column range: " + s.toString());
long timeBeforeScan = System.currentTimeMillis();
Result result;
while ((result = scanner.next()) != null) {
for (Cell kv : result.listCells()) {
results.add(kv);
}
}
long scanTime = System.currentTimeMillis() - timeBeforeScan;
scanner.close();
LOG.info("scan time = " + scanTime + "ms");
LOG.info("found " + results.size() + " results");
LOG.info("Expecting " + rangeMap.get(s).size() + " results");
/*
for (KeyValue kv : results) {
LOG.info("found row " + Bytes.toString(kv.getRow()) + ", column "
+ Bytes.toString(kv.getQualifier()));
}
*/
assertEquals(rangeMap.get(s).size(), results.size());
}
ht.close();
}
use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.
the class TestRegionObserverInterface method testHBASE14489.
@Test(timeout = 300000)
public void testHBASE14489() throws IOException {
final TableName tableName = TableName.valueOf(name.getMethodName());
Table table = util.createTable(tableName, new byte[][] { A });
Put put = new Put(ROW);
put.addColumn(A, A, A);
table.put(put);
Scan s = new Scan();
s.setFilter(new FilterAllFilter());
ResultScanner scanner = table.getScanner(s);
try {
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
}
} finally {
scanner.close();
}
verifyMethodResult(SimpleRegionObserver.class, new String[] { "wasScannerFilterRowCalled" }, tableName, new Boolean[] { true });
util.deleteTable(tableName);
table.close();
}
Aggregations