Search in sources :

Example 76 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class TestMobStoreScanner method testGetReferences.

private void testGetReferences(boolean reversed) throws Exception {
    TableName tn = TableName.valueOf("testGetReferences" + reversed);
    setUp(defaultThreshold, tn);
    long ts1 = System.currentTimeMillis();
    long ts2 = ts1 + 1;
    long ts3 = ts1 + 2;
    byte[] value = generateMobValue((int) defaultThreshold + 1);
    ;
    Put put1 = new Put(row1);
    put1.addColumn(family, qf1, ts3, value);
    put1.addColumn(family, qf2, ts2, value);
    put1.addColumn(family, qf3, ts1, value);
    table.put(put1);
    admin.flush(tn);
    Scan scan = new Scan();
    setScan(scan, reversed, true);
    ResultScanner results = table.getScanner(scan);
    int count = 0;
    for (Result res : results) {
        List<Cell> cells = res.listCells();
        for (Cell cell : cells) {
            // Verify the value
            assertIsMobReference(cell, row1, family, value, tn);
            count++;
        }
    }
    results.close();
    Assert.assertEquals(3, count);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result)

Example 77 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class TestJoinedScanners method runScanner.

private void runScanner(Table table, boolean slow) throws Exception {
    long time = System.nanoTime();
    Scan scan = new Scan();
    scan.addColumn(cf_essential, col_name);
    scan.addColumn(cf_joined, col_name);
    SingleColumnValueFilter filter = new SingleColumnValueFilter(cf_essential, col_name, CompareFilter.CompareOp.EQUAL, flag_yes);
    filter.setFilterIfMissing(true);
    scan.setFilter(filter);
    scan.setLoadColumnFamiliesOnDemand(!slow);
    ResultScanner result_scanner = table.getScanner(scan);
    Result res;
    long rows_count = 0;
    while ((res = result_scanner.next()) != null) {
        rows_count++;
    }
    double timeSec = (System.nanoTime() - time) / 1000000000.0;
    result_scanner.close();
    LOG.info((slow ? "Slow" : "Joined") + " scanner finished in " + Double.toString(timeSec) + " seconds, got " + Long.toString(rows_count / 2) + " rows");
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) Result(org.apache.hadoop.hbase.client.Result)

Example 78 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class TestMobStoreScanner method testReadPt.

@Test
public void testReadPt() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    setUp(0L, tableName);
    long ts = System.currentTimeMillis();
    byte[] value1 = Bytes.toBytes("value1");
    Put put1 = new Put(row1);
    put1.addColumn(family, qf1, ts, value1);
    table.put(put1);
    Put put2 = new Put(row2);
    byte[] value2 = Bytes.toBytes("value2");
    put2.addColumn(family, qf1, ts, value2);
    table.put(put2);
    Scan scan = new Scan();
    scan.setCaching(1);
    ResultScanner rs = table.getScanner(scan);
    Result result = rs.next();
    Put put3 = new Put(row1);
    byte[] value3 = Bytes.toBytes("value3");
    put3.addColumn(family, qf1, ts, value3);
    table.put(put3);
    Put put4 = new Put(row2);
    byte[] value4 = Bytes.toBytes("value4");
    put4.addColumn(family, qf1, ts, value4);
    table.put(put4);
    Cell cell = result.getColumnLatestCell(family, qf1);
    Assert.assertArrayEquals(value1, CellUtil.cloneValue(cell));
    admin.flush(tableName);
    result = rs.next();
    cell = result.getColumnLatestCell(family, qf1);
    Assert.assertArrayEquals(value2, CellUtil.cloneValue(cell));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 79 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class TestMobStoreScanner method testMobThreshold.

private void testMobThreshold(boolean reversed) throws Exception {
    TableName tn = TableName.valueOf("testMobThreshold" + reversed);
    setUp(defaultThreshold, tn);
    byte[] valueLess = generateMobValue((int) defaultThreshold - 1);
    byte[] valueEqual = generateMobValue((int) defaultThreshold);
    byte[] valueGreater = generateMobValue((int) defaultThreshold + 1);
    long ts1 = System.currentTimeMillis();
    long ts2 = ts1 + 1;
    long ts3 = ts1 + 2;
    Put put1 = new Put(row1);
    put1.addColumn(family, qf1, ts3, valueLess);
    put1.addColumn(family, qf2, ts2, valueEqual);
    put1.addColumn(family, qf3, ts1, valueGreater);
    table.put(put1);
    admin.flush(tn);
    Scan scan = new Scan();
    setScan(scan, reversed, true);
    Cell cellLess = null;
    Cell cellEqual = null;
    Cell cellGreater = null;
    ResultScanner results = table.getScanner(scan);
    int count = 0;
    for (Result res : results) {
        List<Cell> cells = res.listCells();
        for (Cell cell : cells) {
            // Verify the value
            String qf = Bytes.toString(CellUtil.cloneQualifier(cell));
            if (qf.equals(Bytes.toString(qf1))) {
                cellLess = cell;
            }
            if (qf.equals(Bytes.toString(qf2))) {
                cellEqual = cell;
            }
            if (qf.equals(Bytes.toString(qf3))) {
                cellGreater = cell;
            }
            count++;
        }
    }
    Assert.assertEquals(3, count);
    assertNotMobReference(cellLess, row1, family, valueLess);
    assertNotMobReference(cellEqual, row1, family, valueEqual);
    assertIsMobReference(cellGreater, row1, family, valueGreater, tn);
    results.close();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result)

Example 80 with ResultScanner

use of org.apache.hadoop.hbase.client.ResultScanner in project hbase by apache.

the class TestScannerWithCorruptHFile method scan.

private void scan(Table table) throws IOException {
    Scan scan = new Scan();
    scan.setCaching(1);
    scan.setCacheBlocks(false);
    ResultScanner scanner = table.getScanner(scan);
    try {
        scanner.next();
    } finally {
        scanner.close();
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan)

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