Java Code Examples for org.apache.hadoop.hbase.Cell#getQualifierArray()

The following examples show how to use org.apache.hadoop.hbase.Cell#getQualifierArray() . 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: HalyardBulkDelete.java    From Halyard with Apache License 2.0 6 votes vote down vote up
@Override
protected void map(ImmutableBytesWritable key, Result value, Context output) throws IOException, InterruptedException {
    for (Cell c : value.rawCells()) {
        Statement st = HalyardTableUtils.parseStatement(c, SVF);
        if ((subj == null || subj.equals(st.getSubject())) && (pred == null || pred.equals(st.getPredicate())) && (obj == null || obj.equals(st.getObject())) && (ctx == null || ctx.contains(st.getContext()))) {
            KeyValue kv = new KeyValue(c.getRowArray(), c.getRowOffset(), (int) c.getRowLength(),
                c.getFamilyArray(), c.getFamilyOffset(), (int) c.getFamilyLength(),
                c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength(),
                c.getTimestamp(), KeyValue.Type.DeleteColumn, c.getValueArray(), c.getValueOffset(),
                c.getValueLength(), c.getTagsArray(), c.getTagsOffset(), c.getTagsLength());
            output.write(new ImmutableBytesWritable(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength()), kv);
            deleted++;
        } else {
            output.progress();
        }
        if (total++ % 10000l == 0) {
            String msg = MessageFormat.format("{0} / {1} cells deleted", deleted, total);
            output.setStatus(msg);
            LOG.log(Level.INFO, msg);
        }
    }

}
 
Example 2
Source File: HBaseSpanViewer.java    From incubator-retired-htrace with Apache License 2.0 6 votes vote down vote up
public List<SpanProtos.Span> getSpans(long traceid) throws IOException {
  startClient();
  List<SpanProtos.Span> spans = new ArrayList<SpanProtos.Span>();
  Get get = new Get(Bytes.toBytes(traceid));
  get.addFamily(this.cf);
  try {
    for (Cell cell : htable.get(get).listCells()) {
      InputStream in = new ByteArrayInputStream(cell.getQualifierArray(),
                                                cell.getQualifierOffset(),
                                                cell.getQualifierLength());
      spans.add(SpanProtos.Span.parseFrom(in));
    }
  } catch (IOException e) {
    LOG.warn("Failed to get spans from HBase. " + e.getMessage());
    stopClient();
  }
  return spans;
}
 
Example 3
Source File: NewVersionBehaviorTracker.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Reset the map if it is different with the last Cell.
 * Save the cq array/offset/length for next Cell.
 *
 * @return If this put has duplicate ts with last cell, return the mvcc of last cell.
 * Else return MAX_VALUE.
 */
protected long prepare(Cell cell) {
  boolean matchCq =
      PrivateCellUtil.matchingQualifier(cell, lastCqArray, lastCqOffset, lastCqLength);
  if (!matchCq) {
    // The last cell is family-level delete and this is not, or the cq is changed,
    // we should construct delColMap as a deep copy of delFamMap.
    delColMap.clear();
    for (Map.Entry<Long, DeleteVersionsNode> e : delFamMap.entrySet()) {
      delColMap.put(e.getKey(), e.getValue().getDeepCopy());
    }
    countCurrentCol = 0;
  }
  if (matchCq && !PrivateCellUtil.isDelete(lastCqType) && lastCqType == cell.getTypeByte()
      && lastCqTs == cell.getTimestamp()) {
    // Put with duplicate timestamp, ignore.
    return lastCqMvcc;
  }
  lastCqArray = cell.getQualifierArray();
  lastCqOffset = cell.getQualifierOffset();
  lastCqLength = cell.getQualifierLength();
  lastCqTs = cell.getTimestamp();
  lastCqMvcc = cell.getSequenceId();
  lastCqType = cell.getTypeByte();
  return Long.MAX_VALUE;
}
 
Example 4
Source File: TransactionIdMapper.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public List<TransactionId> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    Cell[] rawCells = result.rawCells();
    List<TransactionId> traceIdList = new ArrayList<>(rawCells.length);
    for (Cell cell : rawCells) {
        final byte[] qualifierArray = cell.getQualifierArray();
        final int qualifierOffset = cell.getQualifierOffset();
        final int qualifierLength = cell.getQualifierLength();
        // increment by value of key
        TransactionId traceId = parseVarTransactionId(qualifierArray, qualifierOffset, qualifierLength);
        traceIdList.add(traceId);

        logger.debug("found traceId {}", traceId);
    }
    return traceIdList;
}
 
Example 5
Source File: MetaDataUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public static void mutatePutValue(Put somePut, byte[] family, byte[] qualifier, byte[] newValue) {
    NavigableMap<byte[], List<Cell>> familyCellMap = somePut.getFamilyCellMap();
    List<Cell> cells = familyCellMap.get(family);
    List<Cell> newCells = Lists.newArrayList();
    if (cells != null) {
        for (Cell cell : cells) {
            if (Bytes.compareTo(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(),
                qualifier, 0, qualifier.length) == 0) {
                Cell replacementCell = new KeyValue(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                    cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), cell.getQualifierArray(),
                    cell.getQualifierOffset(), cell.getQualifierLength(), cell.getTimestamp(),
                    KeyValue.Type.codeToType(cell.getType().getCode()), newValue, 0, newValue.length);
                newCells.add(replacementCell);
            } else {
                newCells.add(cell);
            }
        }
        familyCellMap.put(family, newCells);
    }
}
 
Example 6
Source File: CellUtils.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether a cell contains a qualifier that is a shadow cell
 * column qualifier or not.
 * @param cell the cell to check if contains the shadow cell qualifier
 * @return whether the cell passed contains a shadow cell qualifier or not
 */
public static boolean isShadowCell(Cell cell) {
    byte[] qualifier = cell.getQualifierArray();
    int qualOffset = cell.getQualifierOffset();
    int qualLength = cell.getQualifierLength();

    return endsWith(qualifier, qualOffset, qualLength, SHADOW_CELL_SUFFIX);
}
 
Example 7
Source File: HostApplicationMapperVer2.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private AcceptApplication createAcceptedApplication(Cell cell) {
    Buffer reader = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
    String host = reader.readPrefixedString();
    String bindApplicationName = reader.readPrefixedString();
    short bindServiceTypeCode = reader.readShort();

    final Application bindApplication = applicationFactory.createApplication(bindApplicationName, bindServiceTypeCode);
    return new AcceptApplication(host, bindApplication);
}
 
Example 8
Source File: ApplicationStatMapper.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public List<JoinStatBo> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    final byte[] distributedRowKey = result.getRow();
    final String applicationId = this.hbaseOperationFactory.getApplicationId(distributedRowKey);
    final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);

    List<JoinStatBo> dataPoints = new ArrayList<>();

    for (Cell cell : result.rawCells()) {
        if (CellUtil.matchingFamily(cell, HbaseColumnFamily.APPLICATION_STAT_STATISTICS.getName())) {
            Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());

            long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);

            ApplicationStatDecodingContext decodingContext = new ApplicationStatDecodingContext();
            decodingContext.setApplicationId(applicationId);
            decodingContext.setBaseTimestamp(baseTimestamp);
            decodingContext.setTimestampDelta(timestampDelta);
            List<JoinStatBo> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
            for (JoinStatBo candidate : candidates) {
                long timestamp = candidate.getTimestamp();
                if (this.filter.filter(timestamp)) {
                    continue;
                }
                dataPoints.add(candidate);
            }
        }
    }
    // Reverse sort as timestamp is stored in a reversed order.
    dataPoints.sort(REVERSE_TIMESTAMP_COMPARATOR);
    return dataPoints;
}
 
Example 9
Source File: AgentStatMapperV2.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    final byte[] distributedRowKey = result.getRow();
    final String agentId = this.hbaseOperationFactory.getAgentId(distributedRowKey);
    final long baseTimestamp = this.hbaseOperationFactory.getBaseTimestamp(distributedRowKey);

    List<T> dataPoints = new ArrayList<>();

    for (Cell cell : result.rawCells()) {
        if (CellUtil.matchingFamily(cell, HbaseColumnFamily.AGENT_STAT_STATISTICS.getName())) {
            Buffer qualifierBuffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
            Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());

            long timestampDelta = this.decoder.decodeQualifier(qualifierBuffer);

            AgentStatDecodingContext decodingContext = new AgentStatDecodingContext();
            decodingContext.setAgentId(agentId);
            decodingContext.setBaseTimestamp(baseTimestamp);
            decodingContext.setTimestampDelta(timestampDelta);
            List<T> candidates = this.decoder.decodeValue(valueBuffer, decodingContext);
            for (T candidate : candidates) {
                if (filter(candidate)) {
                    continue;
                }
                dataPoints.add(candidate);
            }
        }
    }
    // Reverse sort as timestamp is stored in a reversed order.
    dataPoints.sort(REVERSE_TIMESTAMP_COMPARATOR);
    return dataPoints;
}
 
Example 10
Source File: ResponseTimeMapper.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
void recordColumn(ResponseTime responseTime, Cell cell) {

        final byte[] qArray = cell.getQualifierArray();
        final int qOffset = cell.getQualifierOffset();
        short slotNumber = Bytes.toShort(qArray, qOffset);

        // agentId should be added as data.
        String agentId = Bytes.toString(qArray, qOffset + BytesUtils.SHORT_BYTE_LENGTH, cell.getQualifierLength() - BytesUtils.SHORT_BYTE_LENGTH);
        long count = Bytes.toLong(cell.getValueArray(), cell.getValueOffset());
        responseTime.addResponseTime(agentId, slotNumber, count);
    }
 
Example 11
Source File: LocalIndexStoreFileScanner.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private Cell getChangedKey(Cell next, boolean changeBottomKeys) {
    // If it is a top store file change the StartKey with SplitKey in Key
    //and produce the new value corresponding to the change in key
    byte[] changedKey = getNewRowkeyByRegionStartKeyReplacedWithSplitKey(next, changeBottomKeys);
    KeyValue changedKv =
            new KeyValue(changedKey, 0, changedKey.length, next.getFamilyArray(),
                next.getFamilyOffset(), next.getFamilyLength(), next.getQualifierArray(),
                next.getQualifierOffset(), next.getQualifierLength(),
                next.getTimestamp(), Type.codeToType(next.getTypeByte()),
                next.getValueArray(), next.getValueOffset(), next.getValueLength(),
                next.getTagsArray(), next.getTagsOffset(), next.getTagsLength());
    return changedKv;
}
 
Example 12
Source File: MapStatisticsCallerMapper.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public LinkDataMap mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return new LinkDataMap();
    }
    logger.debug("mapRow:{}", rowNum);

    final byte[] rowKey = getOriginalKey(result.getRow());

    final Buffer row = new FixedBuffer(rowKey);
    final Application caller = readCallerApplication(row);
    final long timestamp = TimeUtils.recoveryTimeMillis(row.readLong());

    // key is destApplicationName.
    final LinkDataMap linkDataMap = new LinkDataMap();
    for (Cell cell : result.rawCells()) {
        final Buffer buffer = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
        final Application callee = readCalleeApplication(buffer);
        if (filter.filter(callee)) {
            continue;
        }

        String calleeHost = buffer.readPrefixedString();
        short histogramSlot = buffer.readShort();

        boolean isError = histogramSlot == (short) -1;

        String callerAgentId = buffer.readPrefixedString();

        long requestCount = getValueToLong(cell);
        if (logger.isDebugEnabled()) {
            logger.debug("    Fetched Caller.(New) {} {} -> {} (slot:{}/{}) calleeHost:{}", caller, callerAgentId, callee, histogramSlot, requestCount, calleeHost);
        }

        final short slotTime = (isError) ? (short) -1 : histogramSlot;
        if (StringUtils.isEmpty(calleeHost)) {
            calleeHost = callee.getName();
        }
        linkDataMap.addLinkData(caller, callerAgentId, callee, calleeHost, timestamp, slotTime, requestCount);
    }

    return linkDataMap;
}
 
Example 13
Source File: MergingServerOp.java    From geowave with Apache License 2.0 4 votes vote down vote up
protected Cell mergeList(final List<Cell> cells) {
  synchronized (MUTEX) {
    Mergeable currentMergeable = null;
    final Cell firstCell = cells.get(0);
    for (final Cell cell : cells) {
      final Mergeable mergeable =
          getMergeable(
              cell,
              // TODO consider avoiding extra byte array
              // allocations (which would require
              // persistence utils to be able to use
              // bytebuffer instead of byte[])
              CellUtil.cloneValue(cell));
      if (mergeable != null) {
        if (currentMergeable == null) {
          currentMergeable = mergeable;
        } else {
          currentMergeable.merge(mergeable);
        }
      }
    }
    final byte[] valueBinary = getBinary(currentMergeable);
    // this is basically a lengthy verbose form of cloning
    // in-place (without allocating new byte arrays) and
    // simply replacing the value with the new mergeable
    // value
    return new KeyValue(
        firstCell.getRowArray(),
        firstCell.getRowOffset(),
        firstCell.getRowLength(),
        firstCell.getFamilyArray(),
        firstCell.getFamilyOffset(),
        firstCell.getFamilyLength(),
        firstCell.getQualifierArray(),
        firstCell.getQualifierOffset(),
        firstCell.getQualifierLength(),
        firstCell.getTimestamp(),
        Type.codeToType(firstCell.getTypeByte()),
        valueBinary,
        0,
        valueBinary.length,
        firstCell.getTagsArray(),
        firstCell.getTagsOffset(),
        firstCell.getTagsLength());
  }
}