@Override public byte[] encode(Map<K, V> v) { byte[][] elements = new byte[v.size() * 2][]; int index = 0; for (Entry<K, V> entry : v.entrySet()) { elements[index++] = escape(keyLexicoder.encode(entry.getKey())); elements[index++] = escape(valueLexicoder.encode(entry.getValue())); } return concat(elements); }
return getLexicoder(type).encode(toEncode);
@Override public byte[] encode(T data) { byte[] bytes = escape(lexicoder.encode(data)); byte[] ret = new byte[bytes.length + 1]; for (int i = 0; i < bytes.length; i++) ret[i] = (byte) (0xff - (0xff & bytes[i])); ret[bytes.length] = (byte) 0xff; return ret; }
/** * {@inheritDoc} * * @return a byte array containing the concatenation of each element in the list encoded. */ @Override public byte[] encode(List<LT> v) { byte[][] encElements = new byte[v.size()][]; int index = 0; for (LT element : v) { encElements[index++] = escape(lexicoder.encode(element)); } return concat(encElements); }
@Override public byte[] encode(T data) { byte[] bytes = escape(lexicoder.encode(data)); byte[] ret = new byte[bytes.length + 1]; for (int i = 0; i < bytes.length; i++) ret[i] = (byte) (0xff - (0xff & bytes[i])); ret[bytes.length] = (byte) 0xff; return ret; }
private static byte[] transformVal(final String str) { if( D4mDbInsert.isIntEncodeValueAndDropEmpty() || D4mDbInsert.isIntEncodeKeyAndPrependLastByteRev()) return str.equals("1") ? EMPTY_BYTES : LEX.encode(Integer.parseInt(str)); else return str.getBytes(StandardCharsets.UTF_8); } private static final byte[] EMPTY_BYTES = new byte[0];
/** * {@inheritDoc} * * @return a byte array containing the concatenation of each element in the list encoded. */ @Override public byte[] encode(List<LT> v) { byte[][] encElements = new byte[v.size()][]; int index = 0; for (LT element : v) { encElements[index++] = escape(lexicoder.encode(element)); } return concat(encElements); }
public Pair<Long, Long> ingestMap(SortedMap<ArrayHolder, Integer> map, BatchWriter bw, byte[] sampleidb, SpecificKmerAction specificKmerAction) throws MutationsRejectedException { long ingested = 0, totalsum = 0; for (Map.Entry<ArrayHolder, Integer> entry : map.entrySet()) { Mutation m = new Mutation(specificKmerAction == null ? entry.getKey().b : specificKmerAction.transformKmer(entry.getKey().b)); long lv = entry.getValue().longValue(); totalsum += lv; m.put(EMPTY_BYTES, sampleidb, LEX.encode(lv)); bw.addMutation(m); ingested++; } return new Pair<>(ingested, totalsum); } }
@Override public Iterator<? extends Map.Entry<Key, Value>> apply(Key k, Value v) { // log.info("keyretainonlyapply see "+k.toStringNoTime()+" -> "+INTEGER_LEXICODER.decode(v.get())); final int i = INTEGER_LEXICODER.decode(v.get()); final int inew = i % 2 == 0 ? (i/2)*(i-1) : ((i-1)/2)*i; // try to avoi overflow final Value vnew = new Value(INTEGER_LEXICODER.encode(inew)); return Iterators.singletonIterator(new AbstractMap.SimpleImmutableEntry<>(k, vnew)); }
private static <T> Mutation makeFieldMutation(final T object, final Lexicoder<T> lexicoder, final Text columnQualifer) { final Mutation mutation = new Mutation(MERGE_PARENT_METADATA_ROW_ID); final Value value = new Value(lexicoder.encode(object)); mutation.put(MERGE_PARENT_METADATA_FAMILY, columnQualifer, value); return mutation; }
private static <T> Mutation makeFieldMutation(final T object, final Lexicoder<T> lexicoder, final Text columnQualifer) { final Mutation mutation = new Mutation(MERGE_PARENT_METADATA_ROW_ID); final Value value = new Value(lexicoder.encode(object)); mutation.put(MERGE_PARENT_METADATA_FAMILY, columnQualifer, value); return mutation; }
case DOUBLE: vnew = Double.toString(nnew.doubleValue()).getBytes(StandardCharsets.UTF_8); break; case BIGDECIMAL: vnew = nnew.toString().getBytes(StandardCharsets.UTF_8); break; case LEX_LONG: vnew = lex.encode(nnew.longValue()); break; default: throw new AssertionError();
public Pair<Long, Long> ingestMap(int[] map, BatchWriter bw, byte[] sampleidb, SpecificKmerAction specificKmerAction) throws MutationsRejectedException { long ingested = 0, totalsum = 0; for (int idx = 0; idx < map.length; idx++) { int ival = map[idx]; if (ival == 0) continue; byte[] idxBytes = G.intToBytes(Integer.reverse(idx)); Mutation m = new Mutation(specificKmerAction == null ? idxBytes : specificKmerAction.transformKmer(idxBytes)); totalsum += ival; m.put(EMPTY_BYTES, sampleidb, LEX.encode((long) ival)); bw.addMutation(m); ingested++; } return new Pair<>(ingested, totalsum); } }