forked from alibaba/paimon-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog.h
More file actions
119 lines (103 loc) · 5.16 KB
/
catalog.h
File metadata and controls
119 lines (103 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright 2024-present Alibaba Inc.
*
* Licensed 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.
*/
#pragma once
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "paimon/catalog/identifier.h"
#include "paimon/result.h"
#include "paimon/schema/schema.h"
#include "paimon/status.h"
#include "paimon/type_fwd.h"
#include "paimon/visibility.h"
struct ArrowSchema;
namespace paimon {
class Identifier;
/// This interface is responsible for reading and writing metadata such as database/table from a
/// paimon catalog.
class PAIMON_EXPORT Catalog {
public:
static const char SYSTEM_DATABASE_NAME[];
static const char SYSTEM_TABLE_SPLITTER[];
static const char DB_SUFFIX[];
static const char DB_LOCATION_PROP[];
/// %Factory method for creating a `Catalog` instance.
///
/// @param root_path Path to the root directory where the catalog is located.
/// @param options Configuration options for catalog initialization.
/// @return A result containing a unique pointer to a `Catalog` instance, or an error status.
static Result<std::unique_ptr<Catalog>> Create(
const std::string& root_path, const std::map<std::string, std::string>& options);
virtual ~Catalog() = default;
/// Creates a database with the specified properties.
///
/// @param name Name of the database to be created.
/// @param options Additional properties associated with the database.
/// @param ignore_if_exists If true, no action is taken if the database already exists.
/// If false, an error status is returned if the database exists.
/// @return A status indicating success or failure.
virtual Status CreateDatabase(const std::string& name,
const std::map<std::string, std::string>& options,
bool ignore_if_exists) = 0;
/// Creates a new table in the catalog.
///
/// @note System tables cannot be created using this method.
///
/// @param identifier Identifier of the table to be created.
/// @param c_schema The schema of the table to be created.
/// @param partition_keys List of columns that should be used as partition keys for the table.
/// @param primary_keys List of columns that should be used as primary keys for the table.
/// @param options Additional table-specific options.
/// @param ignore_if_exists If true, no action is taken if the table already exists.
/// If false, an error status is returned if the table exists.
/// @return A status indicating success or failure.
virtual Status CreateTable(const Identifier& identifier, ArrowSchema* c_schema,
const std::vector<std::string>& partition_keys,
const std::vector<std::string>& primary_keys,
const std::map<std::string, std::string>& options,
bool ignore_if_exists) = 0;
/// Lists all the databases available in the catalog.
///
/// @return A result containing a vector of database names, or an error status.
virtual Result<std::vector<std::string>> ListDatabases() const = 0;
/// Lists all the tables within a specified database.
///
/// @note System tables will not be listed.
///
/// @param db_name The name of the database to list tables from.
/// @return A result containing a vector of table names in the specified database, or an error
/// status.
virtual Result<std::vector<std::string>> ListTables(const std::string& db_name) const = 0;
/// Checks whether a database with the specified name exists in the catalog.
///
/// @param db_name The name of the database to check for existence.
/// @return A result containing true if the database exists, false otherwise, or an error status.
virtual Result<bool> DataBaseExists(const std::string& db_name) const = 0;
/// Checks whether a table with the specified identifier exists in the catalog.
///
/// @param identifier The identifier of the table to check for existence.
/// @return A result containing true if the table exists, false otherwise, or an error status.
virtual Result<bool> TableExists(const Identifier& identifier) const = 0;
/// Loads the latest schema of a specified table.
///
/// @note System tables will not be supported.
///
/// @param identifier The identifier (database and table name) of the table to load.
/// @return A result containing table schema if the table exists, or an error status on failure.
virtual Result<std::shared_ptr<Schema>> LoadTableSchema(const Identifier& identifier) const = 0;
};
} // namespace paimon