@Test public void testPagesSer() throws IOException { MemorySegment[] memorySegments = new MemorySegment[5]; ArrayList<MemorySegment> memorySegmentList = new ArrayList<>(); for (int i = 0; i < 5; i++) { memorySegments[i] = MemorySegmentFactory.wrap(new byte[64]); memorySegmentList.add(memorySegments[i]); } { String str = "啦啦啦啦啦我是快乐的粉刷匠，啦啦啦啦啦我是快乐的粉刷匠，" + "啦啦啦啦啦我是快乐的粉刷匠。"; BinaryRow row = new BinaryRow(1); BinaryRowWriter writer = new BinaryRowWriter(row); writer.writeString(0, BinaryString.fromString(str)); writer.complete(); RandomAccessOutputView out = new RandomAccessOutputView(memorySegments, 64); BinaryRowSerializer serializer = new BinaryRowSerializer(1); serializer.serializeToPages(row, out); BinaryRow mapRow = serializer.mapFromPages(new RandomAccessInputView(memorySegmentList, 64)); writer.reset(); writer.writeString(0, mapRow.getString(0)); writer.complete(); assertEquals(str, row.getString(0).toString()); BinaryRow deserRow = serializer.deserializeFromPages(new RandomAccessInputView(memorySegmentList, 64)); writer.reset(); writer.writeString(0, deserRow.getString(0)); writer.complete(); assertEquals(str, row.getString(0).toString()); } { String str1 = "啦啦啦啦啦我是快乐的粉刷匠，啦啦啦啦啦我是快乐的粉刷匠，" + "啦啦啦啦啦我是快乐的粉刷匠。"; String str2 = "啦啦啦啦啦我是快乐的粉刷匠。"; BinaryRow row = new BinaryRow(2); BinaryRowWriter writer = new BinaryRowWriter(row); writer.writeString(0, BinaryString.fromString(str1)); writer.writeString(1, BinaryString.fromString(str2)); writer.complete(); RandomAccessOutputView out = new RandomAccessOutputView(memorySegments, 64); out.skipBytesToWrite(40); BinaryRowSerializer serializer = new BinaryRowSerializer(2); serializer.serializeToPages(row, out); RandomAccessInputView in = new RandomAccessInputView(memorySegmentList, 64); in.skipBytesToRead(40); BinaryRow mapRow = serializer.mapFromPages(in); writer.reset(); writer.writeString(0, mapRow.getString(0)); writer.writeString(1, mapRow.getString(1)); writer.complete(); assertEquals(str1, row.getString(0).toString()); assertEquals(str2, row.getString(1).toString()); in = new RandomAccessInputView(memorySegmentList, 64); in.skipBytesToRead(40); BinaryRow deserRow = serializer.deserializeFromPages(in); writer.reset(); writer.writeString(0, deserRow.getString(0)); writer.writeString(1, deserRow.getString(1)); writer.complete(); assertEquals(str1, row.getString(0).toString()); assertEquals(str2, row.getString(1).toString()); } }
@Override public BinaryString getString(int pos) { assertIndexIsValid(pos); int fieldOffset = getFieldOffset(pos); final long offsetAndLen = segments[0].getLong(fieldOffset); return BinaryString.readBinaryStringFieldFromSegments(segments, offset, fieldOffset, offsetAndLen); }
BinaryRow extends BinaryFormat implements BaseRow { @Override public BinaryString getString(int pos) { assertIndexIsValid(pos); int fieldOffset = getFieldOffset(pos); final long offsetAndLen = segments[0].getLong(fieldOffset); return BinaryString.readBinaryStringFieldFromSegments(segments, offset, fieldOffset, offsetAndLen); } }
BinaryRow extends BinaryFormat implements BaseRow { @Override public BinaryString getString(int pos) { assertIndexIsValid(pos); int fieldOffset = getFieldOffset(pos); final long offsetAndLen = segments[0].getLong(fieldOffset); return BinaryString.readBinaryStringFieldFromSegments(segments, offset, fieldOffset, offsetAndLen); } BinaryRow(int arity); }
BinaryRow extends BinaryFormat implements BaseRow { @Override public BinaryString getString(int pos) { assertIndexIsValid(pos); int fieldOffset = getFieldOffset(pos); final long offsetAndLen = segments[0].getLong(fieldOffset); return BinaryString.readBinaryStringFieldFromSegments(segments, offset, fieldOffset, offsetAndLen); } BinaryRow(int arity); static int calculateBitSetWidthInBytes(int arity); static int calculateFixPartSizeInBytes(int arity); static boolean isInFixedLengthPart(LogicalType type); static boolean isMutable(LogicalType type); int getFixedLengthPartSize(); @Override int getArity(); @Override byte getHeader(); @Override void setHeader(byte header); void setTotalSize(int sizeInBytes); @Override boolean isNullAt(int pos); @Override void setNullAt(int i); @Override void setInt(int pos, int value); @Override void setLong(int pos, long value); @Override void setDouble(int pos, double value); @Override void setDecimal(int pos, Decimal value, int precision); @Override void setBoolean(int pos, boolean value); @Override void setShort(int pos, short value); @Override void setByte(int pos, byte value); @Override void setFloat(int pos, float value); @Override boolean getBoolean(int pos); @Override byte getByte(int pos); @Override short getShort(int pos); @Override int getInt(int pos); @Override long getLong(int pos); @Override float getFloat(int pos); @Override double getDouble(int pos); @Override BinaryString getString(int pos); @Override Decimal getDecimal(int pos, int precision, int scale); @Override BinaryGeneric<T> getGeneric(int pos); @Override byte[] getBinary(int pos); @Override BaseArray getArray(int pos); @Override BaseMap getMap(int pos); @Override BaseRow getRow(int pos, int numFields); boolean anyNull(); boolean anyNull(int[] fields); BinaryRow copy(); BinaryRow copy(BinaryRow reuse); void clear(); @Override int hashCode(); String toOriginString(LogicalType... types); static String toOriginString(BaseRow row, LogicalType[] types); boolean equalsWithoutHeader(BaseRow o); }
BinaryRow extends BinaryFormat implements BaseRow { @Override public BinaryString getString(int pos) { assertIndexIsValid(pos); int fieldOffset = getFieldOffset(pos); final long offsetAndLen = segments[0].getLong(fieldOffset); return BinaryString.readBinaryStringFieldFromSegments(segments, offset, fieldOffset, offsetAndLen); } BinaryRow(int arity); static int calculateBitSetWidthInBytes(int arity); static int calculateFixPartSizeInBytes(int arity); static boolean isInFixedLengthPart(LogicalType type); static boolean isMutable(LogicalType type); int getFixedLengthPartSize(); @Override int getArity(); @Override byte getHeader(); @Override void setHeader(byte header); void setTotalSize(int sizeInBytes); @Override boolean isNullAt(int pos); @Override void setNullAt(int i); @Override void setInt(int pos, int value); @Override void setLong(int pos, long value); @Override void setDouble(int pos, double value); @Override void setDecimal(int pos, Decimal value, int precision); @Override void setBoolean(int pos, boolean value); @Override void setShort(int pos, short value); @Override void setByte(int pos, byte value); @Override void setFloat(int pos, float value); @Override boolean getBoolean(int pos); @Override byte getByte(int pos); @Override short getShort(int pos); @Override int getInt(int pos); @Override long getLong(int pos); @Override float getFloat(int pos); @Override double getDouble(int pos); @Override BinaryString getString(int pos); @Override Decimal getDecimal(int pos, int precision, int scale); @Override BinaryGeneric<T> getGeneric(int pos); @Override byte[] getBinary(int pos); @Override BaseArray getArray(int pos); @Override BaseMap getMap(int pos); @Override BaseRow getRow(int pos, int numFields); boolean anyNull(); boolean anyNull(int[] fields); BinaryRow copy(); BinaryRow copy(BinaryRow reuse); void clear(); @Override int hashCode(); String toOriginString(LogicalType... types); static String toOriginString(BaseRow row, LogicalType[] types); boolean equalsWithoutHeader(BaseRow o); static final boolean LITTLE_ENDIAN; static final int HEADER_SIZE_IN_BITS; }