@@ -1255,6 +1255,64 @@ TEST(FileSystemCatalogTest, TestListSnapshots) {
12551255 ASSERT_LT (snapshots[0 ].snapshot_id , snapshots[1 ].snapshot_id );
12561256}
12571257
1258+ TEST (FileSystemCatalogTest, TestGetLatestSnapshot) {
1259+ std::map<std::string, std::string> options;
1260+ options[Options::FILE_SYSTEM ] = " local" ;
1261+ options[Options::FILE_FORMAT ] = " orc" ;
1262+ ASSERT_OK_AND_ASSIGN (auto core_options, CoreOptions::FromMap (options));
1263+ auto dir = UniqueTestDirectory::Create ();
1264+ ASSERT_TRUE (dir);
1265+
1266+ std::string test_data_path = GetDataDir () + " /append_table_with_multiple_file_format.db" ;
1267+ std::string db_path = dir->Str () + " /append_table_with_multiple_file_format.db" ;
1268+ ASSERT_TRUE (TestUtil::CopyDirectory (test_data_path, db_path));
1269+
1270+ FileSystemCatalog catalog (core_options.GetFileSystem (), dir->Str (), options);
1271+ const Catalog& public_catalog = catalog;
1272+ Identifier identifier (" append_table_with_multiple_file_format" ,
1273+ " append_table_with_multiple_file_format" );
1274+ ASSERT_OK_AND_ASSIGN (std::optional<SnapshotInfo> snapshot,
1275+ public_catalog.GetLatestSnapshot (identifier));
1276+ ASSERT_TRUE (snapshot);
1277+ ASSERT_EQ (snapshot->snapshot_id , 2 );
1278+ ASSERT_EQ (snapshot->schema_id , 1 );
1279+ }
1280+
1281+ TEST (FileSystemCatalogTest, TestGetLatestSnapshotEmptyMissingAndBranch) {
1282+ std::map<std::string, std::string> options;
1283+ options[Options::FILE_SYSTEM ] = " local" ;
1284+ options[Options::FILE_FORMAT ] = " orc" ;
1285+ ASSERT_OK_AND_ASSIGN (auto core_options, CoreOptions::FromMap (options));
1286+ auto dir = UniqueTestDirectory::Create ();
1287+ ASSERT_TRUE (dir);
1288+
1289+ std::string empty_test_data_path = GetDataDir () + " /orc/append_table_with_nested_type.db" ;
1290+ std::string empty_db_path = dir->Str () + " /append_table_with_nested_type.db" ;
1291+ ASSERT_TRUE (TestUtil::CopyDirectory (empty_test_data_path, empty_db_path));
1292+ std::string branch_test_data_path = GetDataDir () + " /orc/append_table_with_rt_branch.db" ;
1293+ std::string branch_db_path = dir->Str () + " /append_table_with_rt_branch.db" ;
1294+ ASSERT_TRUE (TestUtil::CopyDirectory (branch_test_data_path, branch_db_path));
1295+
1296+ FileSystemCatalog catalog (core_options.GetFileSystem (), dir->Str (), options);
1297+ ASSERT_OK_AND_ASSIGN (
1298+ std::optional<SnapshotInfo> empty,
1299+ catalog.GetLatestSnapshot (
1300+ Identifier (" append_table_with_nested_type" , " append_table_with_nested_type" ), " " ));
1301+ ASSERT_FALSE (empty);
1302+ Identifier identifier (" append_table_with_rt_branch" , " append_table_with_rt_branch" );
1303+ ASSERT_OK_AND_ASSIGN (std::optional<SnapshotInfo> branch_snapshot,
1304+ catalog.GetLatestSnapshot (identifier, " rt" ));
1305+ ASSERT_TRUE (branch_snapshot);
1306+ ASSERT_EQ (branch_snapshot->snapshot_id , 1 );
1307+ ASSERT_EQ (branch_snapshot->total_record_count , 4 );
1308+
1309+ ASSERT_TRUE (catalog.GetLatestSnapshot (Identifier (identifier.GetDatabaseName (), " missing" ), " " )
1310+ .status ()
1311+ .IsNotExist ());
1312+ ASSERT_OK_AND_ASSIGN (empty, catalog.GetLatestSnapshot (identifier, " missing" ));
1313+ ASSERT_FALSE (empty);
1314+ }
1315+
12581316namespace {
12591317class ClaimsVersionManagementCatalog : public FileSystemCatalog {
12601318 public:
0 commit comments