Java Code Examples for org.apache.hadoop.hbase.Cell#getValueOffset()
The following examples show how to use
org.apache.hadoop.hbase.Cell#getValueOffset() .
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: HBaseSpanViewer.java From incubator-retired-htrace with Apache License 2.0 | 6 votes |
public List<SpanProtos.Span> getRootSpans() throws IOException { startClient(); Scan scan = new Scan(); scan.addColumn(this.icf, HBaseSpanReceiver.INDEX_SPAN_QUAL); List<SpanProtos.Span> spans = new ArrayList<SpanProtos.Span>(); try { ResultScanner scanner = htable.getScanner(scan); Result result = null; while ((result = scanner.next()) != null) { for (Cell cell : result.listCells()) { InputStream in = new ByteArrayInputStream(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); spans.add(SpanProtos.Span.parseFrom(in)); } } } catch (IOException e) { LOG.warn("Failed to get root spans from HBase. " + e.getMessage()); stopClient(); } return spans; }
Example 2
Source File: AllocatedFilter.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
@Override public ReturnCode filterKeyValue(Cell ignored){ if(foundMatch) return ReturnCode.NEXT_ROW; //can skip the remainder, because we've already got an entry allocated byte[] value=ignored.getValueArray(); int offset=ignored.getValueOffset(); int length=ignored.getValueLength(); if(Bytes.equals(addressMatch,0,addressMatch.length,value,offset,length)){ foundMatch=true; return ReturnCode.INCLUDE; }else if(value.length!=0 || Bytes.equals(value,offset,length,SIConstants.COUNTER_COL,0,SIConstants.COUNTER_COL.length)){ //a machine has already got this id -- also skip the counter column, since we don't need that return ReturnCode.SKIP; } return ReturnCode.INCLUDE; //this is an available entry }
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: IndexMaintainer.java From phoenix with Apache License 2.0 | 6 votes |
public ValueGetter createGetterFromKeyValues(final byte[] rowKey, Collection<? extends Cell> pendingUpdates) { final Map<ColumnReference, ImmutableBytesPtr> valueMap = Maps.newHashMapWithExpectedSize(pendingUpdates .size()); for (Cell kv : pendingUpdates) { // create new pointers to each part of the kv ImmutableBytesPtr value = new ImmutableBytesPtr(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()); valueMap.put(new ColumnReference(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(), kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength()), value); } return new ValueGetter() { @Override public ImmutableBytesWritable getLatestValue(ColumnReference ref, long ts) { if(ref.equals(dataEmptyKeyValueRef)) return null; return valueMap.get(ref); } @Override public byte[] getRowKey() { return rowKey; } }; }
Example 5
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 6
Source File: ServerBuildIndexCompiler.java From phoenix with Apache License 2.0 | 6 votes |
@Override public MutationState execute() throws SQLException { connection.getMutationState().commitDDLFence(dataTable); Tuple tuple = plan.iterator().next(); long rowCount = 0; if (tuple != null) { Cell kv = tuple.getValue(0); ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()); // A single Cell will be returned with the count(*) - we decode that here rowCount = PLong.INSTANCE.getCodec().decodeLong(tmpPtr, SortOrder.getDefault()); } // The contract is to return a MutationState that contains the number of rows modified. In this // case, it's the number of rows in the data table which corresponds to the number of index // rows that were added. return new MutationState(0, 0, connection, rowCount); }
Example 7
Source File: PostLocalIndexDDLCompiler.java From phoenix with Apache License 2.0 | 6 votes |
@Override public MutationState execute() throws SQLException { connection.getMutationState().commitDDLFence(dataTable); Tuple tuple = plan.iterator().next(); long rowCount = 0; if (tuple != null) { Cell kv = tuple.getValue(0); ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()); // A single Cell will be returned with the count(*) - we decode that here rowCount = PLong.INSTANCE.getCodec().decodeLong(tmpPtr, SortOrder.getDefault()); } // The contract is to return a MutationState that contains the number of rows modified. // In this case, it's the number of rows in the data table which corresponds to the // number of index rows that were added. return new MutationState(0, 0, connection, rowCount); }
Example 8
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 9
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 10
Source File: PhoenixServerBuildIndexDBWritable.java From phoenix with Apache License 2.0 | 5 votes |
@Override public void readFields(ResultSet resultSet) throws SQLException { Tuple row = resultSet.unwrap(PhoenixResultSet.class).getCurrentRow(); Cell kv = row.getValue(0); ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()); // A single Cell will be returned with the count(*) - we decode that here rowCount = PLong.INSTANCE.getCodec().decodeLong(tmpPtr, SortOrder.getDefault()); }
Example 11
Source File: LazyValueGetter.java From phoenix with Apache License 2.0 | 5 votes |
/** * @param ref * @return the first value on the scanner for the given column */ private ImmutableBytesPtr get(ColumnReference ref) throws IOException { KeyValue first = ref.getFirstKeyValueForRow(row); if (!scan.seek(first)) { return null; } // there is a next value - we only care about the current value, so we can just snag that Cell next = scan.next(); if (ref.matches(next)) { return new ImmutableBytesPtr(next.getValueArray(), next.getValueOffset(), next.getValueLength()); } return null; }
Example 12
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 13
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 14
Source File: TraceIndexScatterMapper.java From pinpoint with Apache License 2.0 | 5 votes |
static Dot createDot(Cell cell) { final Buffer valueBuffer = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); int elapsed = valueBuffer.readVInt(); int exceptionCode = valueBuffer.readSVInt(); String agentId = valueBuffer.readPrefixedString(); final int acceptTimeOffset = cell.getRowOffset() + HbaseTableConstatns.APPLICATION_NAME_MAX_LEN + HbaseColumnFamily.APPLICATION_TRACE_INDEX_TRACE.ROW_DISTRIBUTE_SIZE; long reverseAcceptedTime = BytesUtils.bytesToLong(cell.getRowArray(), acceptTimeOffset); long acceptedTime = TimeUtils.recoveryTimeMillis(reverseAcceptedTime); TransactionId transactionId = TransactionIdMapper.parseVarTransactionId(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); return new Dot(transactionId, acceptedTime, elapsed, exceptionCode, agentId); }
Example 15
Source File: SampleRegionWALCoprocessor.java From hbase with Apache License 2.0 | 5 votes |
@Override public void preWALWrite(ObserverContext<? extends WALCoprocessorEnvironment> env, RegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException { // check table name matches or not. if (!Bytes.equals(info.getTable().toBytes(), this.tableName)) { return; } preWALWriteCalled = true; // here we're going to remove one keyvalue from the WALEdit, and add // another one to it. List<Cell> cells = logEdit.getCells(); Cell deletedCell = null; for (Cell cell : cells) { // assume only one kv from the WALEdit matches. byte[] family = CellUtil.cloneFamily(cell); byte[] qulifier = CellUtil.cloneQualifier(cell); if (Arrays.equals(family, ignoredFamily) && Arrays.equals(qulifier, ignoredQualifier)) { LOG.debug("Found the KeyValue from WALEdit which should be ignored."); deletedCell = cell; } if (Arrays.equals(family, changedFamily) && Arrays.equals(qulifier, changedQualifier)) { LOG.debug("Found the KeyValue from WALEdit which should be changed."); cell.getValueArray()[cell.getValueOffset()] = (byte) (cell.getValueArray()[cell.getValueOffset()] + 1); } } if (null != row) { cells.add(new KeyValue(row, addedFamily, addedQualifier)); } if (deletedCell != null) { LOG.debug("About to delete a KeyValue from WALEdit."); cells.remove(deletedCell); } }
Example 16
Source File: LazyValueGetter.java From phoenix with Apache License 2.0 | 5 votes |
/** * @param ref * @return the first value on the scanner for the given column */ @SuppressWarnings("deprecation") private ImmutableBytesPtr get(ColumnReference ref) throws IOException { KeyValue first = ref.getFirstKeyValueForRow(row); if (!scan.seek(first)) { return null; } // there is a next value - we only care about the current value, so we can just snag that Cell next = scan.next(); if (ref.matches(next)) { return new ImmutableBytesPtr(next.getValueArray(), next.getValueOffset(), next.getValueLength()); } return null; }
Example 17
Source File: SICompactionState.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
public boolean isFailedCommitTimestamp(Cell element) { return element.getValueLength()==1 && element.getValueArray()[element.getValueOffset()]==SIConstants.SNAPSHOT_ISOLATION_FAILED_TIMESTAMP[0]; }