@@ -87,7 +87,7 @@ Status FileSystemCatalog::CreateDatabaseImpl(const std::string& db_name,
8787 fmt::join (options, " , " ));
8888 PAIMON_LOG_DEBUG (logger_, " %s" , log_msg.c_str ());
8989 }
90- std::string db_path = NewDatabasePath (warehouse_, db_name);
90+ PAIMON_ASSIGN_OR_RAISE ( std::string db_path, NewDatabasePath (warehouse_, db_name) );
9191 PAIMON_RETURN_NOT_OK (fs_->Mkdirs (db_path));
9292 return Status::OK ();
9393}
@@ -96,14 +96,18 @@ Result<bool> FileSystemCatalog::DatabaseExists(const std::string& db_name) const
9696 if (CatalogUtils::IsSystemDatabase (db_name)) {
9797 return true ;
9898 }
99- return fs_->Exists (NewDatabasePath (warehouse_, db_name));
99+ PAIMON_ASSIGN_OR_RAISE (std::string db_path, NewDatabasePath (warehouse_, db_name));
100+ return fs_->Exists (db_path);
100101}
101102
102103Result<bool > FileSystemCatalog::TableExists (const Identifier& identifier) const {
103104 // Handle sys database global tables
104105 if (CatalogUtils::IsSystemDatabase (identifier.GetDatabaseName ())) {
105106 return GlobalSystemTableLoader::IsSupported (identifier.GetTableName (), catalog_options_);
106107 }
108+ // The branch component is dropped when the data table identifier is rebuilt below, so the
109+ // identifier is validated as a whole here.
110+ PAIMON_RETURN_NOT_OK (CatalogUtils::CheckValidTableName (identifier));
107111 PAIMON_ASSIGN_OR_RAISE (bool is_system_table, identifier.IsSystemTable ());
108112 if (is_system_table) {
109113 PAIMON_ASSIGN_OR_RAISE (std::optional<std::string> system_table_name,
@@ -122,7 +126,7 @@ Result<bool> FileSystemCatalog::TableExists(const Identifier& identifier) const
122126 return latest_schema != std::nullopt ;
123127}
124128
125- std::string FileSystemCatalog::GetDatabaseLocation (const std::string& db_name) const {
129+ Result< std::string> FileSystemCatalog::GetDatabaseLocation (const std::string& db_name) const {
126130 return NewDatabasePath (warehouse_, db_name);
127131}
128132
@@ -204,16 +208,19 @@ Result<bool> FileSystemCatalog::IsSystemTable(const Identifier& identifier) {
204208 return IsSpecifiedSystemTable (identifier);
205209}
206210
207- std::string FileSystemCatalog::NewDatabasePath (const std::string& warehouse,
208- const std::string& db_name) {
211+ Result<std::string> FileSystemCatalog::NewDatabasePath (const std::string& warehouse,
212+ const std::string& db_name) {
213+ PAIMON_RETURN_NOT_OK (CatalogUtils::CheckValidDatabaseName (db_name));
209214 return PathUtil::JoinPath (warehouse, db_name + DB_SUFFIX );
210215}
211216
212217Result<std::string> FileSystemCatalog::NewDataTablePath (const std::string& warehouse,
213218 const Identifier& identifier) {
219+ PAIMON_RETURN_NOT_OK (CatalogUtils::CheckValidTableName (identifier));
214220 PAIMON_ASSIGN_OR_RAISE (std::string data_table_name, identifier.GetDataTableName ());
215- return PathUtil::JoinPath (NewDatabasePath (warehouse, identifier.GetDatabaseName ()),
216- data_table_name);
221+ PAIMON_ASSIGN_OR_RAISE (std::string database_path,
222+ NewDatabasePath (warehouse, identifier.GetDatabaseName ()));
223+ return PathUtil::JoinPath (database_path, data_table_name);
217224}
218225
219226Result<std::vector<std::string>> FileSystemCatalog::ListDatabases () const {
@@ -235,7 +242,7 @@ Result<std::vector<std::string>> FileSystemCatalog::ListTables(const std::string
235242 if (CatalogUtils::IsSystemDatabase (db_name)) {
236243 return GlobalSystemTableLoader::GetSupportedTableNames (catalog_options_);
237244 }
238- std::string database_path = NewDatabasePath (warehouse_, db_name);
245+ PAIMON_ASSIGN_OR_RAISE ( std::string database_path, NewDatabasePath (warehouse_, db_name) );
239246 std::vector<BasicFileStatus> file_status_list;
240247 PAIMON_RETURN_NOT_OK (fs_->ListDir (database_path, &file_status_list));
241248 std::vector<std::string> table_names;
@@ -284,6 +291,9 @@ Result<std::shared_ptr<Schema>> FileSystemCatalog::LoadTableSchema(
284291 system_table->ArrowSchema ());
285292 return std::make_shared<SystemTableSchema>(std::move (arrow_schema));
286293 }
294+ // The branch component is dropped when the data table identifier is rebuilt below, so the
295+ // identifier is validated as a whole here.
296+ PAIMON_RETURN_NOT_OK (CatalogUtils::CheckValidTableName (identifier));
287297 PAIMON_ASSIGN_OR_RAISE (bool is_system_table, identifier.IsSystemTable ());
288298 if (is_system_table) {
289299 PAIMON_ASSIGN_OR_RAISE (std::optional<std::string> system_table_name,
@@ -342,7 +352,7 @@ Status FileSystemCatalog::DropDatabase(const std::string& name, bool ignore_if_n
342352 }
343353 }
344354
345- std::string db_path = NewDatabasePath (warehouse_, name);
355+ PAIMON_ASSIGN_OR_RAISE ( std::string db_path, NewDatabasePath (warehouse_, name) );
346356
347357 if (cascade) {
348358 // List all tables in the database and drop them
@@ -511,6 +521,7 @@ Status FileSystemCatalog::RenameTable(const Identifier& from_table, const Identi
511521
512522Result<std::vector<SnapshotInfo>> FileSystemCatalog::ListSnapshots (
513523 const Identifier& identifier, const std::string& branch) const {
524+ PAIMON_RETURN_NOT_OK (BranchManager::CheckValidBranch (branch));
514525 PAIMON_ASSIGN_OR_RAISE (bool exists, TableExists (identifier));
515526 if (!exists) {
516527 return Status::NotExist (fmt::format (" table {} does not exist" , identifier.ToString ()));
0 commit comments