SteNicholas commented on code in PR #447:
URL: https://github.com/apache/paimon-cpp/pull/447#discussion_r4385183689


##########
src/paimon/core/table/system/system_table.cpp:
##########
@@ -176,6 +182,40 @@ std::optional<SystemTableFactory> 
FindSystemTableFactory(const std::string& syst
 
 }  // namespace
 
+SystemTable::SystemTable(const std::shared_ptr<FileSystem>& fs, const 
std::string& table_path)
+    : Table(fs, table_path, /*schema=*/nullptr,
+            Identifier(Identifier::kUnknownDatabase, "system_table"), 
/*uuid=*/"") {}
+
+Status SystemTable::CheckNoSearch(const std::shared_ptr<ReadContext>& context) 
{
+    if (context->HasVectorOrFullTextSearch()) {
+        return Status::NotImplemented(
+            "VectorSearch or FullTextSearch does not support system-table 
reads yet");
+    }
+    return Status::OK();

Review Comment:
   [P2] Reject FullTextMatch on direct system-table reads
   
   `HasVectorOrFullTextSearch()` only checks TopK requests; it does not detect 
`FullTextMatch` predicates supplied through 
`ReadContextBuilder::SetPredicate()`. Calling `NewRead()` on an in-memory 
system table (for example, `t$options`) therefore passes this guard and returns 
all rows without evaluating the predicate. The static `TableRead::Create()` 
path rejects the same request with `NotImplemented`.
   
   Please also check 
`PredicateUtils::ContainsFullTextMatch(context->GetPredicate())` here and add a 
regression test through the direct `Table::NewRead()` entry point.



##########
src/paimon/rest/rest_catalog.cpp:
##########
@@ -388,78 +390,113 @@ Result<std::shared_ptr<Schema>> 
RestCatalog::LoadTableSchema(const Identifier& i
         context.catalog_options = api_->GetMergedOptions();
         PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<SystemTable> system_table,
                                
GlobalSystemTableLoader::Load(identifier.GetObjectName(), context));
-        PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<arrow::Schema> arrow_schema,
-                               system_table->ArrowSchema());
-        return std::make_shared<SystemTableSchema>(std::move(arrow_schema));
+        return system_table->LatestSchema();
     }
     PAIMON_ASSIGN_OR_RAISE(bool is_system_table, identifier.IsSystemTable());
     PAIMON_ASSIGN_OR_RAISE(std::optional<std::string> branch, 
identifier.GetBranchName());
     branch = NormalizeBranch(std::move(branch));
     PAIMON_ASSIGN_OR_RAISE(Identifier load_identifier, 
ToLoadIdentifier(identifier));
     if (is_system_table) {
-        PAIMON_ASSIGN_OR_RAISE(std::optional<std::string> system_table_name,
-                               identifier.GetSystemTableName());
-        if (!system_table_name || 
!SystemTableLoader::IsSupported(system_table_name.value())) {
-            return Status::NotExist(fmt::format("{} not exist", 
identifier.ToString()));
-        }
-        std::string data_table_path;
-        PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<TableSchema> latest_schema,
-                               LoadDataTableSchema(load_identifier, branch, 
&data_table_path,
-                                                   /*table_id=*/nullptr));
+        PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<SystemTable> system_table,
+                               LoadSystemTable(identifier, load_identifier, 
branch));
         if (table_path != nullptr) {
-            *table_path = data_table_path;
-        }
-        std::map<std::string, std::string> dynamic_options;
-        if (branch) {
-            dynamic_options[Options::BRANCH] = branch.value();
+            *table_path = system_table->GetRootPath();
         }
-        // The file system is only used to build the system table, whose 
schema does not
-        // read any file, so the catalog wide one is enough here. The 
credentials of the
-        // table are applied when its rows are read, through the file system 
of the read or
-        // scan context.
-        PAIMON_ASSIGN_OR_RAISE(
-            std::shared_ptr<SystemTable> system_table,
-            SystemTableLoader::Load(system_table_name.value(), fs_, 
data_table_path, latest_schema,
-                                    dynamic_options));
-        PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<arrow::Schema> arrow_schema,
-                               system_table->ArrowSchema());
-        return std::make_shared<SystemTableSchema>(std::move(arrow_schema));
+        return system_table->LatestSchema();
     }
     PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<TableSchema> schema,
                            LoadDataTableSchema(load_identifier, branch, 
table_path, table_id));
     return checked_pointer_cast<Schema>(schema);
 }
 
-Result<std::shared_ptr<FormatTable>> RestCatalog::LoadFormatTable(
-    const Identifier& identifier) const {
-    // A system table is already refused by `Catalog::GetFormatTable()`, which 
every caller goes
-    // through, so this only has to load.
-    PAIMON_ASSIGN_OR_RAISE(std::optional<std::string> branch, 
identifier.GetBranchName());
-    branch = NormalizeBranch(std::move(branch));
-    PAIMON_ASSIGN_OR_RAISE(Identifier load_identifier, 
ToLoadIdentifier(identifier));
-    std::string location;
-    PAIMON_ASSIGN_OR_RAISE(
-        std::shared_ptr<TableSchema> schema,
-        LoadDataTableSchema(load_identifier, branch, &location, 
/*table_id=*/nullptr));
-    // A rest catalog holds the schema itself, so everything below the 
location is data.
-    return FormatTable::Create(fs_, location, identifier, 
checked_pointer_cast<DataSchema>(schema),
-                               /*location_carries_paimon_metadata=*/false,
-                               /*dynamic_options=*/{});
+Result<std::shared_ptr<SystemTable>> RestCatalog::LoadSystemTable(
+    const Identifier& identifier, const Identifier& load_identifier,
+    const std::optional<std::string>& branch) const {
+    PAIMON_ASSIGN_OR_RAISE(std::optional<std::string> system_table_name,
+                           identifier.GetSystemTableName());
+    if (!system_table_name || 
!SystemTableLoader::IsSupported(system_table_name.value())) {
+        return Status::NotExist(fmt::format("{} not exist", 
identifier.ToString()));
+    }
+    std::string data_table_path;
+    PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<TableSchema> latest_schema,
+                           LoadDataTableSchema(load_identifier, branch, 
&data_table_path,
+                                               /*table_id=*/nullptr));
+    std::map<std::string, std::string> dynamic_options;
+    if (branch) {
+        dynamic_options[Options::BRANCH] = branch.value();
+    }
+    // The system table reads the data table's own files, so it is served by 
that table's own
+    // credentials - with data tokens the only file system that can open them.
+    PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<FileSystem> table_file_system,
+                           GetTableFileSystem(identifier));
+    return SystemTableLoader::Load(system_table_name.value(), 
table_file_system, data_table_path,
+                                   latest_schema, dynamic_options);
 }
 
 Result<std::shared_ptr<Table>> RestCatalog::GetTable(const Identifier& 
identifier) const {
+    // The global system tables of the "sys" database expose the catalog 
itself rather than any
+    // table the server stands behind, so they are served locally and never 
reach the managed-table
+    // load below, whose schema cast a read-only system table schema would not 
survive.
+    if (CatalogUtils::IsSystemDatabase(identifier.GetDatabaseName())) {
+        PAIMON_ASSIGN_OR_RAISE(bool supported,
+                               
GlobalSystemTableLoader::IsSupported(identifier.GetObjectName(),
+                                                                    
api_->GetMergedOptions()));
+        if (!supported) {
+            return Status::NotExist(fmt::format("{} not exist", 
identifier.ToString()));
+        }
+        GlobalSystemTableContext context;
+        context.catalog = this;
+        // A global system table builds its rows lazily through the catalog 
above, so the table
+        // handed back has to keep it alive or the pointer dangles at the 
first `BuildRows`. A
+        // catalog not owned by a `std::shared_ptr` cannot be kept, so it is 
refused by name.
+        std::shared_ptr<const RestCatalog> self = weak_from_this().lock();
+        if (self == nullptr) {

Review Comment:
   Confirmed this still occurs at `13fba3780476ce4177d2197e0d7f62816bdd3047`. A 
standalone C++17 reproduction of the same inheritance and ownership conversion 
leaves `weak_from_this()` empty after promoting `unique_ptr<Catalog>` to 
`shared_ptr<Catalog>`, while promoting `unique_ptr<RestCatalog>` initializes 
it. The current test exercises only the latter, so the public 
`Catalog::Create()` path still cannot load global system tables. Please cover 
that public factory path in the retention fix.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to