iceberg-cpp
Loading...
Searching...
No Matches
catalog_store.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
28
29#include <cstdint>
30#include <functional>
31#include <memory>
32#include <optional>
33#include <string>
34#include <string_view>
35#include <unordered_map>
36#include <vector>
37
38#include "iceberg/catalog/sql/iceberg_sql_catalog_export.h"
39#include "iceberg/result.h"
40
41namespace iceberg::sql {
42
44struct ICEBERG_SQL_CATALOG_EXPORT NamespaceProperty {
46 std::string key;
48 std::optional<std::string> value;
49};
50
52struct ICEBERG_SQL_CATALOG_EXPORT CatalogStoreOptions {
54 std::string catalog_name;
56 std::string uri;
58 int32_t max_connections = 1;
60 std::unordered_map<std::string, std::string> properties;
61};
62
72class ICEBERG_SQL_CATALOG_EXPORT CatalogStore {
73 public:
74 virtual ~CatalogStore() = default;
75
79 virtual Status Initialize() = 0;
80
84 virtual Result<std::vector<std::string>> ListNamespaceNames() = 0;
85
90 virtual Result<std::vector<NamespaceProperty>> GetNamespaceProperties(
91 std::string_view ns) = 0;
92
102 virtual Status InsertNamespaceProperty(std::string_view ns, std::string_view key,
103 std::optional<std::string_view> value) = 0;
104
110 virtual Status DeleteNamespaceProperty(std::string_view ns, std::string_view key) = 0;
111
116 virtual Result<int64_t> DeleteNamespace(std::string_view ns) = 0;
117
122 virtual Result<std::vector<std::string>> ListTableNames(std::string_view ns) = 0;
123
129 virtual Result<bool> TableExists(std::string_view ns, std::string_view name) = 0;
130
137 virtual Result<std::optional<std::string>> GetTableMetadataLocation(
138 std::string_view ns, std::string_view name) = 0;
139
149 virtual Status InsertTable(std::string_view ns, std::string_view name,
150 std::string_view metadata_location) = 0;
151
163 virtual Result<int64_t> UpdateTableMetadataLocation(
164 std::string_view ns, std::string_view name, std::string_view new_location,
165 std::string_view new_previous_location,
166 std::string_view expected_current_location) = 0;
167
173 virtual Result<int64_t> DeleteTable(std::string_view ns, std::string_view name) = 0;
174
185 virtual Result<int64_t> RenameTable(std::string_view from_ns,
186 std::string_view from_name, std::string_view to_ns,
187 std::string_view to_name) = 0;
188
198 virtual Status RunInTransaction(const std::function<Status()>& body) = 0;
199};
200
208ICEBERG_SQL_CATALOG_EXPORT Result<std::shared_ptr<CatalogStore>> MakeSqliteCatalogStore(
209 const CatalogStoreOptions& options);
210
219ICEBERG_SQL_CATALOG_EXPORT Result<std::shared_ptr<CatalogStore>>
221
230ICEBERG_SQL_CATALOG_EXPORT Result<std::shared_ptr<CatalogStore>> MakeMySqlCatalogStore(
231 const CatalogStoreOptions& options);
232
233} // namespace iceberg::sql
ICEBERG_SQL_CATALOG_EXPORT Result< std::shared_ptr< CatalogStore > > MakeMySqlCatalogStore(const CatalogStoreOptions &options)
Build the built-in MySQL catalog store (sqlpp23 + libmysqlclient).
Definition catalog_store_mysql.cc:67
ICEBERG_SQL_CATALOG_EXPORT Result< std::shared_ptr< CatalogStore > > MakePostgreSqlCatalogStore(const CatalogStoreOptions &options)
Build the built-in PostgreSQL catalog store (sqlpp23 + libpq).
Definition catalog_store_postgresql.cc:61
ICEBERG_SQL_CATALOG_EXPORT Result< std::shared_ptr< CatalogStore > > MakeSqliteCatalogStore(const CatalogStoreOptions &options)
Build the built-in SQLite catalog store (sqlpp23 + SQLite3).
Definition catalog_store_sqlite3.cc:64
Semantic, driver-agnostic storage interface for the SQL catalog.
Definition catalog_store.h:72
virtual Result< std::optional< std::string > > GetTableMetadataLocation(std::string_view ns, std::string_view name)=0
Return the current metadata location of (ns, name).
virtual Result< int64_t > DeleteTable(std::string_view ns, std::string_view name)=0
Delete the table row (ns, name), if present.
virtual Result< int64_t > RenameTable(std::string_view from_ns, std::string_view from_name, std::string_view to_ns, std::string_view to_name)=0
Move a table row to a new namespace and/or name.
virtual Status InsertTable(std::string_view ns, std::string_view name, std::string_view metadata_location)=0
Insert a new table row with the given metadata location.
virtual Result< int64_t > UpdateTableMetadataLocation(std::string_view ns, std::string_view name, std::string_view new_location, std::string_view new_previous_location, std::string_view expected_current_location)=0
Conditionally update a table's metadata location (optimistic CAS).
virtual Status DeleteNamespaceProperty(std::string_view ns, std::string_view key)=0
Delete the property row identified by (ns, key), if present.
virtual Result< std::vector< NamespaceProperty > > GetNamespaceProperties(std::string_view ns)=0
Return all property rows stored for ns.
virtual Result< int64_t > DeleteNamespace(std::string_view ns)=0
Delete all property rows for ns.
virtual Status InsertNamespaceProperty(std::string_view ns, std::string_view key, std::optional< std::string_view > value)=0
Insert one property row for ns.
virtual Result< bool > TableExists(std::string_view ns, std::string_view name)=0
Whether a row exists for the table (ns, name).
virtual Status RunInTransaction(const std::function< Status()> &body)=0
Execute body atomically inside a single transaction.
virtual Result< std::vector< std::string > > ListTableNames(std::string_view ns)=0
Return the table names stored directly under ns.
virtual Status Initialize()=0
Create the backing tables if they do not already exist.
virtual Result< std::vector< std::string > > ListNamespaceNames()=0
Return the distinct namespace identifiers known to this catalog.
Connection parameters used to construct a built-in CatalogStore.
Definition catalog_store.h:52
std::string uri
Connector-specific connection string.
Definition catalog_store.h:56
std::string catalog_name
Logical catalog name used to scope rows.
Definition catalog_store.h:54
std::unordered_map< std::string, std::string > properties
Additional connector-specific properties.
Definition catalog_store.h:60
A namespace property row.
Definition catalog_store.h:44
std::optional< std::string > value
Property value, or std::nullopt for SQL NULL.
Definition catalog_store.h:48
std::string key
Property key.
Definition catalog_store.h:46