# `Iceberg.Table`
[🔗](https://github.com/Ziinc/iceberg-ex/blob/v0.1.0/lib/iceberg/table.ex#L1)

A loaded Iceberg table: its metadata, scans and appends.

Table data crosses into and out of Elixir as an
[Arrow IPC stream](https://arrow.apache.org/docs/format/Columnar.html#ipc-streaming-format)
binary. With the optional `:explorer` dependency, appends also take an
`Explorer.DataFrame` and `to_dataframe/2` loads a scan.

A table value is a snapshot of the table's metadata at load or commit time;
`refresh/2` reloads it. Every function but `metadata/1` takes `timeout:`
(milliseconds, default `:infinity`).

# `data`

```elixir
@type data() :: binary() | struct()
```

# `result`

```elixir
@type result(ok) :: {:ok, ok} | {:error, Iceberg.Error.t()}
```

# `t`

```elixir
@type t() :: %Iceberg.Table{
  name: String.t(),
  namespace: [String.t()],
  resource: reference()
}
```

# `append`

```elixir
@spec append(t(), data(), keyword()) :: result(t())
```

Writes and commits `data` in one go: `write_data_files/3`, then
`fast_append/3`, taking both functions' options.

# `fast_append`

```elixir
@spec fast_append(t(), Iceberg.DataFiles.t() | [Iceberg.DataFiles.t()], keyword()) ::
  result(t())
```

Commits data files to the table as a new append snapshot. If the table has
moved on since `table` was loaded, the commit is retried on the latest
metadata, as iceberg-rust's `commit.retry.*` table properties allow; when
many writers commit to one table at once, the retries can run out, and the
error is `:catalog_commit_conflicts` with `retryable: true`. With no rows
and no snapshot properties to add, the table is returned as it is.

Options:

  * `:snapshot_properties` - extra entries for the snapshot's summary
    (not `"operation"`, which the commit sets)
  * `:check_duplicate` - refuse files already in the table (default `true`)
  * `:timeout`

# `metadata`

```elixir
@spec metadata(t()) :: map()
```

The table's metadata in the Iceberg spec's JSON shape (string keys:
`"format-version"`, `"current-schema-id"`, `"schemas"`, `"partition-specs"`,
`"current-snapshot-id"`, `"snapshots"` with their `"summary"`, `"properties"`, ...).

# `refresh`

```elixir
@spec refresh(t(), keyword()) :: result(t())
```

Reloads the table from its catalog.

# `scan`

```elixir
@spec scan(t(), keyword()) :: result(binary())
```

Reads the table as an Arrow IPC stream.

Options:

  * `:select` - column names (default: all)
  * `:filter` - a row filter, see `Iceberg.Filter`
  * `:snapshot_id` - read this snapshot instead of the current one
  * `:batch_size` - rows per Arrow record batch
  * `:case_sensitive` - match column names case-sensitively (default `true`)
  * `:timeout`

# `to_dataframe`

```elixir
@spec to_dataframe(t(), keyword()) :: result(Explorer.DataFrame.t())
```

Scans the table (see `scan/2`) into an `Explorer.DataFrame`.

# `write_data_files`

```elixir
@spec write_data_files(t(), data(), keyword()) :: result(Iceberg.DataFiles.t())
```

Writes `data` as Parquet data files in the table's location, without
committing them. Columns are matched to the table's by name and cast to
their types; a missing optional column is written as nulls. Partitioned
tables get a file per partition.

Options:

  * `:file_prefix` - the data files' name prefix (default: a random UUID).
    Files are named `<prefix>-<n>.parquet`, so a retry with the same prefix
    overwrites the files of an attempt that never committed.
  * `:properties` - `write.*` table properties to override for this write,
    such as `"write.parquet.compression-codec"` or
    `"write.target-file-size-bytes"`
  * `:timeout`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
