Skip to content
Merged
2 changes: 2 additions & 0 deletions src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set(ICEBERG_INCLUDES "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>"
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>")
set(ICEBERG_SOURCES
arrow_c_data_internal.cc
catalog/in_memory_catalog.cc
demo.cc
expression/expression.cc
file_reader.cc
Expand Down Expand Up @@ -74,6 +75,7 @@ add_iceberg_lib(iceberg

iceberg_install_all_headers(iceberg)

add_subdirectory(catalog)
add_subdirectory(expression)
add_subdirectory(util)

Expand Down
91 changes: 73 additions & 18 deletions src/iceberg/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "iceberg/result.h"
Expand All @@ -42,6 +43,67 @@ class ICEBERG_EXPORT Catalog {
/// \brief Return the name for this catalog
virtual std::string_view name() const = 0;

/// \brief Create a namespace with associated properties.
///
/// \param ns the namespace to create
/// \param properties a key-value map of metadata for the namespace
/// \return Status::OK if created successfully;
/// ErrorKind::kAlreadyExists if the namespace already exists;
/// ErrorKind::kNotSupported if the operation is not supported
virtual Status CreateNamespace(
const Namespace& ns,
const std::unordered_map<std::string, std::string>& properties) = 0;

/// \brief List child namespaces from the given namespace.
///
/// \param ns the parent namespace
/// \return a list of child namespaces;
/// ErrorKind::kNoSuchNamespace if the given namespace does not exist
virtual Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const = 0;

/// \brief Get metadata properties for a namespace.
///
/// \param ns the namespace to look up
/// \return a key-value map of metadata properties;
/// ErrorKind::kNoSuchNamespace if the namespace does not exist
virtual Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
const Namespace& ns) const = 0;

/// \brief Drop a namespace.
///
/// \param ns the namespace to drop
/// \return Status::OK if dropped successfully;
/// ErrorKind::kNoSuchNamespace if the namespace does not exist;
/// ErrorKind::kNotAllowed if the namespace is not empty
virtual Status DropNamespace(const Namespace& ns) = 0;

/// \brief Check whether the namespace exists.
///
/// \param ns the namespace to check
/// \return true if the namespace exists, false otherwise
virtual Result<bool> NamespaceExists(const Namespace& ns) const = 0;

/// \brief Set metadata properties on a namespace.
///
/// \param ns the namespace to modify
/// \param properties the properties to set or update
/// \return Status::OK if updated successfully;
/// ErrorKind::kNoSuchNamespace if the namespace does not exist;
/// ErrorKind::kNotSupported if the operation is not supported
virtual Status SetNamespaceProperties(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about merging SetNamespaceProperties and RemoveNamespaceProperties into a single UpdateNamespaceProperties(updates, removals)? This is a single call in the rest catalog spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am referring to the implementation in java implementations, which has two interfaces. Should we follow the REST catalog spec?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fokko WDYT?

const Namespace& ns,
const std::unordered_map<std::string, std::string>& properties) = 0;

/// \brief Remove a set of metadata properties from a namespace.
///
/// \param ns the namespace to modify
/// \param properties the set of property keys to remove
/// \return Status::OK if removed successfully;
/// ErrorKind::kNoSuchNamespace if the namespace does not exist;
/// ErrorKind::kNotSupported if the operation is not supported
virtual Status RemoveNamespaceProperties(
const Namespace& ns, const std::unordered_set<std::string>& properties) = 0;

/// \brief Return all the identifiers under this namespace
///
/// \param ns a namespace
Expand Down Expand Up @@ -80,8 +142,8 @@ class ICEBERG_EXPORT Catalog {
/// \param spec a partition spec
/// \param location a location for the table; leave empty if unspecified
/// \param properties a string map of table properties
/// \return a Transaction to create the table or ErrorKind::kAlreadyExists if the table
/// already exists
/// \return a Transaction to create the table or ErrorKind::kAlreadyExists if the
/// table already exists
virtual Result<std::shared_ptr<Transaction>> StageCreateTable(
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
const std::string& location,
Expand All @@ -90,8 +152,11 @@ class ICEBERG_EXPORT Catalog {
/// \brief Check whether table exists
///
/// \param identifier a table identifier
/// \return true if the table exists, false otherwise
virtual bool TableExists(const TableIdentifier& identifier) const = 0;
/// \return Result<bool> indicating table exists or not.
/// - On success, the table existence was successfully checked (actual
/// existence may be inferred elsewhere).
/// - On failure, contains error information.
virtual Result<bool> TableExists(const TableIdentifier& identifier) const = 0;

/// \brief Drop a table; optionally delete data and metadata files
///
Expand All @@ -100,8 +165,10 @@ class ICEBERG_EXPORT Catalog {
///
/// \param identifier a table identifier
/// \param purge if true, delete all data and metadata files in the table
/// \return true if the table was dropped, false if the table did not exist
virtual bool DropTable(const TableIdentifier& identifier, bool purge) = 0;
/// \return Status indicating the outcome of the operation.
/// - On success, the table was dropped (or did not exist).
/// - On failure, contains error information.
virtual Status DropTable(const TableIdentifier& identifier, bool purge) = 0;

/// \brief Load a table
///
Expand All @@ -119,18 +186,6 @@ class ICEBERG_EXPORT Catalog {
virtual Result<std::shared_ptr<Table>> RegisterTable(
const TableIdentifier& identifier, const std::string& metadata_file_location) = 0;

/// \brief Initialize a catalog given a custom name and a map of catalog properties
///
/// A custom Catalog implementation must have a default constructor. A compute engine
/// will first initialize the catalog without any arguments, and then call this method
/// to complete catalog initialization with properties passed into the engine.
///
/// \param name a custom name for the catalog
/// \param properties catalog properties
virtual void Initialize(
const std::string& name,
const std::unordered_map<std::string, std::string>& properties) = 0;

/// \brief Instantiate a builder to either create a table or start a create/replace
/// transaction
///
Expand Down
18 changes: 18 additions & 0 deletions src/iceberg/catalog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

iceberg_install_all_headers(iceberg/catalog)
Loading
Loading