Java Code Examples for org.apache.hadoop.hbase.client.Result#containsColumn()

The following examples show how to use org.apache.hadoop.hbase.client.Result#containsColumn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDeletion.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: IntegrationTestBigLinkedList.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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)));
  }
}
 
Example 3
Source File: IntegrationTestBigLinkedList.java    From hbase with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: FlowEventService.java    From hraven with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 5
Source File: HBaseResolver.java    From pxf with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: HBaseTimestampStorage.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@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;
    }

}
 
Example 7
Source File: HBaseTransactionManager.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: CellUtils.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: FlowQueueService.java    From hraven with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: HBaseCommitTable.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
private boolean containsATimestamp(Result result) {
    return (result != null && result.containsColumn(commitTableFamily, COMMIT_TABLE_QUALIFIER));
}
 
Example 11
Source File: HBaseCommitTable.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
private boolean containsInvalidTransaction(Result result) {
    return (result != null && result.containsColumn(commitTableFamily, INVALID_TX_QUALIFIER));
}
 
Example 12
Source File: HBaseCommitTable.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
private boolean containsLowWatermark(Result result) {
    return (result != null && result.containsColumn(lowWatermarkFamily, LOW_WATERMARK_QUALIFIER));
}
 
Example 13
Source File: SingleCellExtractor.java    From hbase-indexer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean containsTarget(Result result) {
    return result.containsColumn(columnFamily, columnQualifier);
}