@Override public int getQualifierLength() { return this.kv.getQualifierLength(); }
/** * @return Qualifier length */ @Override public int getQualifierLength() { return getQualifierLength(getRowLength(),getFamilyLength()); }
protected static String getQualifierString(final KeyValue kv) { return Bytes.toStringBinary(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength()); }
sb.append(toURLEncodedBytes((byte[]) o)); } else if (o instanceof KeyValue) { if (((KeyValue) o).getQualifierLength() != 0) { sb.append(':'); sb.append(toURLEncodedBytes(CellUtil.cloneQualifier((KeyValue) o)));
/** * 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; }
private static String qualStr(KeyValue kv) { return Bytes.toString(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength()); }
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); } } }
kv1.getQualifierOffset() - KeyValue.ROW_OFFSET, kv1.getQualifierLength(), kv1.getTimestamp(), kv1.getTypeByte(), kv1.getValueArray(), kv1.getValueOffset(), kv1.getValueLength(), kv1.getSequenceId(), kv1.getTagsArray(), kv1.getTagsOffset(), 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(), kv2.getValueLength(), kv2.getSequenceId(), kv2.getTagsArray(), kv2.getTagsOffset(), 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()), kv2.getValueOffset(), kv2.getValueLength(), kv2.getSequenceId(),
@Test public void testCreateKey() { byte[] row = "myRow".getBytes(); byte[] qualifier = "myQualifier".getBytes(); // Mimic what Storefile.createBloomKeyValue() does byte[] rowKey = KeyValueUtil.createFirstOnRow(row, 0, row.length, new byte[0], 0, 0, row, 0, 0).getKey(); byte[] rowColKey = KeyValueUtil.createFirstOnRow(row, 0, row.length, new byte[0], 0, 0, qualifier, 0, qualifier.length).getKey(); KeyValue rowKV = KeyValueUtil.createKeyValueFromKey(rowKey); KeyValue rowColKV = KeyValueUtil.createKeyValueFromKey(rowColKey); assertEquals(rowKV.getTimestamp(), rowColKV.getTimestamp()); assertEquals(Bytes.toStringBinary(rowKV.getRowArray(), rowKV.getRowOffset(), rowKV.getRowLength()), Bytes.toStringBinary(rowColKV.getRowArray(), rowColKV.getRowOffset(), rowColKV.getRowLength())); assertEquals(0, rowKV.getQualifierLength()); } }
cf.length)); assertTrue(Bytes.equals(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(), q, 0, q.length)); assertTrue(Bytes.equals(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength(), value, 0, value.length));
"\n currentKV rowLength " + currentKv.getRowLength() + " familyName " + currentKv.getFamilyLength() + " qualifier " + currentKv.getQualifierLength() + "\n prefix " + prefix + "\n codecKv '" + Bytes.toStringBinary(codecKv.getBuffer(),
private static KeyValue getMutationKeyValue(Mutation headerRow, byte[] key) { List<KeyValue> kvs = headerRow.getFamilyMap().get(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES); if (kvs != null) { for (KeyValue kv : kvs) { if (Bytes.compareTo(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength(), key, 0, key.length) == 0) { return kv; } } } return null; }
@Override public boolean matchingQualifier(KeyValue other) { if (other == null) { return false; } if (other instanceof ClientKeyValue) { ClientKeyValue kv = (ClientKeyValue) other; return this.row.compareTo(kv.row) == 0; } return matchingQualifier(other.getBuffer(), other.getQualifierOffset(), other.getQualifierLength()); }
public static long getSequenceNumber(Mutation tableMutation) { List<KeyValue> kvs = tableMutation.getFamilyMap().get(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES); if (kvs != null) { for (KeyValue kv : kvs) { // list is not ordered, so search. TODO: we could potentially assume the position if (Bytes.compareTo(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength(), PhoenixDatabaseMetaData.TABLE_SEQ_NUM_BYTES, 0, PhoenixDatabaseMetaData.TABLE_SEQ_NUM_BYTES.length) == 0) { return PDataType.LONG.getCodec().decodeLong(kv.getBuffer(), kv.getValueOffset(), null); } } } throw new IllegalStateException(); }
public boolean matches(KeyValue kv) { if (matchesFamily(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength())) { return matchesQualifier(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength()); } return false; }
private static byte[] updateValueIfNecessary(KeyValue keyValue) { byte[] buf = keyValue.getBuffer(); if (Bytes.compareTo( buf, keyValue.getQualifierOffset(), keyValue.getQualifierLength(), PhoenixDatabaseMetaData.DATA_TYPE_BYTES, 0, PhoenixDatabaseMetaData.DATA_TYPE_BYTES.length) == 0) { int sqlType = PDataType.INTEGER.getCodec().decodeInt(buf, keyValue.getValueOffset(), null); // Switch the DATA_TYPE index for TIME types, as they currently don't support negative values // In 3.0, we'll switch them to our serialized LONG type instead, as that way we can easily // support negative types going forward. if (sqlType >= 0 && sqlType < OLD_TO_NEW_DATA_TYPE_3_0.length && OLD_TO_NEW_DATA_TYPE_3_0[sqlType] != null) { return OLD_TO_NEW_DATA_TYPE_3_0[sqlType]; } } return buf; } private static KeyValue upgradeTo3(KeyValue keyValue) {
@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"); }