# iceberg.schema

> A module of iceberg's API.

`Schema` — an Iceberg struct type with a schema id and identifier fields.

## Structs

### `AccessorField`

```mojo
struct AccessorField
```

A field reachable by name: its id, full dotted name and type index.

Implements: `Copyable`, `Movable`

Fields:

- `id: Int`
- `name: String`
- `type: Int`
- `required: Bool`
- `parent: Int`: Position in `Schema.flat` of the field this one is nested in, or -1.
- `child_pos: Int`: Position among the parent struct's fields, or -1 for a list element and a map key or value — the places a dotted path cannot walk through.

#### `simple`

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

### `Schema`

```mojo
struct Schema
```

A named struct type. Owns its `TypeStore`.

`root` is the index of the top-level struct node; `by_id` / `by_name` are
flattened indexes over *all* nested fields, built once at construction.
Nested names are dotted (`addr.city`); list elements use `.element`, map
keys/values `.key` / `.value`, matching the reference implementations.

Implements: `Copyable`, `Movable`

Fields:

- `store: TypeStore`
- `root: Int`
- `schema_id: Int`
- `identifier_field_ids: List[Int]`
- `flat: List[AccessorField]`

#### `__init__`

```mojo
def __init__(out self, var store: TypeStore, root: Int, schema_id: Int)
```

#### `find_index`

```mojo
def find_index(self, id: Int) -> Int
```

Position in `flat` of field `id`, or -1.

#### `find_field`

```mojo
def find_field(self, id: Int) -> AccessorField
```

#### `has_field`

```mojo
def has_field(self, id: Int) -> Bool
```

#### `find_by_name`

```mojo
def find_by_name(self, name: String) -> AccessorField
```

#### `find_name_index`

```mojo
def find_name_index(self, name: String) -> Int
```

Case-sensitive first, then case-insensitive (Iceberg allows both).

#### `has_name`

```mojo
def has_name(self, name: String) -> Bool
```

#### `name_of`

```mojo
def name_of(self, id: Int) -> String
```

#### `columns`

```mojo
def columns(self) -> List[NestedField]
```

The top-level fields only.

#### `top_ancestor_id`

```mojo
def top_ancestor_id(self, id: Int) -> Int
```

The id of the top-level column `id` lives in, or `id` itself.

#### `struct_path`

```mojo
def struct_path(self, id: Int) -> List[Int]
```

Child positions from the top-level column down to field `id`.

Empty for a top-level field. Raises when the path crosses a list
element or a map key/value, which a dotted name cannot address and a
row predicate cannot evaluate.

#### `in_struct_only`

```mojo
def in_struct_only(self, id: Int) -> Bool
```

True when `id` is reachable from the top through structs alone.

#### `is_top_level`

```mojo
def is_top_level(self, id: Int) -> Bool
```

#### `column_type`

```mojo
def column_type(self, id: Int) -> Self
```

A one-column schema holding just the type of field `id`.

#### `select`

```mojo
def select(self, ids: List[Int]) -> Self
```

Project to the named ids, keeping ancestors of any selected field.

Selecting a nested field keeps the structs above it and *prunes* the
ones beside it: `select(["a.b"])` gives back a struct `a` whose only
field is `b`. Selecting a whole nested column keeps all of it. A list
or a map is never partially selected — its element type is pruned when
the selection reaches inside it, but the container itself stays.

#### `highest_field_id`

```mojo
def highest_field_id(self) -> Int
```

#### `from_json`

```mojo
def from_json(doc: Json, i: Int) -> Self
```

#### `parse`

```mojo
def parse(text: String) -> Self
```

#### `to_json`

```mojo
def to_json(self) -> String
```
