# `Latu.Catalog`
[🔗](https://github.com/zero-one-group/latu/blob/v0.4.0/lib/latu/catalog.ex#L1)

Spark's catalog: databases, tables, views, caching.

Session-first and eager — every call answers from the server. Listings come back exactly as
`Latu.collect/2` returns rows: maps with atom keys spelled the way the server spells its
columns (`:tableType`, `:isTemporary`).

    Latu.Catalog.list_tables(session, pattern: "latu_*")
    #=> {:ok, [%{name: "latu_tbl_1", tableType: "MANAGED", isTemporary: false, ...}]}

This is the useful subset of `pyspark.sql.Catalog`, not all of it: catalogs, databases,
tables, views and the cache. Creating or describing a single object, and the function
catalog, are left out — each is one `Latu.sql/2` away.

# `cache_table`

```elixir
@spec cache_table(Latu.Session.t(), String.t() | atom()) :: void()
```

Cache the table at Spark's default storage level (docs/deviations.md).

# `cache_table!`

```elixir
@spec cache_table!(Latu.Session.t(), String.t() | atom()) :: :ok
```

Like `cache_table/2`, raising on failure.

# `clear_cache`

```elixir
@spec clear_cache(Latu.Session.t()) :: void()
```

Drop every cached table.

# `clear_cache!`

```elixir
@spec clear_cache!(Latu.Session.t()) :: :ok
```

Like `clear_cache/1`, raising on failure.

# `current_catalog`

```elixir
@spec current_catalog(Latu.Session.t()) :: result(String.t())
```

The current catalog's name.

# `current_catalog!`

```elixir
@spec current_catalog!(Latu.Session.t()) :: String.t()
```

Like `current_catalog/1`, raising on failure.

# `current_database`

```elixir
@spec current_database(Latu.Session.t()) :: result(String.t())
```

The current database's name.

# `current_database!`

```elixir
@spec current_database!(Latu.Session.t()) :: String.t()
```

Like `current_database/1`, raising on failure.

# `database_exists`

```elixir
@spec database_exists(Latu.Session.t(), String.t() | atom()) :: result(boolean())
```

Whether the database exists.

# `database_exists!`

```elixir
@spec database_exists!(Latu.Session.t(), String.t() | atom()) :: boolean()
```

Like `database_exists/2`, raising on failure.

# `drop_global_temp_view`

```elixir
@spec drop_global_temp_view(Latu.Session.t(), String.t() | atom()) ::
  result(boolean())
```

Drop a global temp view; answers like `drop_temp_view/2`.

# `drop_global_temp_view!`

```elixir
@spec drop_global_temp_view!(Latu.Session.t(), String.t() | atom()) :: boolean()
```

Like `drop_global_temp_view/2`, raising on failure.

# `drop_table`

```elixir
@spec drop_table(Latu.Session.t(), String.t() | atom(), keyword()) :: void()
```

Drop a table. `if_exists: true` tolerates a missing one; `purge: true` skips the trash.

The inverse of `Latu.save_as_table/3` — what the write tests clean up with.

# `drop_table!`

```elixir
@spec drop_table!(Latu.Session.t(), String.t() | atom(), keyword()) :: :ok
```

Like `drop_table/3`, raising on failure.

# `drop_temp_view`

```elixir
@spec drop_temp_view(Latu.Session.t(), String.t() | atom()) :: result(boolean())
```

Drop a temp view. `{:ok, true}` when it existed — Spark answers rather than raising.

# `drop_temp_view!`

```elixir
@spec drop_temp_view!(Latu.Session.t(), String.t() | atom()) :: boolean()
```

Like `drop_temp_view/2`, raising on failure.

# `drop_view`

```elixir
@spec drop_view(Latu.Session.t(), String.t() | atom(), keyword()) :: void()
```

Drop a (non-temporary) view. `if_exists: true` tolerates a missing one.

# `drop_view!`

```elixir
@spec drop_view!(Latu.Session.t(), String.t() | atom(), keyword()) :: :ok
```

Like `drop_view/3`, raising on failure.

# `is_cached`

```elixir
@spec is_cached(Latu.Session.t(), String.t() | atom()) :: result(boolean())
```

Whether the table is cached.

# `is_cached!`

```elixir
@spec is_cached!(Latu.Session.t(), String.t() | atom()) :: boolean()
```

Like `is_cached/2`, raising on failure.

# `list_catalogs`

```elixir
@spec list_catalogs(
  Latu.Session.t(),
  keyword()
) :: result([map()])
```

Every catalog, optionally filtered: `pattern: "spark*"` (SQL LIKE, `*` and `|`).

# `list_catalogs!`

```elixir
@spec list_catalogs!(
  Latu.Session.t(),
  keyword()
) :: [map()]
```

Like `list_catalogs/2`, raising on failure.

# `list_columns`

```elixir
@spec list_columns(Latu.Session.t(), String.t() | atom(), keyword()) ::
  result([map()])
```

The table's columns: name, dataType, nullable, partition and bucket flags.

# `list_columns!`

```elixir
@spec list_columns!(Latu.Session.t(), String.t() | atom(), keyword()) :: [map()]
```

Like `list_columns/3`, raising on failure.

# `list_databases`

```elixir
@spec list_databases(
  Latu.Session.t(),
  keyword()
) :: result([map()])
```

Every database, optionally filtered by `:pattern`.

# `list_databases!`

```elixir
@spec list_databases!(
  Latu.Session.t(),
  keyword()
) :: [map()]
```

Like `list_databases/2`, raising on failure.

# `list_tables`

```elixir
@spec list_tables(
  Latu.Session.t(),
  keyword()
) :: result([map()])
```

Tables and views, temporary ones included.

`db_name: "other"` looks elsewhere than the current database; `pattern: "latu_*"` filters.

# `list_tables!`

```elixir
@spec list_tables!(
  Latu.Session.t(),
  keyword()
) :: [map()]
```

Like `list_tables/2`, raising on failure.

# `refresh_table`

```elixir
@spec refresh_table(Latu.Session.t(), String.t() | atom()) :: void()
```

Refresh Spark's metadata and cache for a table whose files changed underneath it.

# `refresh_table!`

```elixir
@spec refresh_table!(Latu.Session.t(), String.t() | atom()) :: :ok
```

Like `refresh_table/2`, raising on failure.

# `set_current_catalog`

```elixir
@spec set_current_catalog(Latu.Session.t(), String.t() | atom()) :: void()
```

Switch catalogs.

# `set_current_catalog!`

```elixir
@spec set_current_catalog!(Latu.Session.t(), String.t() | atom()) :: :ok
```

Like `set_current_catalog/2`, raising on failure.

# `set_current_database`

```elixir
@spec set_current_database(Latu.Session.t(), String.t() | atom()) :: void()
```

Switch databases.

# `set_current_database!`

```elixir
@spec set_current_database!(Latu.Session.t(), String.t() | atom()) :: :ok
```

Like `set_current_database/2`, raising on failure.

# `table_exists`

```elixir
@spec table_exists(Latu.Session.t(), String.t() | atom(), keyword()) ::
  result(boolean())
```

Whether the table or view exists. `db_name:` as in `list_tables/2`.

# `table_exists!`

```elixir
@spec table_exists!(Latu.Session.t(), String.t() | atom(), keyword()) :: boolean()
```

Like `table_exists/3`, raising on failure.

# `uncache_table`

```elixir
@spec uncache_table(Latu.Session.t(), String.t() | atom()) :: void()
```

Drop the table from the cache.

# `uncache_table!`

```elixir
@spec uncache_table!(Latu.Session.t(), String.t() | atom()) :: :ok
```

Like `uncache_table/2`, raising on failure.

---

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