new HashMap<String, ByteIterator>(row.size()); for (final KeyValue column : row) { rowResult.put(new String(column.qualifier()),
/** * @see CompactionQueue#complexCompact */ public static KeyValue complexCompact(final KeyValue kv) { final ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(1); kvs.add(kv); return CompactionQueue.complexCompact(kvs, kv.qualifier().length / 2); }
public DeleteCompactedCB(final ArrayList<KeyValue> cells) { final KeyValue first = cells.get(0); key = first.key(); family = first.family(); qualifiers = new byte[cells.size()][]; for (int i = 0; i < qualifiers.length; i++) { qualifiers[i] = cells.get(i).qualifier(); } }
/** * Sets the row this instance holds in RAM using a row from a scanner. * * @param row The compacted HBase row to set. * @throws IllegalStateException if this method was already called. */ void setRow(final KeyValue row) { if (this.key != null) { throw new IllegalStateException("setRow was already called on " + this); } this.key = row.key(); this.qualifiers = row.qualifier(); this.values = row.value(); }
@Override Object deserialize(final ChannelBuffer buf, int cell_size) { final MutateResponse resp = readProtobuf(buf, MutateResponse.PARSER); // An increment must always produce a result, so we shouldn't need to // check whether the `result' field is set here. final ArrayList<KeyValue> kvs = GetRequest.convertResult(resp.getResult(), buf, cell_size); Map<byte[], Long> updatedValues = Maps.newHashMap(); for (KeyValue kv : kvs) { updatedValues.put(kv.qualifier(), Bytes.getLong(kv.value())); } return updatedValues; }
/** * Constructor to delete a specific cell. * @param table The table to edit. * @param kv The specific {@link KeyValue} to delete. Note that if this * {@link KeyValue} specifies a timestamp, then this specific timestamp only * will be deleted. * @since 1.2 */ public DeleteRequest(final byte[] table, final KeyValue kv) { this(table, kv.key(), kv.family(), new byte[][] { kv.qualifier() }, kv.timestamp(), RowLock.NO_LOCK); }
/** * Generate a tree structure that ElasticSearch can read and index from one of the rows that has been returned from * HBase. * * @param row * @return */ @SuppressWarnings("unchecked") protected Map<String, Object> readDataTree(final ArrayList<KeyValue> row) { final Map<String, Object> dataTree = new HashMap<String, Object>(); for (final KeyValue column : row) { final String family = this.river.normalizeField(new String(column.family(), this.river.getCharset())); final String qualifier = new String(column.qualifier(), this.river.getCharset()); final String value = new String(column.value(), this.river.getCharset()); if (!dataTree.containsKey(family)) { dataTree.put(family, new HashMap<String, Object>()); } readQualifierStructure((Map<String, Object>) dataTree.get(family), qualifier, value); } return dataTree; }
/** * Package private helper to access the last timestamp in an HBase row. * * @param metric_width The number of bytes on which metric IDs are stored. * @param row A compacted HBase row. * @return A strictly positive 32-bit timestamp. * @throws IllegalArgumentException if {@code row} doesn't contain any cell. */ static long lastTimestampInRow(final short metric_width, final KeyValue row) { final long base_time = Bytes.getUnsignedInt(row.key(), metric_width); final byte[] qual = row.qualifier(); final short last_delta = (short) (Bytes.getUnsignedShort(qual, qual.length - 2) >>> Const.FLAG_BITS); return base_time + last_delta; }
buf.append(metric).append(' '); final byte[] qualifier = kv.qualifier(); final byte[] cell = kv.value(); if (qualifier.length != 2 && cell[cell.length - 1] != 0) {
/** Private constructor. */ private AppendRequest(final byte[] table, final byte[] key, final byte[] family, final byte[] qualifier, final byte[] value, final long timestamp, final long lockid) { this(table, key, family, new byte[][] { qualifier }, new byte[][] { value }, timestamp, lockid, false); }
/** Private constructor. */ private PutRequest(final byte[] table, final byte[] key, final byte[] family, final byte[] qualifier, final byte[] value, final long timestamp, final long lockid) { this(table, key, family, new byte[][] { qualifier }, new byte[][] { value }, timestamp, lockid); }
/** * Helper to print the cells in a given family for a given row, if any. * * @param row The row to print. * @param family Only cells in this family (if any) will be printed. * @param formard If true, this row contains a forward mapping (name to ID). * Otherwise the row is assumed to contain a reverse mapping (ID to name). * @return {@code true} if at least one cell was printed. */ private static boolean printResult(final ArrayList<KeyValue> row, final byte[] family, final boolean formard) { final byte[] key = row.get(0).key(); String name = formard ? fromBytes(key) : null; String id = formard ? null : Arrays.toString(key); boolean printed = false; for (final KeyValue kv : row) { if (!Bytes.equals(kv.family(), family)) { continue; } printed = true; if (formard) { id = Arrays.toString(kv.value()); } else { name = fromBytes(kv.value()); } System.out.println(fromBytes(kv.qualifier()) + ' ' + name + ": " + id); } return printed; }
final ArrayList<Cell> cells = new ArrayList<Cell>(estimated_nvalues); for (final KeyValue kv : row) { final byte[] qual = kv.qualifier(); final int len = qual.length; final byte[] val = kv.value();
int val_idx = 0; for (final KeyValue kv : row) { final byte[] q = kv.qualifier();
final byte[] qualifier = kv.qualifier(); if (Arrays.equals(REGIONINFO, qualifier)) { final byte[][] tmp = new byte[1][]; // Yes, this is ugly.
final byte[] qual = row.qualifier(); final int len = qual.length; int last_delta = Bytes.getUnsignedShort(qualifiers, qualifiers.length - 2);
/** * De-serializes an {@code hbase.client.Result} object. * @param buf The buffer that contains a serialized {@code Result}. * @return The result parsed into a list of {@link KeyValue} objects. */ private static ArrayList<KeyValue> parseResult(final ChannelBuffer buf) { final int length = buf.readInt(); HBaseRpc.checkArrayLength(buf, length); //LOG.debug("total Result response length={}", length); final int num_kv = numberOfKeyValuesAhead(buf, length); final ArrayList<KeyValue> results = new ArrayList<KeyValue>(num_kv); KeyValue kv = null; for (int i = 0; i < num_kv; i++) { final int kv_length = buf.readInt(); // Previous loop checked it's >0. // Now read a KeyValue that spans over kv_length bytes. kv = KeyValue.fromBuffer(buf, kv); final int key_length = (2 + kv.key().length + 1 + kv.family().length + kv.qualifier().length + 8 + 1); // XXX DEBUG if (key_length + kv.value().length + 4 + 4 != kv_length) { badResponse("kv_length=" + kv_length + " doesn't match key_length + value_length (" + key_length + " + " + kv.value().length + ") in " + buf + '=' + Bytes.pretty(buf)); } results.add(kv); } return results; }
/** Private constructor. */ private DeleteRequest(final byte[] table, final byte[] key, final byte[] family, final byte[][] qualifiers, final long timestamp, final long lockid) { super(table, key, family == null ? WHOLE_ROW : family, timestamp, lockid); if (family != null) { KeyValue.checkFamily(family); } if (qualifiers != null) { if (family == null) { throw new IllegalArgumentException("You can't delete specific qualifiers" + " without specifying which family they belong to." + " table=" + Bytes.pretty(table) + ", key=" + Bytes.pretty(key)); } if (qualifiers.length == 0) { throw new IllegalArgumentException("Don't pass an empty list of" + " qualifiers, this would delete the entire row of table=" + Bytes.pretty(table) + " at key " + Bytes.pretty(key)); } for (final byte[] qualifier : qualifiers) { KeyValue.checkQualifier(qualifier); } this.qualifiers = qualifiers; } else { // No specific qualifier to delete: delete the entire family. Not that
static List<Deferred<Boolean>> doList(HBaseClient client) throws Throwable { final Scanner scanner = client.newScanner(TABLE_NAME); scanner.setFamily(INFO_FAM); scanner.setQualifier(PASSWORD_COL); ArrayList<ArrayList<KeyValue>> rows = null; ArrayList<Deferred<Boolean>> workers = new ArrayList<Deferred<Boolean>>(); while ((rows = scanner.nextRows(1).joinUninterruptibly()) != null) { LOG.info("received a page of users."); for (ArrayList<KeyValue> row : rows) { KeyValue kv = row.get(0); byte[] expected = kv.value(); String userId = new String(kv.key()); PutRequest put = new PutRequest( TABLE_NAME, kv.key(), kv.family(), kv.qualifier(), mkNewPassword(expected)); Deferred<Boolean> d = client.compareAndSet(put, expected) .addCallback(new InterpretResponse(userId)) .addCallbacks(new ResultToMessage(), new FailureToMessage()) .addCallback(new SendMessage()); workers.add(d); } } return workers; }