Variant

class Variant(val metadata: VariantMetadata, segment: MemorySegment, val offset: Long = 0)

A view over one encoded Variant value.

Nothing is decoded on construction and nothing is copied: a Variant is a metadata reference, a MemorySegment and an offset into it. Navigating into a field or an element produces another view over the same bytes, which is what makes reading a single path out of a large document cost the path, not the document.

The segment may be a heap array during ingest or a mapped file region once segments are on disk; the reader does not care which, and that is the point — the same code reads a memtable entry and a page of an SSTable.

A view is immutable and cheap to create. It is safe to share between threads as long as the underlying segment is not being written, which for an immutable segment is always.

Every accessor validates before it reads. Bytes that do not decode raise VariantFormatException — the engine never fabricates a default for data it cannot read.

Constructors

Link copied to clipboard
constructor(metadata: VariantMetadata, segment: MemorySegment, offset: Long = 0)
constructor(metadata: VariantMetadata, value: ByteArray)

Reads a value out of a heap array.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The two-bit basic type opening this value.

Link copied to clipboard

Total encoded length of this value in bytes, including its header.

Link copied to clipboard

Number of top-level children: fields for an object, elements for an array, 0 for a scalar.

Link copied to clipboard

Number of elements. @throws VariantTypeException unless this value is an array.

Link copied to clipboard

Number of fields. @throws VariantTypeException unless this value is an object.

Link copied to clipboard

true for the Variant null primitive. Note that a missing field is absent, not null.

Link copied to clipboard

What this value means, independent of the width it was stored in.

Link copied to clipboard

Dictionary resolving this value's field ids. Usually shared by a whole segment.

Link copied to clipboard

Offset of this value's header byte within segment.

Link copied to clipboard

The exact on-disk primitive type, or null when this value is not a primitive — a short string, an object or an array.

Functions

Link copied to clipboard
fun Variant.appendJsonSummaryTo(out: StringBuilder, limit: Int = DEFAULT_SUMMARY_LIMIT)

Appends toJsonSummaryString to out, avoiding an intermediate String.

Link copied to clipboard

Appends Variant.toJsonString to out, avoiding an intermediate String.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The value of a float or double, widened to Double.

Link copied to clipboard
fun element(index: Int): Variant

The element at index. @throws VariantTypeException unless this value is an array.

Link copied to clipboard

The elements, in order. @throws VariantTypeException unless this value is an array.

Link copied to clipboard
fun epochDay(): Int

Days since 1970-01-01 for a date.

Link copied to clipboard
fun field(name: String): Variant?

The field called name, or null if the object does not have one.

Link copied to clipboard
fun fieldId(index: Int): Int

Dictionary id of the field at index; fields are ordered by name, not by id.

Link copied to clipboard
fun fieldName(index: Int): String

Name of the field at index.

Link copied to clipboard

The fields, in the encoded (lexicographic) order.

Link copied to clipboard
fun fieldValue(index: Int): Variant

Value of the field at index.

Link copied to clipboard

The value of an int8/int16/int32/int64, widened to Long.

Link copied to clipboard

Follows path from this value, or returns null if any step does not exist.

fun select(path: String): Variant?

Follows a path expression such as $.items[0].name. See VariantPath.parse.

Link copied to clipboard

The text of a short string or a long string.

Link copied to clipboard

The raw counter behind a time or timestamp: microseconds for VariantPrimitiveType.TIME_NTZ, VariantPrimitiveType.TIMESTAMP_TZ and VariantPrimitiveType.TIMESTAMP_NTZ, nanoseconds for the two NANOS types.

Link copied to clipboard

Copies this value's bytes out of the segment. Pair with VariantMetadata.toByteArray.

Link copied to clipboard

Renders this value as JSON text.

Link copied to clipboard
fun Variant.toJsonSummaryString(limit: Int = DEFAULT_SUMMARY_LIMIT): String

The first limit top-level children, with everything below them elided.

Link copied to clipboard
open override fun toString(): String

Renders as JSON when it can, which is what a failing assertion or a debugger wants to show. Values JSON cannot express fall back to a structural description rather than throwing — toString failing is never helpful.

Link copied to clipboard

One line describing this value's shape and size, whatever it holds and however large it is.

Link copied to clipboard