VariantBuilder

class VariantBuilder(val dictionary: VariantDictionaryBuilder = VariantDictionaryBuilder(), duplicateFields: DuplicateFieldPolicy = DuplicateFieldPolicy.LAST_WINS)

Encodes Variant values.

The builder is a streaming encoder: values are appended to one growable buffer in the order they arrive, and a container's header — which cannot be written first, because it depends on how many elements there turn out to be, how wide their offsets are and how large the biggest field id is — is inserted in front of the children once they are complete. That keeps encoding to a single pass with no intermediate tree.

val builder = VariantBuilder()
builder.startObject()
builder.field("id"); builder.appendLong(7)
builder.field("tags"); builder.startArray(); builder.appendString("a"); builder.endArray()
builder.endObject()
val variant = builder.buildVariant()

The dictionary is deliberately a constructor parameter rather than private state: an SSTable shares one dictionary across every document it holds, so the usual ingest loop creates the dictionary once, then resets the builder per document.

Not thread-safe; the engine has a single writer.

Constructors

Link copied to clipboard
constructor(dictionary: VariantDictionaryBuilder = VariantDictionaryBuilder(), duplicateFields: DuplicateFieldPolicy = DuplicateFieldPolicy.LAST_WINS)

Properties

Link copied to clipboard

Field-name dictionary. Share one across a segment to pay for each name once.

Link copied to clipboard
val size: Int

Number of value bytes written so far.

Functions

Link copied to clipboard
fun append(value: Variant)

Appends value, re-expressed against this builder's dictionary.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun appendDate(epochDay: Int)

Appends a date as days since 1970-01-01.

Link copied to clipboard

Appends value as the narrowest exact decimal type.

Link copied to clipboard
fun appendDouble(value: Double)

Appends value as a double, non-finite values included; JSON cannot read those back.

Link copied to clipboard
fun appendFloat(value: Float)
Link copied to clipboard
fun appendLong(value: Long)

Appends value as the narrowest integer type that holds it.

Link copied to clipboard

Appends the Variant null primitive.

Link copied to clipboard

Appends a JSON number literal, choosing its physical type by the rule exact if possible, narrowest if exact:

Link copied to clipboard
fun appendString(value: String)

Appends value, using the short-string form when its UTF-8 form is under 64 bytes.

Link copied to clipboard
fun appendTimeNtz(microsOfDay: Long)

Appends a time without time zone as microseconds since midnight.

Link copied to clipboard
fun appendTimestampMicros(micros: Long, adjustedToUtc: Boolean)

Appends a timestamp in microseconds since the epoch.

Link copied to clipboard
fun appendTimestampNanos(nanos: Long, adjustedToUtc: Boolean)

Appends a timestamp in nanoseconds since the epoch. See appendTimestampMicros.

Link copied to clipboard
fun appendUuid(value: Uuid)
Link copied to clipboard

The encoded value bytes. The builder may be reset and reused afterwards.

Link copied to clipboard

The encoded value together with a snapshot of the dictionary.

Link copied to clipboard
fun endArray()

Closes the array opened by the matching startArray.

Link copied to clipboard
fun endObject()

Closes the object opened by the matching startObject.

Link copied to clipboard
fun field(name: String)

Names the next value's field.

Link copied to clipboard
fun reset()

Discards the value under construction, keeping the dictionary for the next document.

Link copied to clipboard

Opens an array.

Link copied to clipboard

Opens an object. Every field must be followed by exactly one value.