Catalog#
Interface#
-
class Catalog#
This interface is responsible for reading and writing metadata such as database/table from a paimon catalog.
Public Functions
-
virtual Status CreateDatabase(const std::string &name, const std::map<std::string, std::string> &options, bool ignore_if_exists) = 0#
Creates a database with the specified properties.
- Parameters:
name – Name of the database to be created.
options – Additional properties associated with the database.
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.
- Returns:
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#
Creates a new table in the catalog.
Note
System tables cannot be created using this method.
- Parameters:
identifier – Identifier of the table to be created.
c_schema – The schema of the table to be created.
partition_keys – List of columns that should be used as partition keys for the table.
primary_keys – List of columns that should be used as primary keys for the table.
options – Additional table-specific options.
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.
- Returns:
A status indicating success or failure.
-
virtual Result<std::vector<std::string>> ListDatabases() const = 0#
Lists all the databases available in the catalog.
- Returns:
A result containing a vector of database names, or an error status.
-
virtual Result<std::vector<std::string>> ListTables(const std::string &db_name) const = 0#
Lists all the tables within a specified database.
Note
System tables will not be listed.
- Parameters:
db_name – The name of the database to list tables from.
- Returns:
A result containing a vector of table names in the specified database, or an error status.
-
virtual Status DropDatabase(const std::string &name, bool ignore_if_not_exists, bool cascade) = 0#
Drops a database.
- Parameters:
name – Name of the database to be dropped.
ignore_if_not_exists – If true, no action is taken if the database does not exist.
cascade – If true, drops all tables and functions in the database before dropping the database.
- Returns:
A status indicating success or failure.
-
virtual Status DropTable(const Identifier &identifier, bool ignore_if_not_exists) = 0#
Drops a table.
- Parameters:
identifier – Identifier of the table to drop.
ignore_if_not_exists – If true, no action is taken if the table does not exist.
- Returns:
A status indicating success or failure.
-
virtual Status RenameTable(const Identifier &from_table, const Identifier &to_table, bool ignore_if_not_exists) = 0#
Renames a table.
- Parameters:
from_table – Current identifier of the table.
to_table – New identifier for the table.
ignore_if_not_exists – If true, no action is taken if the table does not exist.
- Returns:
A status indicating success or failure.
-
virtual Result<std::shared_ptr<Table>> GetTable(const Identifier &identifier) const = 0#
Gets a table.
- Parameters:
identifier – Identifier of the table to get.
- Returns:
A result containing the table, or an error status.
-
virtual Result<bool> DatabaseExists(const std::string &db_name) const = 0#
Checks whether a database with the specified name exists in the catalog.
- Parameters:
db_name – The name of the database to check for existence.
- Returns:
A result containing true if the database exists, false otherwise, or an error status.
-
virtual Result<bool> TableExists(const Identifier &identifier) const = 0#
Checks whether a table with the specified identifier exists in the catalog.
- Parameters:
identifier – The identifier of the table to check for existence.
- Returns:
A result containing true if the table exists, false otherwise, or an error status.
-
virtual Result<std::string> GetDatabaseLocation(const std::string &db_name) const = 0#
Returns the expected location of a specified database.
- Parameters:
db_name – The name of the database to get the location for.
- Returns:
A result containing the expected location of the database, or an error status on failure. An implementation that builds the location from the warehouse path, such as the file system catalog, answers without checking whether the database exists. One that resolves the location on a server, such as the REST catalog, propagates the server’s error and so fails for a database that does not exist.
-
virtual Result<std::string> GetTableLocation(const Identifier &identifier) const = 0#
Returns the expected location of a specified table.
- Parameters:
identifier – The table identifier containing database and table name.
- Returns:
A result containing the expected location of the table, or an error status on failure. Whether a missing table is an error depends on the implementation, in the same way as for
GetDatabaseLocation.
-
virtual std::string GetRootPath() const = 0#
Returns the root path of the catalog.
- Returns:
A string representing the root path of the catalog.
-
virtual std::shared_ptr<FileSystem> GetFileSystem() const = 0#
Returns the file system used by the catalog.
- Returns:
A shared pointer to the file system instance.
-
inline virtual Result<std::shared_ptr<FileSystem>> GetTableFileSystem(const Identifier &identifier) const#
Returns the file system used to access the data of a specified table.
Note
A catalog that hands out per-table temporary credentials returns a file system that refreshes them, so the returned instance must be used for the table it was requested for. Pass it to
ReadContextBuilder::WithFileSystem,ScanContextBuilder::WithFileSystemorWriteContextBuilder::WithFileSystem, or let a builder request it for you throughReadContextBuilder::WithCatalog,ScanContextBuilder::WithCatalog,WriteContextBuilder::WithCatalogorCommitContextBuilder::WithCatalog.- Parameters:
identifier – The identifier (database and table name) of the table.
- Returns:
A shared pointer to the file system instance; the catalog-level file system by default.
-
virtual const std::map<std::string, std::string> &GetOptions() const = 0#
Returns the catalog-level options that were passed during catalog creation.
- Returns:
A const reference to the map of catalog options (key-value pairs).
-
virtual Result<std::shared_ptr<Schema>> LoadTableSchema(const Identifier &identifier) const = 0#
Loads the latest schema of a specified table.
Note
System tables will not be supported.
- Parameters:
identifier – The identifier (database and table name) of the table to load.
- Returns:
A result containing table schema if the table exists, or an error status on failure.
-
virtual Result<std::vector<SnapshotInfo>> ListSnapshots(const Identifier &identifier, const std::string &branch = "") const = 0#
Lists all snapshots of the specified table, ordered by snapshot id.
- Parameters:
identifier – The identifier (database and table name) of the table.
branch – Branch name; empty string means the main branch.
- Returns:
A result containing a vector of SnapshotInfo ordered by snapshot id ascending, or an error status.
-
virtual Result<std::optional<SnapshotInfo>> GetLatestSnapshot(const Identifier &identifier, const std::string &branch = "") const = 0#
Gets the latest snapshot of the specified table without loading its snapshot history.
- Parameters:
identifier – The identifier (database and table name) of the table.
branch – Branch name; empty string means the main branch.
- Returns:
A result containing the latest SnapshotInfo, nullopt if there are no snapshots, or an error status.
-
virtual bool SupportsVersionManagement() const#
Returns whether this catalog publishes snapshots through catalog commits.
Defaults to false.
Note
Implementations returning true must also implement the internal
VersionManagedCatalog.
-
Result<std::shared_ptr<FormatTable>> GetFormatTable(const Identifier &identifier) const#
Gets a format table: a directory of data files laid out like a standard Hive table.
A format table carries no snapshots and no manifests, so it is loaded through its own method rather than
GetTable(). Reading and writing it go through the sameTableScan,TableRead,FileStoreWriteandFileStoreCommitentry points every other table uses: hand the table back toScanContextBuilder,ReadContextBuilder,WriteContextBuilderorCommitContextBuilder, each of which takes one.- Parameters:
identifier – Identifier of the table to get.
- Returns:
A result containing the format table, or an error status if the table does not exist or its
typeoption is notformat-table.
Public Static Functions
Factory method for creating a
Cataloginstance.- Parameters:
root_path – Path to the root directory where the catalog is located. For the REST catalog (
CatalogOptions::METASTOREset to “rest”) this is instead the warehouse (instance) name registered on the server.options – Configuration options for catalog initialization.
file_system – Specifies the file system for file operations. If not set, use default file system (configured in
Options::FILE_SYSTEM)fs_scheme_to_identifier_map – Maps a URI scheme (like “oss”) to the registered file system identifier that serves it, so a catalog that resolves several schemes, including the file systems it builds from per-table data tokens, keeps routing each scheme to its backend. Ignored when
file_systemis supplied, which serves every scheme itself.
- Returns:
A result containing a unique pointer to a
Cataloginstance, or an error status.
-
virtual Status CreateDatabase(const std::string &name, const std::map<std::string, std::string> &options, bool ignore_if_exists) = 0#
-
class Identifier#
An identifier for a catalog object: a database name plus an object name, which may carry a branch or system-table suffix.
Public Functions
-
Identifier(const std::string &database, const std::string &object)#
-
Identifier(const std::string &database, const std::string &table, const std::string &branch)#
Names
branchoftable: every branch but the main one is addressed by the object name this builds, which joins them astbl$branch_dev.The branch is matched against the main branch ignoring case, as the Java client matches it, so
MAINnames the main branch here rather than a branch of its own. A branch of only whitespace names it too, which the Java client does not do: this library reads a blank branch as the main branch everywhere.- Parameters:
database – Database holding the table.
table – Data table name, carrying no branch or system table suffix.
branch – Branch of
table; any spelling ofmain, an empty and a blank name all name the main branch.
-
bool operator==(const Identifier &other) const#
-
const std::string &GetDatabaseName() const#
-
const std::string &GetObjectName() const#
The full object name, which keeps any branch and system-table suffix, like
tbl$branch_dev.Mirrors the Java
Identifier#getObjectName.
-
Result<std::string> GetDataTableName() const#
-
Result<std::optional<std::string>> GetBranchName() const#
-
Result<std::string> GetBranchNameOrDefault() const#
The branch the object name carries,
mainwhen it names none.Any spelling of the main branch, as
MAIN, folds tomainhere, as the branch constructor folds it, so a caller binding a manager to the returned value addresses the main branch’s own directory rather than one named after the alias.
-
Result<std::optional<std::string>> GetSystemTableName() const#
-
Result<bool> IsSystemTable() const#
-
std::string GetFullName() const#
-
std::string ToString() const#
-
int32_t HashCode() const#
Public Static Functions
-
static Result<Identifier> FromString(const std::string &full_name)#
-
Identifier(const std::string &database, const std::string &object)#
-
class Database#
Interface of a database in a catalog.
Public Functions
-
virtual std::string Name() const = 0#
================== Database Metadata =====================
A name to identify this database.
-
virtual const std::map<std::string, std::string> &Options() const = 0#
Get the database-level options associated with this database.
- Returns:
-
virtual std::optional<std::string> Comment() const = 0#
Get an optional comment describing the database.
- Returns:
The database comment if set, or std::nullopt otherwise.
-
virtual std::string Name() const = 0#
-
class Table#
A table provides basic abstraction for table type.
Public Functions
- Parameters:
file_system – File system the table’s data is accessed through.
root_path – Root path of the table in the file system.
uuid – Metastore UUID, or empty if unavailable.
-
inline std::shared_ptr<FileSystem> GetFileSystem() const#
Returns the file system the table was opened with, which serves the table’s files.
A catalog that hands out per-table file systems opens a table with the one for that table; it is null when the opener had none.
-
inline const std::string &GetRootPath() const#
Returns the root path of the table in its file system.
It is empty when the opener had no location for the table, which a mock in a test is one case of.
-
inline std::string Name() const#
A name to identify this table.
-
inline std::string FullName() const#
Full name of the table, default is database.tableName.
-
inline Result<std::string> CurrentBranch() const#
Returns the branch the table was opened for, which its identifier carries;
mainwhen it names none or a spelling of it, which its managers are bound to.A malformed object name that hides the branch is reported.
-
inline std::string Uuid() const#
Returns the metastore UUID, falling back to
FullName().Note
Use
CatalogUuid()for commit requests to avoid sending a table name as an ID.
-
inline std::optional<std::string> CatalogUuid() const#
Returns the metastore UUID, or null if unavailable, for
CommitContextBuilder::WithTableId().
-
inline std::shared_ptr<Schema> LatestSchema() const#
Loads the latest schema of table.
-
Result<std::unique_ptr<TableScan>> NewScan(std::unique_ptr<ScanContext> context) const#
Creates a scan of this table from a finished scan context, the table-first entry point that
TableScan::Create()also builds through.The scan is derived from the context.
- Parameters:
context – The finished scan context.
- Returns:
The scan, or the error building it reports.
-
Result<std::unique_ptr<TableRead>> NewRead(std::unique_ptr<ReadContext> context) const#
Creates a read of this table from a finished read context, the table-first entry point that
TableRead::Create()also builds through.The read is derived from the context.
- Parameters:
context – The finished read context.
- Returns:
The read, or the error building it reports.
-
Result<std::unique_ptr<FileStoreWrite>> NewWrite(std::unique_ptr<WriteContext> context) const#
Creates a write of this table from a finished write context, the table-first entry point that
FileStoreWrite::Create()also builds through.The write is derived from the context.
- Parameters:
context – The finished write context.
- Returns:
The write, or the error building it reports.
-
Result<std::unique_ptr<FileStoreCommit>> NewCommit(std::unique_ptr<CommitContext> context) const#
Creates a commit of this table from a finished commit context, the table-first entry point that
FileStoreCommit::Create()also builds through.The commit is derived from the context.
- Parameters:
context – The finished commit context.
- Returns:
The commit, or the error building it reports.
-
struct CatalogOptions#
Catalog-level configuration option keys; table-level keys live in
Options.Public Static Attributes
-
static const char METASTORE[]#
“metastore” - Metastore of the paimon catalog.
Supported values are “filesystem” (default) and “rest”.
-
static const char URI[]#
“uri” - Server url of the REST catalog. Only used when METASTORE is “rest”.
-
static const char TOKEN[]#
“token” - Token of the “bear” token provider of the REST catalog.
-
static const char TOKEN_PROVIDER[]#
“token.provider” - Authentication provider of the REST catalog.
Supported values are “bear” (the protocol’s historical spelling of “bearer”) and “dlf”.
-
static const char DLF_REGION[]#
“dlf.region” - Region used by DLF request signing. Inferred from URI when absent.
-
static const char DLF_TOKEN_PATH[]#
“dlf.token-path” - Path of a JSON file containing refreshable DLF credentials.
-
static const char DLF_ACCESS_KEY_ID[]#
“dlf.access-key-id” - DLF access key id.
-
static const char DLF_ACCESS_KEY_SECRET[]#
“dlf.access-key-secret” - DLF access key secret.
-
static const char DLF_SECURITY_TOKEN[]#
“dlf.security-token” - Optional STS security token used with a DLF access key.
-
static const char DLF_TOKEN_LOADER[]#
“dlf.token-loader” - Refreshable DLF token loader (“ecs” or “local_file”).
-
static const char DLF_TOKEN_ECS_METADATA_URL[]#
“dlf.token-ecs-metadata-url” - ECS RAM role metadata endpoint.
-
static const char DLF_TOKEN_ECS_ROLE_NAME[]#
“dlf.token-ecs-role-name” - Optional ECS RAM role name.
-
static const char DLF_SIGNING_ALGORITHM[]#
“dlf.signing-algorithm” - DLF signer (“default”, “openapi” or “openapi-v4”).
-
static const char DLF_OSS_ENDPOINT[]#
“dlf.oss-endpoint” - OSS endpoint that overrides the “fs.oss.endpoint” of a data token issued by the REST catalog.
-
static const char DATA_TOKEN_ENABLED[]#
“data-token.enabled” - Whether table data is accessed with the temporary credentials issued by the REST catalog instead of the credentials configured in the catalog options.
Defaults to false.
-
static const char TABLE_DEFAULT_OPTION_PREFIX[]#
“table-default.” - Prefix of the catalog options that provide table option defaults: “table-default.<key>=<value>” applies “<key>=<value>” to a created table when the caller left “<key>” unset.
-
static const char METASTORE[]#