Java Code Examples for org.apache.hadoop.hbase.Cell#getQualifierOffset()
The following examples show how to use
org.apache.hadoop.hbase.Cell#getQualifierOffset() .
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 |
@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 |
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: IndexMaintainer.java From phoenix with Apache License 2.0 | 6 votes |
public ValueGetter createGetterFromKeyValues(final byte[] rowKey, Collection<? extends Cell> pendingUpdates) { final Map<ReferencingColumn, ImmutableBytesPtr> valueMap = Maps.newHashMapWithExpectedSize(pendingUpdates .size()); for (Cell kv : pendingUpdates) { // create new pointers to each part of the kv ImmutableBytesPtr family = new ImmutableBytesPtr(kv.getRowArray(),kv.getFamilyOffset(),kv.getFamilyLength()); ImmutableBytesPtr qual = new ImmutableBytesPtr(kv.getRowArray(), kv.getQualifierOffset(), kv.getQualifierLength()); ImmutableBytesPtr value = new ImmutableBytesPtr(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()); valueMap.put(new ReferencingColumn(family, qual), value); } return new ValueGetter() { @Override public ImmutableBytesPtr getLatestValue(ColumnReference ref) { if(ref.equals(dataEmptyKeyValueRef)) return null; return valueMap.get(ReferencingColumn.wrap(ref)); } @Override public byte[] getRowKey() { return rowKey; } }; }
Example 4
Source File: NewVersionBehaviorTracker.java From hbase with Apache License 2.0 | 6 votes |
/** * 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 5
Source File: TransactionIdMapper.java From pinpoint with Apache License 2.0 | 6 votes |
@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 6
Source File: MetaDataUtil.java From phoenix with Apache License 2.0 | 6 votes |
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 7
Source File: HostApplicationMapperVer2.java From pinpoint with Apache License 2.0 | 5 votes |
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: CellUtils.java From phoenix-omid with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: ApplicationStatMapper.java From pinpoint with Apache License 2.0 | 5 votes |
@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 10
Source File: AgentStatMapperV2.java From pinpoint with Apache License 2.0 | 5 votes |
@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 11
Source File: ResponseTimeMapper.java From pinpoint with Apache License 2.0 | 5 votes |
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 12
Source File: LocalIndexStoreFileScanner.java From phoenix with Apache License 2.0 | 5 votes |
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 13
Source File: UpgradeUtil.java From phoenix with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") private static KeyValue addSaltByte(Cell keyValue, int nSaltBuckets) { byte[] buf = keyValue.getRowArray(); int length = keyValue.getRowLength(); int offset = keyValue.getRowOffset(); boolean isViewSeq = length > SEQ_PREFIX_BYTES.length && Bytes.compareTo(SEQ_PREFIX_BYTES, 0, SEQ_PREFIX_BYTES.length, buf, offset, SEQ_PREFIX_BYTES.length) == 0; if (!isViewSeq && nSaltBuckets == 0) { return null; } byte[] newBuf; if (isViewSeq) { // We messed up the name for the sequences for view indexes so we'll take this opportunity to fix it if (buf[length-1] == 0) { // Global indexes on views have trailing null byte length--; } byte[][] rowKeyMetaData = new byte[3][]; SchemaUtil.getVarChars(buf, offset, length, 0, rowKeyMetaData); byte[] schemaName = rowKeyMetaData[PhoenixDatabaseMetaData.SCHEMA_NAME_INDEX]; byte[] unprefixedSchemaName = new byte[schemaName.length - MetaDataUtil.VIEW_INDEX_SEQUENCE_PREFIX_BYTES.length]; System.arraycopy(schemaName, MetaDataUtil.VIEW_INDEX_SEQUENCE_PREFIX_BYTES.length, unprefixedSchemaName, 0, unprefixedSchemaName.length); byte[] tableName = rowKeyMetaData[PhoenixDatabaseMetaData.TABLE_NAME_INDEX]; PName physicalName = PNameFactory.newName(unprefixedSchemaName); // Reformulate key based on correct data newBuf = MetaDataUtil.getViewIndexSequenceKey(tableName == null ? null : Bytes.toString(tableName), physicalName, nSaltBuckets, false).getKey(); } else { newBuf = new byte[length + 1]; System.arraycopy(buf, offset, newBuf, SaltingUtil.NUM_SALTING_BYTES, length); newBuf[0] = SaltingUtil.getSaltingByte(newBuf, SaltingUtil.NUM_SALTING_BYTES, length, nSaltBuckets); } return new KeyValue(newBuf, 0, newBuf.length, buf, keyValue.getFamilyOffset(), keyValue.getFamilyLength(), buf, keyValue.getQualifierOffset(), keyValue.getQualifierLength(), keyValue.getTimestamp(), KeyValue.Type.codeToType(keyValue.getTypeByte()), buf, keyValue.getValueOffset(), keyValue.getValueLength()); }
Example 14
Source File: MapStatisticsCallerMapper.java From pinpoint with Apache License 2.0 | 4 votes |
@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 15
Source File: CellUtils.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
public static Cell newKeyValue(Cell keyValue, byte[] value) { return new KeyValue(getBuffer(keyValue), keyValue.getRowOffset(), keyValue.getRowLength(), getBuffer(keyValue), keyValue.getFamilyOffset(), keyValue.getFamilyLength(), getBuffer(keyValue), keyValue.getQualifierOffset(), keyValue.getQualifierLength(), keyValue.getTimestamp(), KeyValue.Type.Put, value, 0, value == null ? 0 : value.length); }
Example 16
Source File: MergingServerOp.java From geowave with Apache License 2.0 | 4 votes |
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()); } }
Example 17
Source File: CellUtils.java From phoenix-omid with Apache License 2.0 | 4 votes |
@Override public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof CellId)) return false; CellId otherCellId = (CellId) o; Cell otherCell = otherCellId.getCell(); // Row comparison if (!CellUtil.matchingRow(otherCell, cell)) { return false; } // Family comparison if (!CellUtil.matchingFamily(otherCell, cell)) { return false; } // Qualifier comparison int qualifierLength = cell.getQualifierLength(); int qualifierOffset = cell.getQualifierOffset(); int otherQualifierLength = otherCell.getQualifierLength(); int otherQualifierOffset = otherCell.getQualifierOffset(); if (isShadowCell()) { qualifierLength = qualifierLengthFromShadowCellQualifier(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); qualifierOffset = qualifierOffsetFromShadowCellQualifier(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); } if (otherCellId.isShadowCell()) { otherQualifierLength = qualifierLengthFromShadowCellQualifier(otherCell.getQualifierArray(), otherCell.getQualifierOffset(), otherCell.getQualifierLength()); otherQualifierOffset = qualifierOffsetFromShadowCellQualifier(otherCell.getQualifierArray(), otherCell.getQualifierOffset(), otherCell.getQualifierLength()); } if (!Bytes.equals(cell.getQualifierArray(), qualifierOffset, qualifierLength, otherCell.getQualifierArray(), otherQualifierOffset, otherQualifierLength)) { return false; } // Timestamp comparison return otherCell.getTimestamp() == cell.getTimestamp(); }