ExIceberg.Schema (ExIceberg v0.3.0)
Schema definition for Iceberg tables using a declarative API similar to Ecto.Schema.
This module provides macros to define table schemas with proper type safety and a more Elixir-like API for working with Apache Iceberg tables.
Example
defmodule MyApp.UserSchema do
use ExIceberg.Schema
schema "users" do
field :id, :long, required: true
field :name, :string
field :email, :string, required: true
field :age, :int
field :active, :boolean, default: true
field :metadata, ExIceberg.Types.map(:string, :string)
field :tags, ExIceberg.Types.list(:string)
field :address, ExIceberg.Types.struct([
ExIceberg.Types.field("street", :string),
ExIceberg.Types.field("city", :string),
ExIceberg.Types.field("zip", :int)
])
field :balance, ExIceberg.Types.decimal(10, 2)
field :created_at, :timestamp, required: true
field :updated_at, :timestamptz
end
end
# Usage:
{:ok, catalog, _} = MyApp.UserSchema.create_table(catalog, "my_namespace")
Supported Types
Primitive Types
:boolean
- True or false:int
- 32-bit signed integer:long
- 64-bit signed integer:float
- 32-bit IEEE 754 floating point:double
- 64-bit IEEE 754 floating point:string
- UTF-8 character sequences:uuid
- Universally unique identifiers:date
- Calendar date without timezone:time
- Time of day in microsecond precision:timestamp
- Timestamp in microsecond precision, without timezone:timestamptz
- Timestamp in microsecond precision, with timezone:binary
- Arbitrary-length byte array
Complex Types
Use the helper functions from ExIceberg.Types
:
ExIceberg.Types.decimal(precision, scale)
- Fixed point decimalExIceberg.Types.fixed(length)
- Fixed-length byte arrayExIceberg.Types.list(element_type, opts)
- List of elementsExIceberg.Types.map(key_type, value_type, opts)
- Map of key-value pairsExIceberg.Types.struct(fields)
- Struct with named fields
Field Options
:required
- Whether the field is required (default: false):field_id
- Explicit field ID (auto-assigned if not provided)
Summary
Functions
Defines a field in the table schema.
Defines the table schema with the given name and fields.
Functions
Defines a field in the table schema.
Parameters
name
- The field name (atom)type
- The field type (atom or structured type)opts
- Field options (keyword list)
Examples
field :id, :long, required: true
field :price, ExIceberg.Types.decimal(10, 2)
field :tags, ExIceberg.Types.list(:string, element_required: false)
field :metadata, ExIceberg.Types.map(:string, :string)
field :address, ExIceberg.Types.struct([
ExIceberg.Types.field("street", :string),
ExIceberg.Types.field("city", :string)
])
Defines the table schema with the given name and fields.
Example
schema "my_table" do
field :id, :long, required: true
field :name, :string
end