Search in sources :

Example 81 with CellScanner

use of org.apache.hadoop.hbase.CellScanner in project phoenix by apache.

the class IndexIT method assertNoIndexDeletes.

private void assertNoIndexDeletes(Connection conn, long minTimestamp, String fullIndexName) throws IOException, SQLException {
    if (!this.mutable) {
        PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
        PTable index = pconn.getTable(new PTableKey(null, fullIndexName));
        byte[] physicalIndexTable = index.getPhysicalName().getBytes();
        try (HTableInterface hIndex = pconn.getQueryServices().getTable(physicalIndexTable)) {
            Scan scan = new Scan();
            scan.setRaw(true);
            if (this.transactional) {
                minTimestamp = TransactionUtil.convertToNanoseconds(minTimestamp);
            }
            scan.setTimeRange(minTimestamp, HConstants.LATEST_TIMESTAMP);
            ResultScanner scanner = hIndex.getScanner(scan);
            Result result;
            while ((result = scanner.next()) != null) {
                CellScanner cellScanner = result.cellScanner();
                while (cellScanner.advance()) {
                    Cell current = cellScanner.current();
                    assertEquals(KeyValue.Type.Put.getCode(), current.getTypeByte());
                }
            }
        }
        ;
    }
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) PTableKey(org.apache.phoenix.schema.PTableKey) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) CellScanner(org.apache.hadoop.hbase.CellScanner) Cell(org.apache.hadoop.hbase.Cell) PTable(org.apache.phoenix.schema.PTable) Result(org.apache.hadoop.hbase.client.Result)

Example 82 with CellScanner

use of org.apache.hadoop.hbase.CellScanner in project phoenix by apache.

the class StatisticsUtil method readStatistics.

public static GuidePostsInfo readStatistics(HTableInterface statsHTable, GuidePostsKey key, long clientTimeStamp) throws IOException {
    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
    ptr.set(key.getColumnFamily());
    byte[] tableNameBytes = key.getPhysicalName();
    byte[] startKey = getStartKey(tableNameBytes, ptr);
    byte[] endKey = getEndKey(tableNameBytes, ptr);
    Scan s = MetaDataUtil.newTableRowsScan(startKey, endKey, MetaDataProtocol.MIN_TABLE_TIMESTAMP, clientTimeStamp);
    s.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
    s.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES);
    s.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES);
    GuidePostsInfoBuilder guidePostsInfoWriter = new GuidePostsInfoBuilder();
    Cell current = null;
    try (ResultScanner scanner = statsHTable.getScanner(s)) {
        Result result = null;
        while ((result = scanner.next()) != null) {
            CellScanner cellScanner = result.cellScanner();
            long rowCount = 0;
            long byteCount = 0;
            while (cellScanner.advance()) {
                current = cellScanner.current();
                if (Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), current.getQualifierLength(), PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES, 0, PhoenixDatabaseMetaData.GUIDE_POSTS_ROW_COUNT_BYTES.length)) {
                    rowCount = PLong.INSTANCE.getCodec().decodeLong(current.getValueArray(), current.getValueOffset(), SortOrder.getDefault());
                } else if (Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), current.getQualifierLength(), PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES, 0, PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES.length)) {
                    byteCount = PLong.INSTANCE.getCodec().decodeLong(current.getValueArray(), current.getValueOffset(), SortOrder.getDefault());
                }
            }
            if (current != null) {
                int tableNameLength = tableNameBytes.length + 1;
                int cfOffset = current.getRowOffset() + tableNameLength;
                int cfLength = getVarCharLength(current.getRowArray(), cfOffset, current.getRowLength() - tableNameLength);
                ptr.set(current.getRowArray(), cfOffset, cfLength);
                byte[] cfName = ByteUtil.copyKeyBytesIfNecessary(ptr);
                byte[] newGPStartKey = getGuidePostsInfoFromRowKey(tableNameBytes, cfName, result.getRow());
                guidePostsInfoWriter.addGuidePosts(newGPStartKey, byteCount, rowCount);
            }
        }
    }
    // for any guideposts. If we have no rows, it means stats were never generated.
    return current == null ? GuidePostsInfo.NO_GUIDEPOST : guidePostsInfoWriter.isEmpty() ? GuidePostsInfo.EMPTY_GUIDEPOST : guidePostsInfoWriter.build();
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) CellScanner(org.apache.hadoop.hbase.CellScanner) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

CellScanner (org.apache.hadoop.hbase.CellScanner)82 Cell (org.apache.hadoop.hbase.Cell)69 Test (org.junit.Test)58 Result (org.apache.hadoop.hbase.client.Result)47 Scan (org.apache.hadoop.hbase.client.Scan)43 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)42 Table (org.apache.hadoop.hbase.client.Table)41 IOException (java.io.IOException)40 TableName (org.apache.hadoop.hbase.TableName)40 InterruptedIOException (java.io.InterruptedIOException)35 Connection (org.apache.hadoop.hbase.client.Connection)34 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)32 Delete (org.apache.hadoop.hbase.client.Delete)32 Put (org.apache.hadoop.hbase.client.Put)15 KeyValue (org.apache.hadoop.hbase.KeyValue)14 ArrayList (java.util.ArrayList)10 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)7 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)5