Package org.apache.flink.types.variant
Class BinaryVariant
- java.lang.Object
-
- org.apache.flink.types.variant.BinaryVariant
-
- All Implemented Interfaces:
Variant
@Internal public final class BinaryVariant extends Object implements Variant
A data structure that represents a semi-structured value. It consists of two binary values: value and metadata. The value encodes types and values, but not field names. The metadata currently contains a version flag and a list of field names. We can extend/modify the detailed binary format given the version flag.- See Also:
- Variant Binary Encoding for the detail layout of the data structure.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.types.variant.Variant
Variant.Type
-
-
Constructor Summary
Constructors Constructor Description BinaryVariant(byte[] value, byte[] metadata)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Objectget()Get the scalar value of variant.<T> TgetAs()Get the scalar value of variant.booleangetBoolean()Get the scalar value of variant as boolean, if the variant type isVariant.Type.BOOLEAN.bytegetByte()Get the scalar value of variant as byte, if the variant type isVariant.Type.TINYINT.byte[]getBytes()Get the scalar value of variant as byte array, if the variant type isVariant.Type.BYTES.LocalDategetDate()Get the scalar value of variant as LocalDate, if the variant type isVariant.Type.DATE.LocalDateTimegetDateTime()Get the scalar value of variant as LocalDateTime, if the variant type isVariant.Type.TIMESTAMP.BigDecimalgetDecimal()Get the scalar value of variant as BigDecimal, if the variant type isVariant.Type.DECIMAL.doublegetDouble()Get the scalar value of variant as double, if the variant type isVariant.Type.DOUBLE.VariantgetElement(int index)Access value of the specified element of an array variant.VariantgetField(String fieldName)Access value of the specified field of an object variant.floatgetFloat()Get the scalar value of variant as float, if the variant type isVariant.Type.FLOAT.InstantgetInstant()Get the scalar value of variant as Instant, if the variant type isVariant.Type.TIMESTAMP.intgetInt()Get the scalar value of variant as int, if the variant type isVariant.Type.INT.longgetLong()Get the scalar value of variant as long, if the variant type isVariant.Type.BIGINT.byte[]getMetadata()intgetPos()shortgetShort()Get the scalar value of variant as short, if the variant type isVariant.Type.SMALLINT.StringgetString()Get the scalar value of variant as string, if the variant type isVariant.Type.STRING.Variant.TypegetType()Get the type of variant.byte[]getValue()inthashCode()booleanisArray()Returns true if this variant is an Array, false otherwise.booleanisNull()Check If this variant is null.booleanisObject()Returns true if this variant is an Object, false otherwise.booleanisPrimitive()Returns true if the variant is a primitive typed value, such as INT, DOUBLE, STRING, etc.StringtoJson()Parses the variant to json.StringtoString()
-
-
-
Method Detail
-
isPrimitive
public boolean isPrimitive()
Description copied from interface:VariantReturns true if the variant is a primitive typed value, such as INT, DOUBLE, STRING, etc.- Specified by:
isPrimitivein interfaceVariant
-
isArray
public boolean isArray()
Description copied from interface:VariantReturns true if this variant is an Array, false otherwise.
-
isObject
public boolean isObject()
Description copied from interface:VariantReturns true if this variant is an Object, false otherwise.
-
isNull
public boolean isNull()
Description copied from interface:VariantCheck If this variant is null.
-
getType
public Variant.Type getType()
Description copied from interface:VariantGet the type of variant.
-
getBoolean
public boolean getBoolean() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as boolean, if the variant type isVariant.Type.BOOLEAN.- Specified by:
getBooleanin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.BOOLEAN.
-
getByte
public byte getByte() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as byte, if the variant type isVariant.Type.TINYINT.- Specified by:
getBytein interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.TINYINT.
-
getShort
public short getShort() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as short, if the variant type isVariant.Type.SMALLINT.- Specified by:
getShortin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.SMALLINT.
-
getInt
public int getInt() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as int, if the variant type isVariant.Type.INT.- Specified by:
getIntin interfaceVariant- Throws:
VariantTypeException- if this variant is not a scalar value or is notVariant.Type.INT.
-
getLong
public long getLong() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as long, if the variant type isVariant.Type.BIGINT.- Specified by:
getLongin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.BIGINT.
-
getFloat
public float getFloat() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as float, if the variant type isVariant.Type.FLOAT.- Specified by:
getFloatin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.FLOAT.
-
getDecimal
public BigDecimal getDecimal() throws VariantTypeException
Description copied from interface:VariantGet the scalar value of variant as BigDecimal, if the variant type isVariant.Type.DECIMAL.- Specified by:
getDecimalin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.DECIMAL.
-
getDouble
public double getDouble() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as double, if the variant type isVariant.Type.DOUBLE.- Specified by:
getDoublein interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.DOUBLE.
-
getString
public String getString() throws VariantTypeException
Description copied from interface:VariantGet the scalar value of variant as string, if the variant type isVariant.Type.STRING.- Specified by:
getStringin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.STRING.
-
getDate
public LocalDate getDate() throws VariantTypeException
Description copied from interface:VariantGet the scalar value of variant as LocalDate, if the variant type isVariant.Type.DATE.- Specified by:
getDatein interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.DATE.
-
getDateTime
public LocalDateTime getDateTime() throws VariantTypeException
Description copied from interface:VariantGet the scalar value of variant as LocalDateTime, if the variant type isVariant.Type.TIMESTAMP.- Specified by:
getDateTimein interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.TIMESTAMP.
-
getInstant
public Instant getInstant() throws VariantTypeException
Description copied from interface:VariantGet the scalar value of variant as Instant, if the variant type isVariant.Type.TIMESTAMP.- Specified by:
getInstantin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.TIMESTAMP.
-
getBytes
public byte[] getBytes() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant as byte array, if the variant type isVariant.Type.BYTES.- Specified by:
getBytesin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value or is notVariant.Type.BYTES.
-
get
public Object get() throws VariantTypeException
Description copied from interface:VariantGet the scalar value of variant.- Specified by:
getin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value.
-
getAs
public <T> T getAs() throws VariantTypeExceptionDescription copied from interface:VariantGet the scalar value of variant.- Specified by:
getAsin interfaceVariant- Throws:
VariantTypeException- If this variant is not a scalar value.
-
getElement
public Variant getElement(int index) throws VariantTypeException
Description copied from interface:VariantAccess value of the specified element of an array variant. If index is out of range, null is returned.NOTE: if the element value has been explicitly set as
null(which is different from removal!), a variant that @Variant.isNull()returns true will be returned, not null.- Specified by:
getElementin interfaceVariant- Throws:
VariantTypeException- If this variant is not an array.
-
getField
public Variant getField(String fieldName) throws VariantTypeException
Description copied from interface:VariantAccess value of the specified field of an object variant. If there is no field with the specified name, null is returned.NOTE: if the property value has been explicitly set as
null, a variant that @Variant.isNull()returns true will be returned, not null.- Specified by:
getFieldin interfaceVariant- Throws:
VariantTypeException- If this variant is not an object.
-
toJson
public String toJson()
Description copied from interface:VariantParses the variant to json.
-
getValue
public byte[] getValue()
-
getMetadata
public byte[] getMetadata()
-
getPos
public int getPos()
-
-