public static int readUnsigned(ByteArray in, int offset, int size) { int integer = 0; offset += in.offset(); byte[] bytes = in.array(); for (int i = offset, n = offset + size; i < n; i++) { integer <<= 8; integer |= (int) bytes[i] & 0xFF; } return integer; }
private void importFrom(DataInputStream in, ByteArray result) throws IOException { byte[] data = result.array(); int len = in.readInt(); in.read(data, 0, len); result.setLength(len); }
@Override public void reload(Object measureValue) { if (measureValue == null) { value = null; return; } ByteArray byteArray = (ByteArray) measureValue; //the array in ByteArray is guaranteed to be completed owned by the ByteArray value = Bytes.toString(byteArray.array()); }
public void exportColumns(int[] fieldIndex, ByteBuffer buf) { for (int i : fieldIndex) { buf.put(cols[i].array(), cols[i].offset(), cols[i].length()); } }
public Object decodeValue(int c) { ByteArray col = cols[c]; if (col != null && col.array() != null) { return info.codeSystem.decodeColumnValue(c, col.asBuffer()); } return null; }
/** write data to given buffer, like serialize */ public void exportColumns(ImmutableBitSet selectedCols, ByteArray buf) { int pos = 0; for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); Preconditions.checkNotNull(cols[c].array()); System.arraycopy(cols[c].array(), cols[c].offset(), buf.array(), buf.offset() + pos, cols[c].length()); pos += cols[c].length(); } buf.setLength(pos); }
@Override public void encode(ByteArray bodyBytes, ByteArray outputBuf) { Preconditions.checkState(bodyBytes.length() == bodyLength); Preconditions.checkState(bodyBytes.length() + getHeaderLength() == outputBuf.length(), // "bodybytes length: " + bodyBytes.length() + " outputBuf length: " + outputBuf.length() + " header length: " + getHeaderLength()); System.arraycopy(bodyBytes.array(), bodyBytes.offset(), outputBuf.array(), getHeaderLength(), bodyLength); //fill shard and cuboid fillHeader(outputBuf.array()); }
/** write data to given buffer, like serialize */ public void exportColumns(ImmutableBitSet selectedCols, ByteBuffer buf) { for (int i = 0; i < selectedCols.trueBitCount(); i++) { int c = selectedCols.trueBitAt(i); buf.put(cols[c].array(), cols[c].offset(), cols[c].length()); } }
public void shallowCopyFrom(GTRecord source) { assert info == source.info; for (int i = 0; i < cols.length; i++) { cols[i].reset(source.cols[i].array(), source.cols[i].offset(), source.cols[i].length()); } }
@Override public void fillTuple(Tuple tuple, int row) { if (expectRow++ != row) throw new IllegalStateException(); ByteArray raw = rawIterator.next(); int key = BytesUtil.readUnsigned(raw.array(), raw.offset(), raw.length()); String colValue = rawColDict.getValueFromId(key); tuple.setDimensionValue(literalTupleIdx, colValue); } };
@Override public void doMap(Text key, Text value, Context context) throws IOException, InterruptedException { long cuboidID = rowKeySplitter.split(key.getBytes()); Cuboid cuboid = Cuboid.findForMandatory(cubeDesc, cuboidID); int fullKeySize = buildKey(cuboid, rowKeySplitter.getSplitBuffers()); outputKey.set(newKeyBuf.array(), 0, fullKeySize); String baseOutputPath = PathNameCuboidOld; if (cuboidID == baseCuboid) { baseOutputPath = PathNameCuboidBase; } mos.write(outputKey, value, generateFileName(baseOutputPath)); }
@Override public void serialize(ByteArray code, ByteBuffer buffer) { if (code == null) BytesUtil.writeByteArray(null, 0, 0, buffer); else BytesUtil.writeByteArray(code.array(), code.offset(), code.length(), buffer); }
private List<ByteArray> getValueList(int size) { if (size == -1) { return null; } List<ByteArray> valueList = new ArrayList<ByteArray>(size); for (Integer i = 0; i < size; i++) { ByteArray key = new ByteArray(1); BytesUtil.writeUnsigned(i, key.array(), 0, key.length()); valueList.add(key); } return valueList; }
public void testWriteReadUnsignedInt(int testInt, int length) { ByteArray ba = new ByteArray(new byte[length]); BytesUtil.writeUnsigned(testInt, length, ba.asBuffer()); byte[] newBytes = new byte[length]; System.arraycopy(ba.array(), 0, newBytes, 0, length); int value = BytesUtil.readUnsigned(new ByteArray(newBytes).asBuffer(), length); assertEquals(value, testInt); byte[] anOtherNewBytes = new byte[length]; BytesUtil.writeUnsigned(testInt, anOtherNewBytes, 0, length); assertTrue(Arrays.equals(anOtherNewBytes, ba.array())); }
private CompareTupleFilter gt(ColumnTupleFilter col, int v) { CompareTupleFilter r = new CompareTupleFilter(FilterOperatorEnum.GT); r.addChild(col); int c = col.getColumn().getColumnDesc().getZeroBasedIndex(); int len = info.getCodeSystem().maxCodeLength(c); ByteArray bytes = new ByteArray(len); BytesUtil.writeLong(v, bytes.array(), bytes.offset(), len); r.addChild(new ConstantTupleFilter(bytes)); return r; }
private CompareTupleFilter gt(ColumnTupleFilter col, int v) { CompareTupleFilter r = new CompareTupleFilter(FilterOperatorEnum.GT); r.addChild(col); int c = col.getColumn().getColumnDesc().getZeroBasedIndex(); int len = info.getCodeSystem().maxCodeLength(c); ByteArray bytes = new ByteArray(len); BytesUtil.writeLong(v, bytes.array(), bytes.offset(), len); r.addChild(new ConstantTupleFilter(bytes)); return r; }