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"
38#include "iceberg/catalog/sql/iceberg_sql_catalog_export.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
86 static Result<std::shared_ptr<SqlCatalog>> Make(const SqlCatalogConfig& config,
87 std::shared_ptr<FileIO> file_io,
88 std::shared_ptr<CatalogStore> store);
89
90 std::string_view name() const override;
91
92 Status CreateNamespace(
93 const Namespace& ns,
94 const std::unordered_map<std::string, std::string>& properties) override;
95
96 Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const override;
97
98 Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
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
105 Status UpdateNamespaceProperties(
106 const Namespace& ns, const std::unordered_map<std::string, std::string>& updates,
107 const std::unordered_set<std::string>& removals) override;
108
109 Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns) const override;
110
111 Result<std::shared_ptr<Table>> CreateTable(
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
117 Result<std::shared_ptr<Table>> UpdateTable(
118 const TableIdentifier& identifier,
119 const std::vector<std::unique_ptr<TableRequirement>>& requirements,
120 const std::vector<std::unique_ptr<TableUpdate>>& updates) override;
121
122 Result<std::shared_ptr<Transaction>> StageCreateTable(
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
138 Result<std::shared_ptr<Table>> LoadTable(const TableIdentifier& identifier) override;
139
140 Result<std::shared_ptr<Table>> RegisterTable(
141 const TableIdentifier& identifier,
142 const std::string& metadata_file_location) override;
143
150 static Result<std::shared_ptr<SqlCatalog>> MakeSqliteCatalog(
151 const SqlCatalogConfig& config, std::shared_ptr<FileIO> file_io);
152
160 static Result<std::shared_ptr<SqlCatalog>> MakePostgreSqlCatalog(
161 const SqlCatalogConfig& config, std::shared_ptr<FileIO> file_io);
162
170 static Result<std::shared_ptr<SqlCatalog>> MakeMySqlCatalog(
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
178 Result<std::string> GetTableMetadataLocation(const TableIdentifier& identifier) const;
179
181 Result<std::shared_ptr<Table>> LoadTableFrom(const TableIdentifier& identifier,
182 const std::string& metadata_location);
183
184 SqlCatalogConfig config_;
185 std::shared_ptr<FileIO> file_io_;
186 std::shared_ptr<CatalogStore> store_;
187};
188
189} // namespace iceberg::sql
A Catalog API for table create, drop, and load operations.
Definition catalog.h:39
SQL-backed Iceberg catalog.
Definition sql_catalog.h:67
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