use of org.apache.hadoop.hbase.client.Scan in project hbase by apache.
the class TestStoreScanner method testDeletedRowThenGoodRow.
/*
* Test the case where there is a delete row 'in front of' the next row, the scanner
* will move to the next row.
*/
@Test
public void testDeletedRowThenGoodRow() throws IOException {
KeyValue[] kvs = new KeyValue[] { KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"), KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"), KeyValueTestUtil.create("R2", "cf", "a", 20, KeyValue.Type.Put, "dont-care") };
List<KeyValueScanner> scanners = scanFixture(kvs);
Scan scanSpec = new Scan(Bytes.toBytes("R1"));
try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, scanType, getCols("a"), scanners)) {
List<Cell> results = new ArrayList<>();
Assert.assertEquals(true, scan.next(results));
Assert.assertEquals(0, results.size());
Assert.assertEquals(true, scan.next(results));
Assert.assertEquals(1, results.size());
Assert.assertEquals(kvs[2], results.get(0));
Assert.assertEquals(false, scan.next(results));
}
}
use of org.apache.hadoop.hbase.client.Scan in project hbase by apache.
the class TestStoreScanner method testOptimize.
/**
* Test optimize in StoreScanner. Test that we skip to the next 'block' when we it makes sense
* reading the block 'index'.
* @throws IOException
*/
@Test
public void testOptimize() throws IOException {
Scan scan = new Scan();
// A scan that just gets the first qualifier on each row of the CELL_GRID
scan.addColumn(CF, ONE);
CellGridStoreScanner scanner = new CellGridStoreScanner(scan, this.scanInfo, this.scanType);
try {
List<Cell> results = new ArrayList<>();
while (scanner.next(results)) {
continue;
}
// Should be four results of column 1 (though there are 5 rows in the CELL_GRID -- the
// TWO_POINT_TWO row does not have a a column ONE.
Assert.assertEquals(4, results.size());
for (Cell cell : results) {
assertTrue(Bytes.equals(ONE, 0, ONE.length, cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()));
}
Assert.assertTrue("Optimize should do some optimizations", scanner.optimization.get() > 0);
} finally {
scanner.close();
}
}
use of org.apache.hadoop.hbase.client.Scan in project hbase by apache.
the class TestStoreScanner method testSkipColumn.
@Test
public void testSkipColumn() throws IOException {
List<KeyValueScanner> scanners = scanFixture(kvs);
try (StoreScanner scan = new StoreScanner(new Scan(), scanInfo, scanType, getCols("a", "d"), scanners)) {
List<Cell> results = new ArrayList<>();
Assert.assertEquals(true, scan.next(results));
Assert.assertEquals(2, results.size());
Assert.assertEquals(kvs[0], results.get(0));
Assert.assertEquals(kvs[3], results.get(1));
results.clear();
Assert.assertEquals(true, scan.next(results));
Assert.assertEquals(1, results.size());
Assert.assertEquals(kvs[kvs.length - 1], results.get(0));
results.clear();
Assert.assertEquals(false, scan.next(results));
}
}
use of org.apache.hadoop.hbase.client.Scan in project hbase by apache.
the class TestWithDisabledAuthorization method testPassiveVisibility.
@Test(timeout = 180000)
public void testPassiveVisibility() throws Exception {
// No values should be filtered regardless of authorization if we are passive
try (Table t = createTableAndWriteDataWithLabels(TableName.valueOf(TEST_NAME.getMethodName()), SECRET, PRIVATE, SECRET + "|" + CONFIDENTIAL, PRIVATE + "|" + CONFIDENTIAL)) {
Scan s = new Scan();
s.setAuthorizations(new Authorizations());
try (ResultScanner scanner = t.getScanner(s)) {
Result[] next = scanner.next(10);
assertEquals(next.length, 4);
}
s = new Scan();
s.setAuthorizations(new Authorizations(SECRET));
try (ResultScanner scanner = t.getScanner(s)) {
Result[] next = scanner.next(10);
assertEquals(next.length, 4);
}
s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
try (ResultScanner scanner = t.getScanner(s)) {
Result[] next = scanner.next(10);
assertEquals(next.length, 4);
}
s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE));
try (ResultScanner scanner = t.getScanner(s)) {
Result[] next = scanner.next(10);
assertEquals(next.length, 4);
}
}
}
use of org.apache.hadoop.hbase.client.Scan in project hbase by apache.
the class TestVisibilityLabelsWithACL method testScanForUserWithFewerLabelAuthsThanLabelsInScanAuthorizations.
@Test
public void testScanForUserWithFewerLabelAuthsThanLabelsInScanAuthorizations() throws Throwable {
String[] auths = { SECRET };
String user = "user2";
VisibilityClient.setAuths(TEST_UTIL.getConnection(), auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL + "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER2.getShortName(), tableName, null, null, Permission.Action.READ);
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception {
Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
try (Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(table.getName())) {
ResultScanner scanner = t.getScanner(s);
Result result = scanner.next();
assertTrue(!result.isEmpty());
assertTrue(Bytes.equals(Bytes.toBytes("row2"), result.getRow()));
result = scanner.next();
assertNull(result);
}
return null;
}
};
NORMAL_USER2.runAs(scanAction);
}
Aggregations