Search in sources :

Example 11 with Scanner

use of org.apache.phoenix.hbase.index.scanner.Scanner in project phoenix by apache.

the class LocalTableStateTest method testOnlyLoadsRequestedColumns.

@SuppressWarnings("unchecked")
@Test
public void testOnlyLoadsRequestedColumns() throws Exception {
    // setup mocks
    RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
    Region region = Mockito.mock(Region.class);
    Mockito.when(env.getRegion()).thenReturn(region);
    final KeyValue storedKv = new KeyValue(row, fam, qual, ts, Type.Put, Bytes.toBytes("stored-value"));
    storedKv.setSequenceId(2);
    Put pendingUpdate = new Put(row);
    pendingUpdate.addColumn(fam, qual, ts, val);
    HashMap<ImmutableBytesPtr, List<Cell>> rowKeyPtrToCells = new HashMap<ImmutableBytesPtr, List<Cell>>();
    rowKeyPtrToCells.put(new ImmutableBytesPtr(row), Collections.singletonList((Cell) storedKv));
    CachedLocalTable cachedLocalTable = CachedLocalTable.build(rowKeyPtrToCells);
    LocalTableState table = new LocalTableState(cachedLocalTable, pendingUpdate);
    // do the lookup for the given column
    ColumnReference col = new ColumnReference(fam, qual);
    table.setCurrentTimestamp(ts);
    // check that the value is there
    Pair<CoveredDeleteScanner, IndexUpdate> p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
    Scanner s = p.getFirst();
    // make sure it read the table the one time
    assertEquals("Didn't get the stored keyvalue!", storedKv, s.next());
    // on the second lookup it shouldn't access the underlying table again - the cached columns
    // should know they are done
    p = table.getIndexedColumnsTableState(Arrays.asList(col), false, false, indexMetaData);
    s = p.getFirst();
    assertEquals("Lost already loaded update!", storedKv, s.next());
}
Also used : CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) Scanner(org.apache.phoenix.hbase.index.scanner.Scanner) KeyValue(org.apache.hadoop.hbase.KeyValue) HashMap(java.util.HashMap) CoveredDeleteScanner(org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Put(org.apache.hadoop.hbase.client.Put) RegionCoprocessorEnvironment(org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment) Region(org.apache.hadoop.hbase.regionserver.Region) List(java.util.List) CachedLocalTable(org.apache.phoenix.hbase.index.covered.data.CachedLocalTable) Cell(org.apache.hadoop.hbase.Cell) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) Test(org.junit.Test)

Aggregations

Scanner (org.apache.phoenix.hbase.index.scanner.Scanner)11 Put (org.apache.hadoop.hbase.client.Put)10 List (java.util.List)9 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)8 Region (org.apache.hadoop.hbase.regionserver.Region)8 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)8 Test (org.junit.Test)8 KeyValue (org.apache.hadoop.hbase.KeyValue)6 CoveredDeleteScanner (org.apache.phoenix.hbase.index.scanner.ScannerBuilder.CoveredDeleteScanner)5 Configuration (org.apache.hadoop.conf.Configuration)4 Scan (org.apache.hadoop.hbase.client.Scan)4 RegionScanner (org.apache.hadoop.hbase.regionserver.RegionScanner)4 CachedLocalTable (org.apache.phoenix.hbase.index.covered.data.CachedLocalTable)4 LocalHBaseState (org.apache.phoenix.hbase.index.covered.data.LocalHBaseState)4 LocalTable (org.apache.phoenix.hbase.index.covered.data.LocalTable)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Cell (org.apache.hadoop.hbase.Cell)3 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)3