iceberg · API

iceberg.types

Iceberg data types — primitives, nested types, and their JSON forms.

Iceberg types are recursive (a struct holds fields whose types may be structs). Mojo has no easy recursive value type, so a whole type tree lives in a TypeStore arena: every node is an entry in TypeStore.nodes and children are referred to by Int index. A "type" in this module is therefore always a (store, index) pair; TypeStore owns the memory.

All primitives from format versions 1, 2 and 3 are covered, including the v3 additions unknown, timestamp_ns, timestamptz_ns, variant, geometry(C) and geography(C, A). A primitive the reader does not recognise is kept as UNKNOWN_PRIM with its original spelling in TypeNode.raw, so forward-compatible metadata (the spec requires readers to tolerate it) still parses instead of blowing up.

Structs

NestedField

struct NestedField

A field of a struct type: id, name, requiredness and a type index.

Implements Copyable, Movable, Writable

Fields
id: Int
name: String
required: Bool
type: Int: Index into the owning TypeStore.
doc: String
has_doc: Bool
initial_default: String: Raw JSON text of initial-default, or "" when absent.
has_initial_default: Bool
write_default: String
has_write_default: Bool

simple

def simple(id: Int, var name: String, required: Bool, type: Int) -> Self

write_to

def write_to(self, mut writer: T)

TypeNode

struct TypeNode

One node of a type tree. Which fields matter depends on kind/prim.

Implements Copyable, Movable

Fields
kind: UInt8
prim: UInt8
precision: Int: decimal(P, S).
scale: Int
length: Int: fixed[L].
crs: String: geometry(C) / geography(C, A).
algorithm: String
raw: String: Original spelling, for P_UNRECOGNIZED and for exact re-serialization.
fields: List[NestedField]: struct.
element: Int: list: element type index.
element_id: Int
element_required: Bool
key: Int: map: key type index.
key_id: Int
value: Int
value_id: Int
value_required: Bool

prim_

def prim_(kind: UInt8) -> Self

TypeStore

struct TypeStore

Arena of type nodes. Indices returned by the builders point in here.

Implements Copyable, Movable

Fields
nodes: List[TypeNode]

__init__

def __init__(out self)

add

def add(mut self, var n: TypeNode) -> Int

primitive

def primitive(mut self, kind: UInt8) -> Int

decimal

def decimal(mut self, precision: Int, scale: Int) -> Int

fixed

def fixed(mut self, length: Int) -> Int

struct_

def struct_(mut self, var fields: List[NestedField]) -> Int

list_

def list_(mut self, element_id: Int, element: Int, required: Bool) -> Int

map_

def map_(mut self, key_id: Int, key: Int, value_id: Int, value: Int, value_required: Bool) -> Int

kind

def kind(self, i: Int) -> UInt8

prim

def prim(self, i: Int) -> UInt8

is_primitive

def is_primitive(self, i: Int) -> Bool

is_nested

def is_nested(self, i: Int) -> Bool

type_name

def type_name(self, i: Int) -> String

The Iceberg JSON spelling of a primitive; the kind for nested types.

equal

def equal(self, a: Int, b: Int) -> Bool

Structural equality of two types in this store.

parse_type

def parse_type(mut self, doc: Json, i: Int) -> Int

Parse an Iceberg type from JSON — a string, or a nested-type object.

parse_field

def parse_field(mut self, doc: Json, i: Int) -> NestedField

parse_primitive

def parse_primitive(mut self, s: String) -> Int

Parse a primitive spelling. Unknown spellings are kept, not rejected.

type_json

def type_json(self, i: Int) -> String

Serialize a type back to its Iceberg JSON form.

field_json

def field_json(self, f: NestedField) -> String

Functions

primitive_name

def primitive_name(kind: UInt8) -> String

is_integer_like

def is_integer_like(kind: UInt8) -> Bool

True for primitives whose value is carried as a signed 64-bit integer.

is_time_like

def is_time_like(kind: UInt8) -> Bool

Aliases

comptime TK_PRIMITIVE = UInt8(0)
comptime TK_STRUCT = UInt8(1)
comptime TK_LIST = UInt8(2)
comptime TK_MAP = UInt8(3)
comptime P_BOOLEAN = UInt8(0)
comptime P_INT = UInt8(1)
comptime P_LONG = UInt8(2)
comptime P_FLOAT = UInt8(3)
comptime P_DOUBLE = UInt8(4)
comptime P_DATE = UInt8(5)
comptime P_TIME = UInt8(6)
comptime P_TIMESTAMP = UInt8(7)
comptime P_TIMESTAMPTZ = UInt8(8)
comptime P_TIMESTAMP_NS = UInt8(9)
comptime P_TIMESTAMPTZ_NS = UInt8(10)
comptime P_STRING = UInt8(11)
comptime P_UUID = UInt8(12)
comptime P_FIXED = UInt8(13)
comptime P_BINARY = UInt8(14)
comptime P_DECIMAL = UInt8(15)
comptime P_UNKNOWN = UInt8(16)
comptime P_VARIANT = UInt8(17)
comptime P_GEOMETRY = UInt8(18)
comptime P_GEOGRAPHY = UInt8(19)
comptime P_UNRECOGNIZED = UInt8(255)

A primitive spelling this build does not know — kept verbatim, never fatal.

comptime DEFAULT_CRS = String("OGC:CRS84")
comptime DEFAULT_EDGE_ALGORITHM = String("spherical")