|
| 1 | +/* |
| 2 | + * Copyright 2024-present Alibaba Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#pragma once |
| 18 | + |
| 19 | +#include <map> |
| 20 | +#include <memory> |
| 21 | +#include <string> |
| 22 | +#include <vector> |
| 23 | + |
| 24 | +#include "paimon/catalog/identifier.h" |
| 25 | +#include "paimon/result.h" |
| 26 | +#include "paimon/status.h" |
| 27 | +#include "paimon/type_fwd.h" |
| 28 | +#include "paimon/visibility.h" |
| 29 | + |
| 30 | +struct ArrowSchema; |
| 31 | + |
| 32 | +namespace paimon { |
| 33 | +class Identifier; |
| 34 | + |
| 35 | +/// This interface is responsible for reading and writing metadata such as database/table from a |
| 36 | +/// paimon catalog. |
| 37 | +class PAIMON_EXPORT Catalog { |
| 38 | + public: |
| 39 | + static const char SYSTEM_DATABASE_NAME[]; |
| 40 | + static const char SYSTEM_TABLE_SPLITTER[]; |
| 41 | + static const char DB_SUFFIX[]; |
| 42 | + static const char DB_LOCATION_PROP[]; |
| 43 | + |
| 44 | + /// %Factory method for creating a `Catalog` instance. |
| 45 | + /// |
| 46 | + /// @param root_path Path to the root directory where the catalog is located. |
| 47 | + /// @param options Configuration options for catalog initialization. |
| 48 | + /// @return A result containing a unique pointer to a `Catalog` instance, or an error status. |
| 49 | + static Result<std::unique_ptr<Catalog>> Create( |
| 50 | + const std::string& root_path, const std::map<std::string, std::string>& options); |
| 51 | + |
| 52 | + virtual ~Catalog() = default; |
| 53 | + |
| 54 | + /// Creates a database with the specified properties. |
| 55 | + /// |
| 56 | + /// @param name Name of the database to be created. |
| 57 | + /// @param options Additional properties associated with the database. |
| 58 | + /// @param ignore_if_exists If true, no action is taken if the database already exists. |
| 59 | + /// If false, an error status is returned if the database exists. |
| 60 | + /// @return A status indicating success or failure. |
| 61 | + virtual Status CreateDatabase(const std::string& name, |
| 62 | + const std::map<std::string, std::string>& options, |
| 63 | + bool ignore_if_exists) = 0; |
| 64 | + |
| 65 | + /// Creates a new table in the catalog. |
| 66 | + /// |
| 67 | + /// @note System tables cannot be created using this method. |
| 68 | + /// |
| 69 | + /// @param identifier Identifier of the table to be created. |
| 70 | + /// @param c_schema The schema of the table to be created. |
| 71 | + /// @param partition_keys List of columns that should be used as partition keys for the table. |
| 72 | + /// @param primary_keys List of columns that should be used as primary keys for the table. |
| 73 | + /// @param options Additional table-specific options. |
| 74 | + /// @param ignore_if_exists If true, no action is taken if the table already exists. |
| 75 | + /// If false, an error status is returned if the table exists. |
| 76 | + /// @return A status indicating success or failure. |
| 77 | + virtual Status CreateTable(const Identifier& identifier, ArrowSchema* c_schema, |
| 78 | + const std::vector<std::string>& partition_keys, |
| 79 | + const std::vector<std::string>& primary_keys, |
| 80 | + const std::map<std::string, std::string>& options, |
| 81 | + bool ignore_if_exists) = 0; |
| 82 | + |
| 83 | + /// Lists all the databases available in the catalog. |
| 84 | + /// |
| 85 | + /// @return A result containing a vector of database names, or an error status. |
| 86 | + virtual Result<std::vector<std::string>> ListDatabases() const = 0; |
| 87 | + |
| 88 | + /// Lists all the tables within a specified database. |
| 89 | + /// |
| 90 | + /// @note System tables will not be listed. |
| 91 | + /// |
| 92 | + /// @param db_name The name of the database to list tables from. |
| 93 | + /// @return A result containing a vector of table names in the specified database, or an error |
| 94 | + /// status. |
| 95 | + virtual Result<std::vector<std::string>> ListTables(const std::string& db_name) const = 0; |
| 96 | +}; |
| 97 | + |
| 98 | +} // namespace paimon |
0 commit comments