Class LazyBinaryFormat<T>
- java.lang.Object
-
- org.apache.flink.table.data.binary.LazyBinaryFormat<T>
-
- All Implemented Interfaces:
BinaryFormat
- Direct Known Subclasses:
BinaryRawValueData,BinaryStringData
@Internal public abstract class LazyBinaryFormat<T> extends Object implements BinaryFormat
An abstract implementation foBinaryFormatwhich is lazily serialized into binary or lazily deserialized into Java object.The reason why we introduce this data structure is in order to save (de)serialization in nested function calls. Consider the following function call chain:
UDF0(input) -> UDF1(result0) -> UDF2(result1) -> UDF3(result2)
Such nested calls, if the return values of UDFs are Java object format, it will result in multiple conversions between Java object and binary format:
converterToBinary(UDF0(converterToJavaObject(input))) -> converterToBinary(UDF1(converterToJavaObject(result0))) -> converterToBinary(UDF2(converterToJavaObject(result1))) -> ...So we introduced
LazyBinaryFormatto avoid the redundant cost, it has three forms:- Binary form
- Java object form
- Binary and Java object both exist
It can lazy the conversions as much as possible. It will be converted into required form only when it is needed.
-
-
Field Summary
-
Fields inherited from interface org.apache.flink.table.data.binary.BinaryFormat
HIGHEST_FIRST_BIT, HIGHEST_SECOND_TO_EIGHTH_BIT, MAX_FIX_PART_DATA_SIZE
-
-
Constructor Summary
Constructors Constructor Description LazyBinaryFormat()LazyBinaryFormat(org.apache.flink.core.memory.MemorySegment[] segments, int offset, int sizeInBytes)LazyBinaryFormat(org.apache.flink.core.memory.MemorySegment[] segments, int offset, int sizeInBytes, T javaObject)LazyBinaryFormat(T javaObject)LazyBinaryFormat(T javaObject, BinarySection binarySection)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidensureMaterialized(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer)Ensure we have materialized binary format.BinarySectiongetBinarySection()TgetJavaObject()intgetOffset()Gets the start offset of this binary data in theMemorySegments.org.apache.flink.core.memory.MemorySegment[]getSegments()Gets the underlyingMemorySegments this binary format spans.intgetSizeInBytes()Gets the size in bytes of this binary data.protected abstract BinarySectionmaterialize(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer)Materialize java object to binary format.voidsetJavaObject(T javaObject)Must be public as it is used during code generation.
-
-
-
Constructor Detail
-
LazyBinaryFormat
public LazyBinaryFormat()
-
LazyBinaryFormat
public LazyBinaryFormat(org.apache.flink.core.memory.MemorySegment[] segments, int offset, int sizeInBytes, T javaObject)
-
LazyBinaryFormat
public LazyBinaryFormat(org.apache.flink.core.memory.MemorySegment[] segments, int offset, int sizeInBytes)
-
LazyBinaryFormat
public LazyBinaryFormat(T javaObject)
-
LazyBinaryFormat
public LazyBinaryFormat(T javaObject, BinarySection binarySection)
-
-
Method Detail
-
getJavaObject
public T getJavaObject()
-
getBinarySection
public BinarySection getBinarySection()
-
setJavaObject
public void setJavaObject(T javaObject)
Must be public as it is used during code generation.
-
getSegments
public org.apache.flink.core.memory.MemorySegment[] getSegments()
Description copied from interface:BinaryFormatGets the underlyingMemorySegments this binary format spans.- Specified by:
getSegmentsin interfaceBinaryFormat
-
getOffset
public int getOffset()
Description copied from interface:BinaryFormatGets the start offset of this binary data in theMemorySegments.- Specified by:
getOffsetin interfaceBinaryFormat
-
getSizeInBytes
public int getSizeInBytes()
Description copied from interface:BinaryFormatGets the size in bytes of this binary data.- Specified by:
getSizeInBytesin interfaceBinaryFormat
-
ensureMaterialized
public final void ensureMaterialized(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer)
Ensure we have materialized binary format.
-
materialize
protected abstract BinarySection materialize(org.apache.flink.api.common.typeutils.TypeSerializer<T> serializer) throws IOException
Materialize java object to binary format. Inherited classes need to hold the information they need. (For example,RawValueDataneeds javaObjectSerializer).- Throws:
IOException
-
-