public void decode(Text bytes, Object[] result) { decode(ByteBuffer.wrap(bytes.getBytes(), 0, bytes.getLength()), result); }
public void decode(byte[] bytes) { codec.decode(ByteBuffer.wrap(bytes), values); convertToJavaObjects(values, values); }
@Override public void map(Text key, Text value, Context context) throws IOException, InterruptedException { outputKey.set(key.getBytes(), 0, key.getLength()); KeyValue outputValue; int n = keyValueCreators.size(); if (n == 1 && keyValueCreators.get(0).isFullCopy) { // shortcut for // simple full copy outputValue = keyValueCreators.get(0).create(key, value.getBytes(), 0, value.getLength()); context.write(outputKey, outputValue); } else { // normal (complex) case that distributes measures to multiple // HBase columns inputCodec.decode(value, inputMeasures); for (int i = 0; i < n; i++) { outputValue = keyValueCreators.get(i).create(key, inputMeasures); context.write(outputKey, outputValue); } } }
@Override public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { aggs.reset(); for (Text value : values) { codec.decode(value, input); aggs.aggregate(input); } aggs.collectStates(result); valueBuf.clear(); codec.encode(result, valueBuf); outputValue.set(valueBuf.array(), 0, valueBuf.position()); context.write(key, outputValue); counter++; if (counter % BatchConstants.COUNTER_MAX == 0) { logger.info("Handled " + counter + " records!"); } }
private void verifyMeasures(List<MeasureDesc> measures, Text valueBytes, String m1, String m2, String m3) { MeasureCodec codec = new MeasureCodec(measures); Object[] values = new Object[measures.size()]; codec.decode(valueBytes, values); assertTrue(new BigDecimal(m1).equals(values[0])); assertTrue(new BigDecimal(m2).equals(values[1])); assertTrue(new BigDecimal(m3).equals(values[2])); }
public void aggregate(MeasureAggregator[] measureAggrs, List<Cell> rowCells) { int i = 0; for (int ci = 0; ci < nHCols; ci++) { HCol col = hcols[ci]; Cell cell = findCell(col, rowCells); if (cell == null) { i += col.nMeasures; continue; } ByteBuffer input = ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); col.measureCodec.decode(input, col.measureValues); for (int j = 0; j < col.nMeasures; j++) measureAggrs[i++].aggregate(col.measureValues[j]); } }
fail(); hcol.measureCodec.decode(ByteBuffer.wrap(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()), hcol.measureValues);
@Test public void basicTest() { MeasureDesc descs[] = new MeasureDesc[] { measure("double"), measure("long"), measure("decimal"), measure("HLLC16"), measure("HLLC16") }; MeasureCodec codec = new MeasureCodec(descs); DoubleWritable d = new DoubleWritable(1.0); LongWritable l = new LongWritable(2); BigDecimal b = new BigDecimal("333.1234567"); HyperLogLogPlusCounter hllc = new HyperLogLogPlusCounter(16); hllc.add("1234567"); hllc.add("abcdefg"); HyperLogLogPlusCounter hllc2 = new HyperLogLogPlusCounter(16); hllc.add("1234567"); hllc.add("abcdefg"); Object values[] = new Object[] { d, l, b, hllc, hllc2 }; ByteBuffer buf = ByteBuffer.allocate(RowConstants.ROWVALUE_BUFFER_SIZE); codec.encode(values, buf); buf.flip(); System.out.println("size: " + buf.limit()); Object copy[] = new Object[values.length]; codec.decode(buf, copy); assertTrue(Arrays.equals(values, copy)); }