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());
}
}
}
;
}
}
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();
}
Aggregations