Search in sources :

Example 56 with Scan

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));
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 57 with Scan

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();
    }
}
Also used : ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 58 with Scan

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));
    }
}
Also used : ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 59 with Scan

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);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 60 with Scan

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Connection(org.apache.hadoop.hbase.client.Connection) Scan(org.apache.hadoop.hbase.client.Scan) ByteString(com.google.protobuf.ByteString) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

Scan (org.apache.hadoop.hbase.client.Scan)950 Test (org.junit.Test)495 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)302 Result (org.apache.hadoop.hbase.client.Result)286 Cell (org.apache.hadoop.hbase.Cell)258 ArrayList (java.util.ArrayList)238 Table (org.apache.hadoop.hbase.client.Table)178 Put (org.apache.hadoop.hbase.client.Put)161 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)153 IOException (java.io.IOException)135 TableName (org.apache.hadoop.hbase.TableName)98 Delete (org.apache.hadoop.hbase.client.Delete)95 Filter (org.apache.hadoop.hbase.filter.Filter)95 KeyValue (org.apache.hadoop.hbase.KeyValue)84 Connection (org.apache.hadoop.hbase.client.Connection)81 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)78 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)78 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)72 Configuration (org.apache.hadoop.conf.Configuration)51 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)51