iceberg-cpp
Loading...
Searching...
No Matches
sql_catalog.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
27
28#include <cstdint>
29#include <memory>
30#include <string>
31#include <string_view>
32#include <unordered_map>
33#include <unordered_set>
34#include <vector>
35
36#include "iceberg/catalog.h"
39#include "iceberg/result.h"
41#include "iceberg/type_fwd.h"
42
43namespace iceberg::sql {
44
46constexpr static int32_t kMaxConnections = 10;
47
49struct ICEBERG_SQL_CATALOG_EXPORT SqlCatalogConfig {
52 std::string name = "sql_catalog";
54 std::string uri;
56 std::string warehouse_location;
59 int32_t max_connections = kMaxConnections;
61 std::unordered_map<std::string, std::string> props;
62};
63
65class ICEBERG_SQL_CATALOG_EXPORT SqlCatalog
66 : public Catalog,
67 public std::enable_shared_from_this<SqlCatalog> {
68 public:
69 ~SqlCatalog() override;
70
71 SqlCatalog(const SqlCatalog&) = delete;
72 SqlCatalog& operator=(const SqlCatalog&) = delete;
73 SqlCatalog(SqlCatalog&&) = delete;
74 SqlCatalog& operator=(SqlCatalog&&) = delete;
75
87 std::shared_ptr<FileIO> file_io,
88 std::shared_ptr<CatalogStore> store);
89
90 std::string_view name() const override;
91
93 const Namespace& ns,
94 const std::unordered_map<std::string, std::string>& properties) override;
95
97
99 const Namespace& ns) const override;
100
101 Status DropNamespace(const Namespace& ns) override;
102
103 Result<bool> NamespaceExists(const Namespace& ns) const override;
104
106 const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
107 const std::unordered_set<std::string>& removals) override;
108
110
112 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
113 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
114 const std::string& location,
115 const std::unordered_map<std::string, std::string>& properties) override;
116
118 const TableIdentifier& identifier,
119 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
120 const std::vector<std::unique_ptr<TableUpdate>>& updates) override;
121
123 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
124 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
125 const std::string& location,
126 const std::unordered_map<std::string, std::string>& properties) override;
127
128 Result<bool> TableExists(const TableIdentifier& identifier) const override;
129
134 Status DropTable(const TableIdentifier& identifier, bool purge) override;
135
136 Status RenameTable(const TableIdentifier& from, const TableIdentifier& to) override;
137
139
141 const TableIdentifier& identifier,
142 const std::string& metadata_file_location) override;
143
151 const SqlCatalogConfig& config, std::shared_ptr<FileIO> file_io);
152
161 const SqlCatalogConfig& config, std::shared_ptr<FileIO> file_io);
162
171 const SqlCatalogConfig& config, std::shared_ptr<FileIO> file_io);
172
173 private:
174 SqlCatalog(SqlCatalogConfig config, std::shared_ptr<FileIO> file_io,
175 std::shared_ptr<CatalogStore> store,
176 std::shared_ptr<MetricsReporter> reporter);
177
179 Result<std::string> GetTableMetadataLocation(const TableIdentifier& identifier) const;
180
182 Result<std::shared_ptr<Table>> LoadTableFrom(const TableIdentifier& identifier,
183 const std::string& metadata_location);
184
185 SqlCatalogConfig config_;
186 std::shared_ptr<FileIO> file_io_;
187 std::shared_ptr<CatalogStore> store_;
188 std::shared_ptr<MetricsReporter> reporter_;
189};
190
191} // namespace iceberg::sql
Define the catalog API for table and namespace operations.
A Catalog API for table create, drop, and load operations.
Definition catalog.h:42
SQL-backed Iceberg catalog.
Definition sql_catalog.h:67
Status CreateNamespace(const Namespace &ns, const std::unordered_map< std::string, std::string > &properties) override
Create a namespace with associated properties.
static Result< std::shared_ptr< SqlCatalog > > Make(const SqlCatalogConfig &config, std::shared_ptr< FileIO > file_io, std::shared_ptr< CatalogStore > store)
Create a catalog backed by a user-supplied CatalogStore.
std::string_view name() const override
Return the name for this catalog.
Result< bool > NamespaceExists(const Namespace &ns) const override
Check whether the namespace exists.
Result< std::shared_ptr< Table > > UpdateTable(const TableIdentifier &identifier, const std::vector< std::unique_ptr< TableRequirement > > &requirements, const std::vector< std::unique_ptr< TableUpdate > > &updates) override
Update a table.
Result< std::vector< Namespace > > ListNamespaces(const Namespace &ns) const override
List child namespaces from the given namespace.
Result< std::unordered_map< std::string, std::string > > GetNamespaceProperties(const Namespace &ns) const override
Get metadata properties for a namespace.
Result< std::shared_ptr< Table > > LoadTable(const TableIdentifier &identifier) override
Load a table.
static Result< std::shared_ptr< SqlCatalog > > MakeMySqlCatalog(const SqlCatalogConfig &config, std::shared_ptr< FileIO > file_io)
Create a catalog backed by the built-in MySQL client.
Status DropNamespace(const Namespace &ns) override
Drop a namespace.
Result< std::shared_ptr< Transaction > > StageCreateTable(const TableIdentifier &identifier, const std::shared_ptr< Schema > &schema, const std::shared_ptr< PartitionSpec > &spec, const std::shared_ptr< SortOrder > &order, const std::string &location, const std::unordered_map< std::string, std::string > &properties) override
Start a transaction to create a table.
Result< std::vector< TableIdentifier > > ListTables(const Namespace &ns) const override
Return all the identifiers under this namespace.
Status RenameTable(const TableIdentifier &from, const TableIdentifier &to) override
Rename a table.
Status DropTable(const TableIdentifier &identifier, bool purge) override
Drop a table.
Result< std::shared_ptr< Table > > CreateTable(const TableIdentifier &identifier, const std::shared_ptr< Schema > &schema, const std::shared_ptr< PartitionSpec > &spec, const std::shared_ptr< SortOrder > &order, const std::string &location, const std::unordered_map< std::string, std::string > &properties) override
Create a table.
Status UpdateNamespaceProperties(const Namespace &ns, const std::unordered_map< std::string, std::string > &updates, const std::unordered_set< std::string > &removals) override
Update a namespace's properties by applying additions and removals.
static Result< std::shared_ptr< SqlCatalog > > MakePostgreSqlCatalog(const SqlCatalogConfig &config, std::shared_ptr< FileIO > file_io)
Create a catalog backed by the built-in PostgreSQL (libpq) client.
Result< bool > TableExists(const TableIdentifier &identifier) const override
Check whether table exists.
Result< std::shared_ptr< Table > > RegisterTable(const TableIdentifier &identifier, const std::string &metadata_file_location) override
Register a table with the catalog if it does not exist.
static Result< std::shared_ptr< SqlCatalog > > MakeSqliteCatalog(const SqlCatalogConfig &config, std::shared_ptr< FileIO > file_io)
Create a catalog backed by the built-in SQLite client.
Define symbol visibility macros for the SQL catalog library.
SQL catalog APIs.
Definition catalog_store.h:41
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.
A namespace in a catalog.
Definition table_identifier.h:35
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
Configuration for the SQL catalog.
Definition sql_catalog.h:49
std::string warehouse_location
Base location used to derive table locations when none is supplied.
Definition sql_catalog.h:56
std::string uri
Database connection string interpreted by the chosen CatalogStore.
Definition sql_catalog.h:54
std::unordered_map< std::string, std::string > props
Additional connector-specific properties.
Definition sql_catalog.h:61