Skip to content

Commit

Permalink
Add catalog public api (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrluis committed Jul 16, 2024
1 parent c96e66f commit 7de8442
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 10 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.


# [Unreleased]

# v0.2.0

Official first release

# v0.1.0

First release (retired)
111 changes: 110 additions & 1 deletion lib/ex_iceberg/catalog.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
defmodule ExIceberg.Catalog do
@moduledoc """
This module provides functions to interact with the catalog.
## Usage Example
catalog = ExIceberg.Catalog.new("my_catalog", :rest, %{})
{:ok, catalog, _} = ExIceberg.Catalog.create_namespace(catalog, "my_namespace", %{})
{:ok, catalog, _} = ExIceberg.Catalog.list_namespaces(catalog)
As you see in the example above, you need to pass the reasign and pass the catalog to the next function.
"""

@callback create_namespace(t(), String.t(), map()) :: {:ok, t(), map()} | {:error, String.t()}
@callback list_namespaces(t()) :: {:ok, t(), list(String.t())} | {:error, String.t()}
@callback drop_namespace(t(), String.t()) :: {:ok, t(), map()} | {:error, String.t()}
Expand All @@ -9,6 +22,102 @@ defmodule ExIceberg.Catalog do

@type t :: %{
name: String.t(),
config: ExIceberg.Config.t()
type: String.t(),
config: struct()
}

alias ExIceberg.Rest.Catalog, as: RestCatalog

@doc """
Defines a catalog to be accessed by the client.
## Examples
iex> ExIceberg.Catalog.new("my_catalog", :rest, %{})
%ExIceberg.Rest.Catalog{name: "my_catalog", config: %{}}
## Catalog Types
* `:rest` - REST API catalog.
## Configuration
The configuration for the catalog is specific to the catalog type.
* [Rest Catalog Configuration](`ExIceberg.Rest.Config`)
"""
def new(name, :rest = _type, config), do: RestCatalog.new(name, config)
def new(_name, _type, _config), do: {:error, "Invalid catalog type"}

@doc """
Creates a new namespace in the catalog.
## Examples
iex> ExIceberg.Catalog.create_namespace(catalog, "my_namespace", %{})
{:ok, catalog, %{}}
"""
def create_namespace(catalog, namespace, properties) do
catalog.__struct__.create_namespace(catalog, namespace, properties)
end

@doc """
Lists the namespaces in the catalog.
## Examples
iex> ExIceberg.Catalog.list_namespaces(catalog)
{:ok, catalog, ["namespace1", "namespace2"]}
"""
def list_namespaces(catalog) do
catalog.__struct__.list_namespaces(catalog)
end

@doc """
Drops a namespace from the catalog.
## Examples
iex> ExIceberg.Catalog.drop_namespace(catalog, "my_namespace")
{:ok, catalog, %{}}
"""
def drop_namespace(catalog, namespace) do
catalog.__struct__.drop_namespace(catalog, namespace)
end

@doc """
Loads the metadata for a namespace in the catalog.
## Examples
iex> ExIceberg.Catalog.load_namespace_metadata(catalog, "my_namespace")
{:ok, catalog, %{}}
"""
def load_namespace_metadata(catalog, namespace) do
catalog.__struct__.load_namespace_metadata(catalog, namespace)
end

@doc """
Checks if a namespace exists in the catalog.
## Examples
iex> ExIceberg.Catalog.namespace_exists?(catalog, "my_namespace")
{:ok, catalog, true}
"""
def namespace_exists?(catalog, namespace) do
catalog.__struct__.namespace_exists?(catalog, namespace)
end

@doc """
Updates the properties of a namespace in the catalog.
## Examples
iex> ExIceberg.Catalog.update_namespace_properties(catalog, "my_namespace", [], %{})
{:ok, catalog, %{}}
"""
def update_namespace_properties(catalog, namespace, removals, updates) do
catalog.__struct__.update_namespace_properties(catalog, namespace, removals, updates)
end
end
6 changes: 1 addition & 5 deletions lib/ex_iceberg/glue/catalog.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
defmodule ExIceberg.Glue.Catalog do
@moduledoc """
Module to interact with the Glue catalog.
"""

# @behaviour ExIceberg.Catalog
@moduledoc false
end
1 change: 1 addition & 0 deletions lib/ex_iceberg/glue/client.ex
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
defmodule ExIceberg.Glue.Client do
@moduledoc false
end
1 change: 1 addition & 0 deletions lib/ex_iceberg/glue/config.ex
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
defmodule ExIceberg.Glue.Config do
@moduledoc false
end
4 changes: 1 addition & 3 deletions lib/ex_iceberg/rest/catalog.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
defmodule ExIceberg.Rest.Catalog do
@moduledoc """
Module to interact with the REST catalog of Apache Iceberg.
"""
@moduledoc false

alias ExIceberg.Rest.Client
alias ExIceberg.Rest.Config
Expand Down
1 change: 1 addition & 0 deletions lib/ex_iceberg/rest/client.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ExIceberg.Rest.Client do
@moduledoc false
alias ExIceberg.Rest.Config

def new(options \\ []) do
Expand Down
2 changes: 2 additions & 0 deletions lib/ex_iceberg/rest/response.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule ExIceberg.Rest.Response do
@moduledoc false

def parse({:ok, %Req.Response{status: 404}}, :namespace_exists) do
{:ok, false}
end
Expand Down
1 change: 1 addition & 0 deletions lib/ex_iceberg/s3/config.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ExIceberg.S3.Config do
@moduledoc false
defstruct [
:endpoint,
:access_key_id,
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ExIceberg.MixProject do
use Mix.Project

@version "0.1.0"
@version "0.2.0"
@description "ExIceberg is an Elixir library for interacting with Apache Iceberg."

def project do
Expand Down

0 comments on commit 7de8442

Please sign in to comment.