Class BinaryVariantUtil
- java.lang.Object
-
- org.apache.flink.types.variant.BinaryVariantUtil
-
@Internal public class BinaryVariantUtil extends Object
This class defines constants related to the variant format and provides functions for manipulating variant binaries.A variant is made up of 2 binaries: value and metadata. A variant value consists of a one-byte header and a number of content bytes (can be zero). The header byte is divided into upper 6 bits (called "type info") and lower 2 bits (called "basic type"). The content format is explained in the below constants for all possible basic type and type info values.
The variant metadata includes a version id and a dictionary of distinct strings (case-sensitive). Its binary format is: - Version: 1-byte unsigned integer. The only acceptable value is 1 currently. - Dictionary size: 4-byte little-endian unsigned integer. The number of keys in the dictionary. - Offsets: (size + 1) * 4-byte little-endian unsigned integers. `offsets[i]` represents the starting position of string i, counting starting from the address of `offsets[0]`. Strings must be stored contiguously, so we don’t need to store the string size, instead, we compute it with `offset[i + 1] - offset[i]`. - UTF-8 string data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBinaryVariantUtil.ArrayHandler<T>1.static interfaceBinaryVariantUtil.ObjectHandler<T>1.
-
Field Summary
Fields Modifier and Type Field Description static intARRAYstatic intBASIC_TYPE_BITSstatic intBASIC_TYPE_MASKstatic intBINARYstatic intBINARY_SEARCH_THRESHOLDstatic intDATEstatic intDECIMAL16static intDECIMAL4static intDECIMAL8static intDOUBLEstatic intFALSEstatic intFLOATstatic intINT1static intINT2static intINT4static intINT8static intLONG_STRstatic intMAX_DECIMAL16_PRECISIONstatic intMAX_DECIMAL4_PRECISIONstatic intMAX_DECIMAL8_PRECISIONstatic intMAX_SHORT_STR_SIZEstatic intNULLstatic intOBJECTstatic intPRIMITIVEstatic intSHORT_STRstatic intSIZE_LIMITstatic intTIMESTAMPstatic DateTimeFormatterTIMESTAMP_FORMATTERstatic intTIMESTAMP_LTZstatic DateTimeFormatterTIMESTAMP_LTZ_FORMATTERstatic intTRUEstatic intTYPE_INFO_MASKstatic intU16_MAXstatic intU24_MAXstatic intU24_SIZEstatic intU32_SIZEstatic intU8_MAXstatic byteVERSIONstatic byteVERSION_MASK
-
Constructor Summary
Constructors Constructor Description BinaryVariantUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static bytearrayHeader(boolean largeSize, int offsetSize)static byte[]getBinary(byte[] value, int pos)static booleangetBoolean(byte[] value, int pos)static BigDecimalgetDecimal(byte[] value, int pos)static BigDecimalgetDecimalWithOriginalScale(byte[] value, int pos)static doublegetDouble(byte[] value, int pos)static floatgetFloat(byte[] value, int pos)static longgetLong(byte[] value, int pos)static StringgetMetadataKey(byte[] metadata, int id)static StringgetString(byte[] value, int pos)static Variant.TypegetType(byte[] value, int pos)static intgetTypeInfo(byte[] value, int pos)static <T> ThandleArray(byte[] value, int pos, BinaryVariantUtil.ArrayHandler<T> handler)static <T> ThandleObject(byte[] value, int pos, BinaryVariantUtil.ObjectHandler<T> handler)static byteobjectHeader(boolean largeSize, int idSize, int offsetSize)static byteprimitiveHeader(int type)static byteshortStrHeader(int size)static intvalueSize(byte[] value, int pos)static voidwriteLong(byte[] bytes, int pos, long value, int numBytes)
-
-
-
Field Detail
-
BASIC_TYPE_BITS
public static final int BASIC_TYPE_BITS
- See Also:
- Constant Field Values
-
BASIC_TYPE_MASK
public static final int BASIC_TYPE_MASK
- See Also:
- Constant Field Values
-
TYPE_INFO_MASK
public static final int TYPE_INFO_MASK
- See Also:
- Constant Field Values
-
MAX_SHORT_STR_SIZE
public static final int MAX_SHORT_STR_SIZE
- See Also:
- Constant Field Values
-
PRIMITIVE
public static final int PRIMITIVE
- See Also:
- Constant Field Values
-
SHORT_STR
public static final int SHORT_STR
- See Also:
- Constant Field Values
-
OBJECT
public static final int OBJECT
- See Also:
- Constant Field Values
-
ARRAY
public static final int ARRAY
- See Also:
- Constant Field Values
-
NULL
public static final int NULL
- See Also:
- Constant Field Values
-
TRUE
public static final int TRUE
- See Also:
- Constant Field Values
-
FALSE
public static final int FALSE
- See Also:
- Constant Field Values
-
INT1
public static final int INT1
- See Also:
- Constant Field Values
-
INT2
public static final int INT2
- See Also:
- Constant Field Values
-
INT4
public static final int INT4
- See Also:
- Constant Field Values
-
INT8
public static final int INT8
- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
- See Also:
- Constant Field Values
-
DECIMAL4
public static final int DECIMAL4
- See Also:
- Constant Field Values
-
DECIMAL8
public static final int DECIMAL8
- See Also:
- Constant Field Values
-
DECIMAL16
public static final int DECIMAL16
- See Also:
- Constant Field Values
-
DATE
public static final int DATE
- See Also:
- Constant Field Values
-
TIMESTAMP_LTZ
public static final int TIMESTAMP_LTZ
- See Also:
- Constant Field Values
-
TIMESTAMP
public static final int TIMESTAMP
- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
- See Also:
- Constant Field Values
-
BINARY
public static final int BINARY
- See Also:
- Constant Field Values
-
LONG_STR
public static final int LONG_STR
- See Also:
- Constant Field Values
-
VERSION
public static final byte VERSION
- See Also:
- Constant Field Values
-
VERSION_MASK
public static final byte VERSION_MASK
- See Also:
- Constant Field Values
-
U8_MAX
public static final int U8_MAX
- See Also:
- Constant Field Values
-
U16_MAX
public static final int U16_MAX
- See Also:
- Constant Field Values
-
U24_MAX
public static final int U24_MAX
- See Also:
- Constant Field Values
-
U24_SIZE
public static final int U24_SIZE
- See Also:
- Constant Field Values
-
U32_SIZE
public static final int U32_SIZE
- See Also:
- Constant Field Values
-
SIZE_LIMIT
public static final int SIZE_LIMIT
- See Also:
- Constant Field Values
-
MAX_DECIMAL4_PRECISION
public static final int MAX_DECIMAL4_PRECISION
- See Also:
- Constant Field Values
-
MAX_DECIMAL8_PRECISION
public static final int MAX_DECIMAL8_PRECISION
- See Also:
- Constant Field Values
-
MAX_DECIMAL16_PRECISION
public static final int MAX_DECIMAL16_PRECISION
- See Also:
- Constant Field Values
-
BINARY_SEARCH_THRESHOLD
public static final int BINARY_SEARCH_THRESHOLD
- See Also:
- Constant Field Values
-
TIMESTAMP_FORMATTER
public static final DateTimeFormatter TIMESTAMP_FORMATTER
-
TIMESTAMP_LTZ_FORMATTER
public static final DateTimeFormatter TIMESTAMP_LTZ_FORMATTER
-
-
Method Detail
-
writeLong
public static void writeLong(byte[] bytes, int pos, long value, int numBytes)
-
primitiveHeader
public static byte primitiveHeader(int type)
-
shortStrHeader
public static byte shortStrHeader(int size)
-
objectHeader
public static byte objectHeader(boolean largeSize, int idSize, int offsetSize)
-
arrayHeader
public static byte arrayHeader(boolean largeSize, int offsetSize)
-
getTypeInfo
public static int getTypeInfo(byte[] value, int pos)
-
getType
public static Variant.Type getType(byte[] value, int pos)
-
valueSize
public static int valueSize(byte[] value, int pos)
-
getBoolean
public static boolean getBoolean(byte[] value, int pos)
-
getLong
public static long getLong(byte[] value, int pos)
-
getDouble
public static double getDouble(byte[] value, int pos)
-
getDecimalWithOriginalScale
public static BigDecimal getDecimalWithOriginalScale(byte[] value, int pos)
-
getDecimal
public static BigDecimal getDecimal(byte[] value, int pos)
-
getFloat
public static float getFloat(byte[] value, int pos)
-
getBinary
public static byte[] getBinary(byte[] value, int pos)
-
getString
public static String getString(byte[] value, int pos)
-
handleObject
public static <T> T handleObject(byte[] value, int pos, BinaryVariantUtil.ObjectHandler<T> handler)
-
handleArray
public static <T> T handleArray(byte[] value, int pos, BinaryVariantUtil.ArrayHandler<T> handler)
-
getMetadataKey
public static String getMetadataKey(byte[] metadata, int id)
-
-