/** * {@inheritDoc} */ @Override public void put(Put put) throws IOException { byte[] row = put.getRow(); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowData = forceFind(data, row, new TreeMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>(Bytes.BYTES_COMPARATOR)); for (byte[] family : put.getFamilyMap().keySet()) { if (columnFamilies.contains(new String(family, StandardCharsets.UTF_8)) == false) { throw new RuntimeException("Not Exists columnFamily : " + new String(family, StandardCharsets.UTF_8)); } NavigableMap<byte[], NavigableMap<Long, byte[]>> familyData = forceFind(rowData, family, new TreeMap<byte[], NavigableMap<Long, byte[]>>(Bytes.BYTES_COMPARATOR)); for (KeyValue kv : put.getFamilyMap().get(family)) { kv.updateLatestStamp(Bytes.toBytes(System.currentTimeMillis())); byte[] qualifier = kv.getQualifier(); NavigableMap<Long, byte[]> qualifierData = forceFind(familyData, qualifier, new TreeMap<Long, byte[]>()); qualifierData.put(kv.getTimestamp(), kv.getValue()); } } }
ArrayList<String> kvList = new ArrayList<String>(); kvList.add(new String(thePut.getRow())); Map<byte[], List<KeyValue>> familyMap = thePut.getFamilyMap(); for (List<KeyValue> innerList : familyMap.values()) { for (KeyValue kv : innerList) {
/** * Essentially a short-cut from building a {@link Put}. * @param pk row key * @param timestamp timestamp of all the keyvalues * @param values expected value--column pair * @return a keyvalues that the index contains for a given row at a timestamp with the given value * -- column pairs. */ public static List<KeyValue> getIndexKeyValueForTesting(byte[] pk, long timestamp, List<Pair<byte[], CoveredColumn>> values) { int length = 0; List<ColumnEntry> expected = new ArrayList<ColumnEntry>(values.size()); for (Pair<byte[], CoveredColumn> value : values) { ColumnEntry entry = new ColumnEntry(value.getFirst(), value.getSecond()); length += value.getFirst().length; expected.add(entry); } byte[] rowKey = CoveredColumnIndexCodec.composeRowKey(pk, length, expected); Put p = new Put(rowKey, timestamp); CoveredColumnIndexCodec.addColumnsToPut(p, expected); List<KeyValue> kvs = new ArrayList<KeyValue>(); for (Entry<byte[], List<KeyValue>> entry : p.getFamilyMap().entrySet()) { kvs.addAll(entry.getValue()); } return kvs; }
@Override public void put(Put put) throws IOException { addToPutLog(put); byte[] row = put.getRow(); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowData = forceFind(data, row, new TreeMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>(Bytes.BYTES_COMPARATOR)); for (byte[] family : put.getFamilyMap().keySet()){ NavigableMap<byte[], NavigableMap<Long, byte[]>> familyData = forceFind(rowData, family, new TreeMap<byte[], NavigableMap<Long, byte[]>>(Bytes.BYTES_COMPARATOR)); for (KeyValue kv : put.getFamilyMap().get(family)){ kv.updateLatestStamp(Bytes.toBytes(System.currentTimeMillis())); byte[] qualifier = kv.getQualifier(); NavigableMap<Long, byte[]> qualifierData = forceFind(familyData, qualifier, new TreeMap<Long, byte[]>()); qualifierData.put(kv.getTimestamp(), kv.getValue()); } } }
allKvs.addAll(p2.getFamilyMap().get(family)); allKvs.addAll(p1.getFamilyMap().get(family)); codec.verifiers.add(new ListMatchingVerifier("put state 1", p1.getFamilyMap().get(family), familyRef)); codec.verifiers.add(new ListMatchingVerifier("cleanup state 2", p1.getFamilyMap().get(family), familyRef));
allKvs.addAll(p.getFamilyMap().get(family));
@Override public Map<byte[], List<KeyValue>> getFamilyMap() { return put.getFamilyMap(); } }
@Override protected boolean hasColumn() { return put.getFamilyMap() != null && put.getFamilyMap().size() != 0; }
public static Result convert(Put put) { List<KeyValue> kvs = new ArrayList<KeyValue>(); for (List<KeyValue> l : put.getFamilyMap().values()) { kvs.addAll(l); } Result result = new Result(kvs); return result; }
/** * For each value in put2, add it to put1. * * @param put1 * The put to modify * @param put2 * The put to add to put1 */ public static void addToPut(Put put1, Put put2) { Map<byte[], List<KeyValue>> familyMap = put2.getFamilyMap(); for (List<KeyValue> keyValueList : familyMap.values()) { for (KeyValue keyValue : keyValueList) { try { put1.add(keyValue); } catch (IOException e) { throw new DatasetIOException("Could not add KeyValue to put", e); } } } }
/** * Copy constructor. Creates a Put operation cloned from the specified Put. * @param putToCopy put to copy */ public Put(Put putToCopy) { this(putToCopy.getRow(), putToCopy.ts, putToCopy.getRowLock()); this.familyMap = new TreeMap<byte [], List<KeyValue>>(Bytes.BYTES_COMPARATOR); for(Map.Entry<byte [], List<KeyValue>> entry : putToCopy.getFamilyMap().entrySet()) { this.familyMap.put(entry.getKey(), entry.getValue()); } this.writeToWAL = putToCopy.writeToWAL; }
private void validatePut(final Put put) throws IllegalArgumentException{ if (put.isEmpty()) { throw new IllegalArgumentException("No columns to insert"); } if (maxKeyValueSize > 0) { for (List<KeyValue> list : put.getFamilyMap().values()) { for (KeyValue kv : list) { if (kv.getLength() > maxKeyValueSize) { throw new IllegalArgumentException("KeyValue size too large"); } } } } }
public ThemisPut(Put put) throws IOException { checkContainingPreservedColumns(put.getFamilyMap()); setHBasePut(put); }
/** * utitlity function for printing all puts */ public void printAllPuts(List<Put> p) { for (Put p1 : p) { Map<byte[], List<KeyValue>> d = p1.getFamilyMap(); for (byte[] k : d.keySet()) { System.out.println(" k " + Bytes.toString(k)); } for (List<KeyValue> lkv : d.values()) { for (KeyValue kv : lkv) { System.out.println("\n row: " + taskKeyConv.fromBytes(kv.getRow()) + "\n " + Bytes.toString(kv.getQualifier()) + ": " + Bytes.toString(kv.getValue())); } } } }
/** * {@inheritDoc} */ @Override public void put(Put put) throws IOException { this.sleeper(); byte[] row = put.getRow(); NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> rowData = forceFind(data, row, new TreeMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>>(Bytes.BYTES_COMPARATOR)); for (byte[] family : put.getFamilyMap().keySet()) { if (columnFamilies.contains(new String(family)) == false) { throw new RuntimeException("Not Exists columnFamily : " + new String(family)); } NavigableMap<byte[], NavigableMap<Long, byte[]>> familyData = forceFind(rowData, family, new TreeMap<byte[], NavigableMap<Long, byte[]>>(Bytes.BYTES_COMPARATOR)); for (KeyValue kv : put.getFamilyMap().get(family)) { kv.updateLatestStamp(Bytes.toBytes(System.currentTimeMillis())); byte[] qualifier = kv.getQualifier(); NavigableMap<Long, byte[]> qualifierData = forceFind(familyData, qualifier, new TreeMap<Long, byte[]>()); qualifierData.put(kv.getTimestamp(), kv.getValue()); } } }
@Override public void write(WritableComparable<?> key, Object value) throws IOException { Put original = toPut(value); Put put = original; if (outputVersion != null) { put = new Put(original.getRow(), outputVersion.longValue()); for (List<? extends Cell> row : original.getFamilyMap().values()) { for (Cell cell : row) { KeyValue el = (KeyValue)cell; put.add(el.getFamily(), el.getQualifier(), el.getValue()); } } } baseWriter.write(key, put); }
@Override public void write(WritableComparable<?> key, Object value) throws IOException { Put original = toPut(value); Put put = original; if (outputVersion != null) { put = new Put(original.getRow(), outputVersion.longValue()); for (List<? extends Cell> row : original.getFamilyMap().values()) { for (Cell cell : row) { KeyValue el = (KeyValue)cell; put.add(el.getFamily(), el.getQualifier(), el.getValue()); } } } // we ignore the key baseWriter.write(EMPTY_LIST, put); }
private static Put clonePut(Put put) { long startId = 0; long commitId = 1; Put ret = new Put(put.getRow()); Map<byte[], List<KeyValue>> families = put.getFamilyMap(); Columns cols = new Columns(null); for (byte[] family : families.keySet()) { List<KeyValue> columns = families.get(family); Iterator<KeyValue> it = columns.iterator(); while (it.hasNext()) { KeyValue kv = it.next(); // byte[] column = DominoConst.getColumnKey(kv.getQualifier(), startId); byte[] qualifier = kv.getQualifier(); ret.add(family, qualifier, startId, kv.getValue()); cols.add(family, qualifier); } } Map<String, byte[]> attributes = put.getAttributesMap(); for (String key : attributes.keySet()) { ret.setAttribute(key, attributes.get(key)); } ret.add(DominoConst.INNER_FAMILY, DominoConst.COLUMNS_COL, startId, cols.toByteArray()); ret.add(DominoConst.INNER_FAMILY, DominoConst.VERSION_COL, commitId, DominoConst.versionValue(startId, false)); return ret; }
/** * Given a list of puts, create a new put with the values in each put merged * together. It is expected that no puts have a value for the same fully * qualified column. Return the new put. * * @param key * The key of the new put. * @param putList * The list of puts to merge * @return the new Put instance */ public static Put mergePuts(byte[] keyBytes, List<Put> putList) { Put put = new Put(keyBytes); for (Put putToMerge : putList) { Map<byte[], List<KeyValue>> familyMap = putToMerge.getFamilyMap(); for (List<KeyValue> keyValueList : familyMap.values()) { for (KeyValue keyValue : keyValueList) { try { put.add(new KeyValue(keyBytes, keyValue.getFamily(), keyValue.getQualifier(), keyValue.getTimestamp(), keyValue.getValue())); } catch (IOException e) { throw new DatasetIOException("Could not add KeyValue to put", e); } } } } return put; }
protected CellSetModel buildModelFromPut(Put put) { RowModel row = new RowModel(put.getRow()); long ts = put.getTimeStamp(); for (List<KeyValue> kvs: put.getFamilyMap().values()) { for (KeyValue kv: kvs) { row.addCell(new CellModel(kv.getFamily(), kv.getQualifier(), ts != HConstants.LATEST_TIMESTAMP ? ts : kv.getTimestamp(), kv.getValue())); } } CellSetModel model = new CellSetModel(); model.addRow(row); return model; }