3333
3434namespace paimon {
3535
36+ class TableScan ;
37+ class TableRead ;
38+
3639// / A table provides basic abstraction for table type.
3740class PAIMON_EXPORT Table {
3841 public:
39- // / Creates a table by loading the latest schema from the specified table path.
40- // /
41- // / @param file_system File system used to access the table directory and schema files.
42- // / @param table_path Root path of the table in the file system.
43- // / @param identifier Logical table identifier selecting the schema branch and table name.
44- // / @return A table initialized with the latest available schema.
45- static Result<std::shared_ptr<Table>> Create (const std::shared_ptr<FileSystem>& file_system,
46- const std::string& table_path,
47- const Identifier& identifier);
48-
42+ // / @param file_system File system the table's data is accessed through.
43+ // / @param root_path Root path of the table in the file system.
4944 // / @param uuid Metastore UUID, or empty if unavailable.
50- Table (const std::shared_ptr<Schema >& schema , const std::string& database ,
51- const std::string& table_name , const std::string& uuid = " " )
52- : schema_(schema), database_(database), table_name_(table_name), uuid_( uuid) {}
45+ Table (const std::shared_ptr<FileSystem >& file_system , const std::string& root_path ,
46+ const std::shared_ptr<Schema>& schema , const Identifier& identifier,
47+ const std::string& uuid = " " );
5348
5449 ~Table () = default ;
5550
51+ // / Returns the file system the table was opened with, which serves the table's
52+ // / files. A catalog that hands out per-table file systems opens a table with the
53+ // / one for that table; it is null when the opener had none.
54+ std::shared_ptr<FileSystem> GetFileSystem () const {
55+ return file_system_;
56+ }
57+
58+ // / Returns the root path of the table in its file system. It is empty when the
59+ // / opener had no location for the table, which a mock in a test is one case of.
60+ const std::string& GetRootPath () const {
61+ return root_path_;
62+ }
63+
5664 // / A name to identify this table.
5765 std::string Name () const {
58- return table_name_ ;
66+ return identifier_. GetObjectName () ;
5967 }
6068
6169 // / Full name of the table, default is database.tableName.
62- std::string FullName () const ;
70+ std::string FullName () const {
71+ return identifier_.GetFullName ();
72+ }
73+
74+ // / Returns the branch the table was opened for, which its identifier carries; `main`
75+ // / when it names none or a spelling of it, which its managers are bound to. A
76+ // / malformed object name that hides the branch is reported.
77+ Result<std::string> CurrentBranch () const {
78+ return identifier_.GetBranchNameOrDefault ();
79+ }
6380
6481 // / Returns the metastore UUID, falling back to `FullName()`.
6582 // / @note Use `CatalogUuid()` for commit requests to avoid sending a table name as an ID.
@@ -78,10 +95,37 @@ class PAIMON_EXPORT Table {
7895 return schema_;
7996 }
8097
98+ // / Creates a scan of this table from a finished scan context, the table-first entry point
99+ // / that `TableScan::Create()` also builds through. The scan is derived from the context.
100+ // / @param context The finished scan context.
101+ // / @return The scan, or the error building it reports.
102+ Result<std::unique_ptr<TableScan>> NewScan (std::unique_ptr<ScanContext> context) const ;
103+
104+ // / Creates a read of this table from a finished read context, the table-first entry point
105+ // / that `TableRead::Create()` also builds through. The read is derived from the context.
106+ // / @param context The finished read context.
107+ // / @return The read, or the error building it reports.
108+ Result<std::unique_ptr<TableRead>> NewRead (std::unique_ptr<ReadContext> context) const ;
109+
110+ // / Creates a write of this table from a finished write context, the table-first entry point
111+ // / that `FileStoreWrite::Create()` also builds through. The write is derived from the context.
112+ // / @param context The finished write context.
113+ // / @return The write, or the error building it reports.
114+ Result<std::unique_ptr<FileStoreWrite>> NewWrite (std::unique_ptr<WriteContext> context) const ;
115+
116+ // / Creates a commit of this table from a finished commit context, the table-first entry point
117+ // / that `FileStoreCommit::Create()` also builds through. The commit is derived from the
118+ // / context.
119+ // / @param context The finished commit context.
120+ // / @return The commit, or the error building it reports.
121+ Result<std::unique_ptr<FileStoreCommit>> NewCommit (
122+ std::unique_ptr<CommitContext> context) const ;
123+
81124 private:
125+ std::shared_ptr<FileSystem> file_system_;
126+ std::string root_path_;
82127 std::shared_ptr<Schema> schema_;
83- std::string database_;
84- std::string table_name_;
128+ Identifier identifier_;
85129 std::string uuid_;
86130};
87131
0 commit comments