/** * @return Qualifier offset */ private int getQualifierOffset(int foffset) { return foffset + getFamilyLength(foffset); }
/** * @return Family length */ @Override public byte getFamilyLength() { return getFamilyLength(getFamilyOffset()); }
@Override public byte getFamilyLength() { return this.kv.getFamilyLength(); }
/** * @return Qualifier length */ @Override public int getQualifierLength() { return getQualifierLength(getRowLength(),getFamilyLength()); }
protected static String getFamilyString(final KeyValue kv) { return Bytes.toStringBinary(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength()); }
/** * Produces a string map for this key/value pair. Useful for programmatic use * and manipulation of the data stored in an WALKey, for example, printing * as JSON. Values are left out due to their tendency to be large. If needed, * they can be added manually. * * @return the Map<String,?> containing data from this key */ public Map<String, Object> toStringMap() { Map<String, Object> stringMap = new HashMap<>(); stringMap.put("row", Bytes.toStringBinary(getRowArray(), getRowOffset(), getRowLength())); stringMap.put("family", Bytes.toStringBinary(getFamilyArray(), getFamilyOffset(), getFamilyLength())); stringMap.put("qualifier", Bytes.toStringBinary(getQualifierArray(), getQualifierOffset(), getQualifierLength())); stringMap.put("timestamp", getTimestamp()); stringMap.put("vlen", getValueLength()); Iterator<Tag> tags = getTags(); if (tags != null) { List<String> tagsString = new ArrayList<String>(); while (tags.hasNext()) { tagsString.add(tags.next().toString()); } stringMap.put("tag", tagsString); } return stringMap; }
protected static String toStringWithPadding(final KeyValue kv, final int maxRowLength, int maxFamilyLength, int maxQualifierLength, int maxTimestampLength, boolean includeMeta) { String leadingLengths = ""; String familyLength = kv.getFamilyLength() + " "; if (includeMeta) { leadingLengths += Strings.padFront(kv.getKeyLength() + "", '0', 4); leadingLengths += " "; leadingLengths += Strings.padFront(kv.getValueLength() + "", '0', 4); leadingLengths += " "; leadingLengths += Strings.padFront(kv.getRowLength() + "", '0', 2); leadingLengths += " "; } int spacesAfterRow = maxRowLength - getRowString(kv).length() + 2; int spacesAfterFamily = maxFamilyLength - getFamilyString(kv).length() + 2; int spacesAfterQualifier = maxQualifierLength - getQualifierString(kv).length() + 1; int spacesAfterTimestamp = maxTimestampLength - Long.valueOf(kv.getTimestamp()).toString().length() + 1; return leadingLengths + getRowString(kv) + StringUtils.repeat(' ', spacesAfterRow) + familyLength + getFamilyString(kv) + StringUtils.repeat(' ', spacesAfterFamily) + getQualifierString(kv) + StringUtils.repeat(' ', spacesAfterQualifier) + getTimestampString(kv) + StringUtils.repeat(' ', spacesAfterTimestamp) + getTypeString(kv) + " " + getValueString(kv); }
Bytes.toBytes("q123"), null); Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv3.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE + kv4.getFamilyLength() + kv4.getQualifierLength(), PrivateCellUtil.findCommonPrefixInFlatKey(kv4, kv5, true, true)); + kv6.getFamilyLength() + kv6.getQualifierLength() + 7, PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv7, true, true)); + kv6.getFamilyLength() + kv6.getQualifierLength() + KeyValue.TIMESTAMP_SIZE, PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, true)); + kv6.getFamilyLength() + kv6.getQualifierLength(), PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, false));
private void updateMutationAddingTags(final Mutation m) { byte[] attribute = m.getAttribute("visibility"); byte[] cf = null; List<Cell> updatedCells = new ArrayList<>(); if (attribute != null) { for (List<? extends Cell> edits : m.getFamilyCellMap().values()) { for (Cell cell : edits) { KeyValue kv = KeyValueUtil.ensureKeyValue(cell); if (cf == null) { cf = CellUtil.cloneFamily(kv); } Tag tag = new ArrayBackedTag((byte) 1, attribute); List<Tag> tagList = new ArrayList<>(); tagList.add(tag); KeyValue newKV = new KeyValue(CellUtil.cloneRow(kv), 0, kv.getRowLength(), CellUtil.cloneFamily(kv), 0, kv.getFamilyLength(), CellUtil.cloneQualifier(kv), 0, kv.getQualifierLength(), kv.getTimestamp(), KeyValue.Type.codeToType(kv.getTypeByte()), CellUtil.cloneValue(kv), 0, kv.getValueLength(), tagList); ((List<Cell>) updatedCells).add(newKV); } } m.getFamilyCellMap().remove(cf); // Update the family map m.getFamilyCellMap().put(cf, updatedCells); } }
@Override public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, final Put put, final WALEdit edit, final Durability durability) throws IOException { byte[] attribute = put.getAttribute("visibility"); byte[] cf = null; List<Cell> updatedCells = new ArrayList<>(); if (attribute != null) { for (List<? extends Cell> edits : put.getFamilyCellMap().values()) { for (Cell cell : edits) { KeyValue kv = KeyValueUtil.ensureKeyValue(cell); if (cf == null) { cf = CellUtil.cloneFamily(kv); } Tag tag = new ArrayBackedTag(TAG_TYPE, attribute); List<Tag> tagList = new ArrayList<>(1); tagList.add(tag); KeyValue newKV = new KeyValue(CellUtil.cloneRow(kv), 0, kv.getRowLength(), CellUtil.cloneFamily(kv), 0, kv.getFamilyLength(), CellUtil.cloneQualifier(kv), 0, kv.getQualifierLength(), kv.getTimestamp(), KeyValue.Type.codeToType(kv.getTypeByte()), CellUtil.cloneValue(kv), 0, kv.getValueLength(), tagList); ((List<Cell>) updatedCells).add(newKV); } } put.getFamilyCellMap().remove(cf); // Update the family map put.getFamilyCellMap().put(cf, updatedCells); } } }
int cfLen = currentKV.getFamilyLength(currentKV.getFamilyOffset()); int restLen = currentKV.getLength() - kLen - vLen;
kv1.getFamilyOffset() - KeyValue.ROW_OFFSET, kv1.getFamilyLength(), kv1.getQualifierOffset() - KeyValue.ROW_OFFSET, kv1.getQualifierLength(), kv1.getTimestamp(), kv1.getTypeByte(), kv1.getValueArray(), kv1.getValueOffset(), HConstants.LATEST_TIMESTAMP, Bytes.toBytes("2")); OnheapDecodedCell c2 = new OnheapDecodedCell(kv2.getKey(), kv2.getRowLength(), kv2.getFamilyOffset() - KeyValue.ROW_OFFSET, kv2.getFamilyLength(), kv2.getQualifierOffset() - KeyValue.ROW_OFFSET, kv2.getQualifierLength(), kv2.getTimestamp(), kv2.getTypeByte(), kv2.getValueArray(), kv2.getValueOffset(), BufferedDataBlockEncoder.OffheapDecodedExtendedCell c3 = new BufferedDataBlockEncoder.OffheapDecodedExtendedCell(ByteBuffer.wrap(kv2.getKey()), kv2.getRowLength(), kv2.getFamilyOffset() - KeyValue.ROW_OFFSET, kv2.getFamilyLength(), kv2.getQualifierOffset() - KeyValue.ROW_OFFSET, kv2.getQualifierLength(), kv2.getTimestamp(), kv2.getTypeByte(), ByteBuffer.wrap(kv2.getValueArray()),
assertTrue(Bytes.equals(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), row, 0, row.length)); assertTrue(Bytes.equals(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(), cf, 0, cf.length)); assertTrue(Bytes.equals(kv.getQualifierArray(), kv.getQualifierOffset(),
"\n codecKv.getLength() " + currentKv.getLength() + "\n currentKV rowLength " + currentKv.getRowLength() + " familyName " + currentKv.getFamilyLength() + " qualifier " + currentKv.getQualifierLength() + "\n prefix " + prefix +
@Override public boolean matchingFamily(KeyValue other) { if(other == null) { return false; } if(other instanceof ClientKeyValue) { ClientKeyValue kv = (ClientKeyValue)other; return this.family.compareTo(kv.family) == 0; } return matchingFamily(other.getBuffer(), other.getFamilyOffset(), other.getFamilyLength()); }
@Override public KeyValue getHint(KeyValue peeked) { // check to see if we have another column to seek ImmutableBytesPtr nextFamily = getNextFamily(new ImmutableBytesPtr(peeked.getBuffer(), peeked.getFamilyOffset(), peeked.getFamilyLength())); if (nextFamily == null) { // no known next family, so we can be completely done done = true; return KeyValue.LOWESTKEY; } // there is a valid family, so we should seek to that return KeyValue.createFirstOnRow(peeked.getRow(), nextFamily.copyBytesIfNecessary(), HConstants.EMPTY_BYTE_ARRAY); }
public static ValueGetter createGetterFromKeyValues(Collection<KeyValue> pendingUpdates) { final Map<ReferencingColumn, ImmutableBytesPtr> valueMap = Maps.newHashMapWithExpectedSize(pendingUpdates .size()); for (KeyValue kv : pendingUpdates) { // create new pointers to each part of the kv ImmutableBytesPtr family = new ImmutableBytesPtr(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength()); ImmutableBytesPtr qual = new ImmutableBytesPtr(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength()); ImmutableBytesPtr value = new ImmutableBytesPtr(kv.getBuffer(), kv.getValueOffset(), kv.getValueLength()); valueMap.put(new ReferencingColumn(family, qual), value); } return new ValueGetter() { @Override public ImmutableBytesPtr getLatestValue(ColumnReference ref) throws IOException { return valueMap.get(ReferencingColumn.wrap(ref)); } }; }
public boolean matches(KeyValue kv) { if (matchesFamily(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength())) { return matchesQualifier(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength()); } return false; }
@Override public KeyValue getHint(KeyValue kv) { return KeyValue.createLastOnRow(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength(), kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength(), kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength()); } }
/** * Set ptr to point to the value contained in the first KeyValue without * exploding Result into KeyValue array. * @param r * @param ptr */ public static void getAggregateValue(Tuple r, ImmutableBytesWritable ptr) { if (r.size() == 1) { KeyValue kv = r.getValue(0); // Just one KV for aggregation if (Bytes.compareTo(SINGLE_COLUMN_FAMILY, 0, SINGLE_COLUMN_FAMILY.length, kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength()) == 0) { if (Bytes.compareTo(SINGLE_COLUMN, 0, SINGLE_COLUMN.length, kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength()) == 0) { ptr.set(kv.getBuffer(), kv.getValueOffset(), kv.getValueLength()); return; } } } throw new IllegalStateException("Expected single, aggregated KeyValue from coprocessor, but instead received " + r + ". Ensure aggregating coprocessors are loaded correctly on server"); }