Search in sources :

Example 46 with ResultScanner

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();
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(org.apache.hadoop.hbase.client.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableName(org.apache.hadoop.hbase.TableName) Scan(org.apache.hadoop.hbase.client.Scan) Test(org.junit.Test)

Example 47 with ResultScanner

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

Example 48 with ResultScanner

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

Example 49 with ResultScanner

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

Example 50 with ResultScanner

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

Aggregations

ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)342 Scan (org.apache.hadoop.hbase.client.Scan)303 Result (org.apache.hadoop.hbase.client.Result)302 Table (org.apache.hadoop.hbase.client.Table)164 Test (org.junit.Test)152 Cell (org.apache.hadoop.hbase.Cell)106 IOException (java.io.IOException)102 TableName (org.apache.hadoop.hbase.TableName)89 Delete (org.apache.hadoop.hbase.client.Delete)79 Connection (org.apache.hadoop.hbase.client.Connection)77 Put (org.apache.hadoop.hbase.client.Put)75 ArrayList (java.util.ArrayList)71 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)47 InterruptedIOException (java.io.InterruptedIOException)46 CellScanner (org.apache.hadoop.hbase.CellScanner)42 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 HTable (org.apache.hadoop.hbase.client.HTable)29 Admin (org.apache.hadoop.hbase.client.Admin)24 Get (org.apache.hadoop.hbase.client.Get)23