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(); } }
/** * 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; }
/** 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); }
final KeyValue kv = new KeyValue(first.key(), first.family(), qualifier, value); return kv;
/** * 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 byte[] family = kv.family(); final byte[] value = kv.value(); if (Bytes.equals(key, MAXID_ROW)) {
return new KeyValue(first.key(), first.family(), qualifier, value);
if (fix) { client.put(new PutRequest(table, ordered.key(), ordered.family(), ordered.qualifier(), ordered.value())) client.put(new PutRequest(table, kv.key(), kv.family(), qual, value)); } else { final DeleteOutOfOrder delooo = new DeleteOutOfOrder(kv); if (timestamp < prev.timestamp()) { client.put(new PutRequest(table, newkey, kv.family(), Bytes.fromShort(newqual), value))
/** * 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; }
final byte[] newqual = new byte[]{qual[0], fixQualifierFlags(qual[1], newval.length)}; kv = new KeyValue(kv.key(), kv.family(), newqual, newval);