下面列出了org.apache.hadoop.hbase.client.Result#containsColumn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Map<FamCol, Integer> countColsInRows(ResultScanner rs, FamCol... famCols) throws IOException {
Map<FamCol, Integer> colCount = new HashMap<>();
Result r = rs.next();
while (r != null) {
for (FamCol col : famCols) {
if (r.containsColumn(col.fam, col.col)) {
Integer c = colCount.get(col);
if (c == null) {
colCount.put(col, 1);
} else {
colCount.put(col, c + 1);
}
}
}
r = rs.next();
}
return colCount;
}
@Override
protected void map(ImmutableBytesWritable key, Result value, Context context)
throws IOException ,InterruptedException {
byte[] rowKey = key.get();
row.set(rowKey, 0, rowKey.length);
if (multipleUnevenColumnFamilies
&& (!value.containsColumn(BIG_FAMILY_NAME, BIG_FAMILY_NAME) || !value.containsColumn(
TINY_FAMILY_NAME, TINY_FAMILY_NAME))) {
context.write(row, DEF_LOST_FAMILIES);
} else {
context.write(row, DEF);
}
byte[] prev = value.getValue(FAMILY_NAME, COLUMN_PREV);
if (prev != null && prev.length > 0) {
ref.set(prev, 0, prev.length);
context.write(ref, row);
} else {
LOG.warn(String.format("Prev is not set for: %s", Bytes.toStringBinary(rowKey)));
}
}
private static CINode getCINode(Result result, CINode node) {
node.key = Bytes.copy(result.getRow());
if (result.containsColumn(FAMILY_NAME, COLUMN_PREV)) {
node.prev = Bytes.copy(result.getValue(FAMILY_NAME, COLUMN_PREV));
} else {
node.prev = NO_KEY;
}
if (result.containsColumn(FAMILY_NAME, COLUMN_COUNT)) {
node.count = Bytes.toLong(result.getValue(FAMILY_NAME, COLUMN_COUNT));
} else {
node.count = -1;
}
if (result.containsColumn(FAMILY_NAME, COLUMN_CLIENT)) {
node.client = Bytes.toString(result.getValue(FAMILY_NAME, COLUMN_CLIENT));
} else {
node.client = "";
}
return node;
}
protected FlowEvent createEventFromResult(Result result) {
if (result == null || result.isEmpty()) {
return null;
}
FlowEventKey key = keyConverter.fromBytes(result.getRow());
FlowEvent event = new FlowEvent(key);
if (result.containsColumn(Constants.INFO_FAM_BYTES, TIMESTAMP_COL_BYTES)) {
event.setTimestamp(Bytes.toLong(
result.getValue(Constants.INFO_FAM_BYTES, TIMESTAMP_COL_BYTES)));
}
if (result.containsColumn(Constants.INFO_FAM_BYTES, TYPE_COL_BYTES)) {
event.setType(Bytes
.toString(result.getValue(Constants.INFO_FAM_BYTES, TYPE_COL_BYTES)));
}
if (result.containsColumn(Constants.INFO_FAM_BYTES,
Constants.FRAMEWORK_COLUMN_BYTES)) {
String code = Bytes.toString(result.getValue(Constants.INFO_FAM_BYTES,
Constants.FRAMEWORK_COLUMN_BYTES));
event.setFramework(Framework.get(code));
}
if (result.containsColumn(Constants.INFO_FAM_BYTES, DATA_COL_BYTES)) {
event.setEventDataJSON(Bytes
.toString(result.getValue(Constants.INFO_FAM_BYTES, DATA_COL_BYTES)));
}
return event;
}
/**
* Returns the value of a column from a Result object.
*
* @param result HBase table row
* @param column HBase column to be retrieved
* @return HBase column value
*/
byte[] getColumnValue(Result result, HBaseColumnDescriptor column) {
// if column does not contain a value, return null
if (!result.containsColumn(column.columnFamilyBytes(),
column.qualifierBytes())) {
return null;
}
// else, get the latest version of the requested column
Cell cell = result.getColumnLatestCell(column.columnFamilyBytes(), column.qualifierBytes());
return CellUtil.cloneValue(cell);
}
@Override
public long getMaxTimestamp() throws IOException {
Get get = new Get(TSO_ROW);
get.addColumn(cfName, TSO_QUALIFIER);
Result result = table.get(get);
if (result.containsColumn(cfName, TSO_QUALIFIER)) {
return Bytes.toLong(result.getValue(cfName, TSO_QUALIFIER));
} else {
// This happens for example when a new cluster is created
return INITIAL_MAX_TS_VALUE;
}
}
@Override
public Optional<Long> readCommitTimestampFromShadowCell(long startTimestamp) throws IOException {
Get get = new Get(hBaseCellId.getRow());
byte[] family = hBaseCellId.getFamily();
byte[] shadowCellQualifier = CellUtils.addShadowCellSuffixPrefix(hBaseCellId.getQualifier());
get.addColumn(family, shadowCellQualifier);
get.setMaxVersions(1);
get.setTimeStamp(startTimestamp);
Result result = tableAccessWrapper.get(get);
if (result.containsColumn(family, shadowCellQualifier)) {
return Optional.of(Bytes.toLong(result.getValue(family, shadowCellQualifier)));
}
return Optional.absent();
}
/**
* Returns true if the particular cell passed exists in the datastore.
* @param row row
* @param family column family
* @param qualifier columnn name
* @param version version
* @param cellGetter an instance of CellGetter
* @return true if the cell specified exists. false otherwise
* @throws IOException
*/
public static boolean hasCell(byte[] row,
byte[] family,
byte[] qualifier,
long version,
CellGetter cellGetter)
throws IOException {
Get get = new Get(row);
get.addColumn(family, qualifier);
get.setTimeStamp(version);
Result result = cellGetter.get(get);
return result.containsColumn(family, qualifier);
}
protected Flow createFlowFromResult(Result result) {
if (result == null || result.isEmpty()) {
return null;
}
FlowQueueKey queueKey = queueKeyConverter.fromBytes(result.getRow());
FlowKey flowKey = null;
// when flow is first being launched FlowKey may not yet be present
if (result.containsColumn(Constants.INFO_FAM_BYTES,
Constants.ROWKEY_COL_BYTES)) {
flowKey = flowKeyConverter.fromBytes(result
.getValue(Constants.INFO_FAM_BYTES, Constants.ROWKEY_COL_BYTES));
}
Flow flow = new Flow(flowKey);
flow.setQueueKey(queueKey);
if (result.containsColumn(Constants.INFO_FAM_BYTES, JOB_GRAPH_COL_BYTES)) {
flow.setJobGraphJSON(Bytes.toString(
result.getValue(Constants.INFO_FAM_BYTES, JOB_GRAPH_COL_BYTES)));
}
if (result.containsColumn(Constants.INFO_FAM_BYTES, FLOW_NAME_COL_BYTES)) {
flow.setFlowName(Bytes.toString(
result.getValue(Constants.INFO_FAM_BYTES, FLOW_NAME_COL_BYTES)));
}
if (result.containsColumn(Constants.INFO_FAM_BYTES, USER_NAME_COL_BYTES)) {
flow.setUserName(Bytes.toString(
result.getValue(Constants.INFO_FAM_BYTES, USER_NAME_COL_BYTES)));
}
if (result.containsColumn(Constants.INFO_FAM_BYTES, PROGRESS_COL_BYTES)) {
flow.setProgress(Bytes.toInt(
result.getValue(Constants.INFO_FAM_BYTES, PROGRESS_COL_BYTES)));
}
return flow;
}
private boolean containsATimestamp(Result result) {
return (result != null && result.containsColumn(commitTableFamily, COMMIT_TABLE_QUALIFIER));
}
private boolean containsInvalidTransaction(Result result) {
return (result != null && result.containsColumn(commitTableFamily, INVALID_TX_QUALIFIER));
}
private boolean containsLowWatermark(Result result) {
return (result != null && result.containsColumn(lowWatermarkFamily, LOW_WATERMARK_QUALIFIER));
}
@Override
public boolean containsTarget(Result result) {
return result.containsColumn(columnFamily, columnQualifier);
}