Package org.apache.parquet.variant
Class VariantBuilder
- java.lang.Object
-
- org.apache.parquet.variant.VariantBuilder
-
- Direct Known Subclasses:
VariantArrayBuilder,VariantObjectBuilder
public class VariantBuilder extends Object
Builder for creating Variant value and metadata.
-
-
Field Summary
Fields Modifier and Type Field Description protected VariantArrayBuilderarrayBuilderprotected org.apache.parquet.variant.MetadatametadataObject and array builders share the same Metadata object as the main builder.protected VariantObjectBuilderobjectBuilderThese are used to build nested objects and arrays, via startObject() and startArray().protected byte[]writeBufferThe buffer for building the Variant value.protected intwritePos
-
Constructor Summary
Constructors Constructor Description VariantBuilder()Creates a VariantBuilder.VariantBuilder(org.apache.parquet.variant.Metadata metadata)Creates a VariantBuilder with a non-default metadata object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendBinary(ByteBuffer binary)Appends binary data to the variant builder.voidappendBoolean(boolean b)Appends a boolean value to the Variant builder.voidappendByte(byte b)Appends a byte value to the variant builder.voidappendDate(int daysSinceEpoch)Appends a date value to the variant builder.voidappendDecimal(BigDecimal d)Appends a decimal value to the variant builder.voidappendDouble(double d)Appends a double value to the variant builder.voidappendEncodedValue(ByteBuffer value)Directly append a Variant value.voidappendFloat(float f)Appends a float value to the variant builder.voidappendInt(int i)Appends an int value to the variant builder.voidappendLong(long l)Appends a long value to the variant builder.voidappendNull()Appends a null value to the Variant builder.voidappendNullIfEmpty()voidappendShort(short s)Appends a short value to the variant builder.voidappendString(String str)Appends a string value to the Variant builder.voidappendTime(long microsSinceMidnight)Appends a Time value to the variant builder.voidappendTimestampNanosNtz(long nanosSinceEpoch)Appends a TimestampNanosNtz value to the variant builder.voidappendTimestampNanosTz(long nanosSinceEpoch)Appends a TimestampNanosTz value to the variant builder.voidappendTimestampNtz(long microsSinceEpoch)Appends a TimestampNtz value to the variant builder.voidappendTimestampTz(long microsSinceEpoch)Appends a TimestampTz value to the variant builder.voidappendUUID(UUID uuid)Appends a UUID value to the variant builder.Variantbuild()protected voidcheckAppendWhileNested()protected voidcheckMultipleNested(String message)ByteBufferencodedValue()voidendArray()Ends appending an array to this variant builder.voidendObject()Finishes appending the object to this builder.voidendObjectIfExists()static intgetMinIntegerSize(int value)protected voidonAppend()protected voidonStartNested()VariantArrayBuilderstartArray()Starts appending an array to this variant builder.VariantObjectBuilderstartObject()Starts appending an object to this variant builder.VariantObjectBuilderstartOrContinueObject()VariantObjectBuilderstartOrContinuePartialObject(ByteBuffer value, Set<String> suppressedKeys)
-
-
-
Field Detail
-
writeBuffer
protected byte[] writeBuffer
The buffer for building the Variant value. The first `writePos` bytes have been written.
-
writePos
protected int writePos
-
metadata
protected org.apache.parquet.variant.Metadata metadata
Object and array builders share the same Metadata object as the main builder.
-
objectBuilder
protected VariantObjectBuilder objectBuilder
These are used to build nested objects and arrays, via startObject() and startArray(). Only one of these can be non-null at a time. If one of these is non-null, then no append() methods can be called on this builder, until endObject() or endArray() is called.
-
arrayBuilder
protected VariantArrayBuilder arrayBuilder
-
-
Method Detail
-
build
public Variant build()
- Returns:
- the Variant value
-
encodedValue
public ByteBuffer encodedValue()
- Returns:
- the constructed Variant value binary, without metadata.
-
appendEncodedValue
public void appendEncodedValue(ByteBuffer value)
Directly append a Variant value. Its keys must already be in the metadata dictionary.
-
appendString
public void appendString(String str)
Appends a string value to the Variant builder.- Parameters:
str- the string value to append
-
appendNull
public void appendNull()
Appends a null value to the Variant builder.
-
appendNullIfEmpty
public void appendNullIfEmpty()
-
appendBoolean
public void appendBoolean(boolean b)
Appends a boolean value to the Variant builder.- Parameters:
b- the boolean value to append
-
appendLong
public void appendLong(long l)
Appends a long value to the variant builder.- Parameters:
l- the long value to append
-
appendInt
public void appendInt(int i)
Appends an int value to the variant builder.- Parameters:
i- the int to append
-
appendShort
public void appendShort(short s)
Appends a short value to the variant builder.- Parameters:
s- the short to append
-
appendByte
public void appendByte(byte b)
Appends a byte value to the variant builder.- Parameters:
b- the byte to append
-
appendDouble
public void appendDouble(double d)
Appends a double value to the variant builder.- Parameters:
d- the double to append
-
appendDecimal
public void appendDecimal(BigDecimal d)
Appends a decimal value to the variant builder. The actual encoded decimal type depends on the precision and scale of the decimal value.- Parameters:
d- the decimal value to append
-
appendDate
public void appendDate(int daysSinceEpoch)
Appends a date value to the variant builder. The date is represented as the number of days since the epoch.- Parameters:
daysSinceEpoch- the number of days since the epoch
-
appendTimestampTz
public void appendTimestampTz(long microsSinceEpoch)
Appends a TimestampTz value to the variant builder. The timestamp is represented as the number of microseconds since the epoch.- Parameters:
microsSinceEpoch- the number of microseconds since the epoch
-
appendTimestampNtz
public void appendTimestampNtz(long microsSinceEpoch)
Appends a TimestampNtz value to the variant builder. The timestamp is represented as the number of microseconds since the epoch.- Parameters:
microsSinceEpoch- the number of microseconds since the epoch
-
appendTime
public void appendTime(long microsSinceMidnight)
Appends a Time value to the variant builder. The time is represented as the number of microseconds since midnight.- Parameters:
microsSinceMidnight- the number of microseconds since midnight
-
appendTimestampNanosTz
public void appendTimestampNanosTz(long nanosSinceEpoch)
Appends a TimestampNanosTz value to the variant builder. The timestamp is represented as the number of nanoseconds since the epoch.- Parameters:
nanosSinceEpoch- the number of nanoseconds since the epoch
-
appendTimestampNanosNtz
public void appendTimestampNanosNtz(long nanosSinceEpoch)
Appends a TimestampNanosNtz value to the variant builder. The timestamp is represented as the number of nanoseconds since the epoch.- Parameters:
nanosSinceEpoch- the number of nanoseconds since the epoch
-
appendFloat
public void appendFloat(float f)
Appends a float value to the variant builder.- Parameters:
f- the float to append
-
appendBinary
public void appendBinary(ByteBuffer binary)
Appends binary data to the variant builder.- Parameters:
binary- the binary data to append
-
appendUUID
public void appendUUID(UUID uuid)
Appends a UUID value to the variant builder.- Parameters:
uuid- the UUID to append
-
startObject
public VariantObjectBuilder startObject()
Starts appending an object to this variant builder. The returned VariantObjectBuilder is used to append object keys and values. startObject() must be called before endObject(). No append*() methods can be called in between startObject() and endObject().Example usage: VariantBuilder builder = new VariantBuilder(); VariantObjectBuilder objBuilder = builder.startObject(); objBuilder.appendKey("key1"); objBuilder.appendString("value1"); builder.endObject();
- Returns:
- a VariantObjectBuilder to build an object
-
startOrContinueObject
public VariantObjectBuilder startOrContinueObject()
-
startOrContinuePartialObject
public VariantObjectBuilder startOrContinuePartialObject(ByteBuffer value, Set<String> suppressedKeys)
-
endObjectIfExists
public void endObjectIfExists()
-
endObject
public void endObject()
Finishes appending the object to this builder. This method must be called after startObject(), before other append*() methods can be called on this builder.
-
startArray
public VariantArrayBuilder startArray()
Starts appending an array to this variant builder. The returned VariantArrayBuilder is used to append values ot the array. startArray() must be called before endArray(). No append*() methods can be called in between startArray() and endArray().Example usage: VariantBuilder builder = new VariantBuilder(); VariantArrayBuilder arrayBuilder = builder.startArray(); arrayBuilder.appendString("value1"); arrayBuilder.appendString("value2"); builder.endArray();
- Returns:
- a VariantArrayBuilder to use for startArrayElement() and endArray().
-
endArray
public void endArray()
Ends appending an array to this variant builder. This method must be called after all elements have been added to the array.
-
onAppend
protected void onAppend()
-
onStartNested
protected void onStartNested()
-
checkMultipleNested
protected void checkMultipleNested(String message)
-
checkAppendWhileNested
protected void checkAppendWhileNested()
-
getMinIntegerSize
public static int getMinIntegerSize(int value)
-
-