Java Code Examples for org.apache.hadoop.hbase.Cell#getValueArray()
The following examples show how to use
org.apache.hadoop.hbase.Cell#getValueArray() .
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> 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 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: 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 6
Source File: LoadBooksTest.java From cloud-bigtable-examples with Apache License 2.0 | 6 votes |
@Test public void doMutation_encodesKeysAndCounts() { // Arrange DoFnTester<KV<String, Integer>, Mutation> tester = DoFnTester.of(LoadBooks.ENCODE_NGRAM); KV<String, Integer> input = KV.of("this is a test", 513); // Act List<Mutation> output = tester.processBatch(input); // Assert Put put = (Put) output.get(0); assertThat(put.getRow()).isEqualTo("this is a test".getBytes(StandardCharsets.UTF_8)); Cell valueCell = put.get(LoadBooks.FAMILY, LoadBooks.COUNT_QUALIFIER).get(0); byte[] valueArray = valueCell.getValueArray(); byte[] value = Arrays.copyOfRange( valueArray, valueCell.getValueOffset(), valueCell.getValueOffset() + valueCell.getValueLength()); assertThat(value).isEqualTo(new byte[] {0, 0, 2, 1}); }
Example 7
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 8
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 9
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 10
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 11
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 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: GridTableHBaseBenchmark.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private void consume(Result r, int nBytesToConsume) { Cell cell = r.getColumnLatestCell(CF, QN); byte mix = 0; byte[] valueArray = cell.getValueArray(); int n = Math.min(nBytesToConsume, cell.getValueLength()); for (int i = 0; i < n; i++) { mix ^= valueArray[i]; bytesRead++; } discard(mix); rowsRead++; }
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: RSRpcServices.java From hbase with Apache License 2.0 | 5 votes |
/** * Method to account for the size of retained cells and retained data blocks. * @param context rpc call context * @param r result to add size. * @param lastBlock last block to check whether we need to add the block size in context. * @return an object that represents the last referenced block from this response. */ Object addSize(RpcCallContext context, Result r, Object lastBlock) { if (context != null && r != null && !r.isEmpty()) { for (Cell c : r.rawCells()) { context.incrementResponseCellSize(PrivateCellUtil.estimatedSerializedSizeOf(c)); // Since byte buffers can point all kinds of crazy places it's harder to keep track // of which blocks are kept alive by what byte buffer. // So we make a guess. if (c instanceof ByteBufferExtendedCell) { ByteBufferExtendedCell bbCell = (ByteBufferExtendedCell) c; ByteBuffer bb = bbCell.getValueByteBuffer(); if (bb != lastBlock) { context.incrementResponseBlockSize(bb.capacity()); lastBlock = bb; } } else { // We're using the last block being the same as the current block as // a proxy for pointing to a new block. This won't be exact. // If there are multiple gets that bounce back and forth // Then it's possible that this will over count the size of // referenced blocks. However it's better to over count and // use two rpcs than to OOME the regionserver. byte[] valueArray = c.getValueArray(); if (valueArray != lastBlock) { context.incrementResponseBlockSize(valueArray.length); lastBlock = valueArray; } } } } return lastBlock; }
Example 17
Source File: GridTableHBaseBenchmark.java From kylin with Apache License 2.0 | 5 votes |
private void consume(Result r, int nBytesToConsume) { Cell cell = r.getColumnLatestCell(CF, QN); byte mix = 0; byte[] valueArray = cell.getValueArray(); int n = Math.min(nBytesToConsume, cell.getValueLength()); for (int i = 0; i < n; i++) { mix ^= valueArray[i]; bytesRead++; } discard(mix); rowsRead++; }
Example 18
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 19
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]; }
Example 20
Source File: CellUtils.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
public static byte[] getBuffer(Cell keyValue) { return keyValue.getValueArray(); }