@@ -180,6 +180,12 @@ TEST(FileSystemCatalogTest, TestCreateTableWithBlob) {
180180 ASSERT_OK_AND_ASSIGN (std::vector<std::string> table_names, catalog.ListTables (" db1" ));
181181 ASSERT_EQ (1 , table_names.size ());
182182 ASSERT_EQ (table_names[0 ], " tbl1" );
183+ ASSERT_OK_AND_ASSIGN (std::optional<std::shared_ptr<Schema>> table_schema,
184+ catalog.LoadTableSchema (Identifier (" db1" , " tbl1" )));
185+ ASSERT_TRUE (table_schema.has_value ());
186+ ASSERT_OK_AND_ASSIGN (auto arrow_schema, (*table_schema)->GetArrowSchema ());
187+ auto loaded_schema = arrow::ImportSchema (arrow_schema.get ()).ValueOrDie ();
188+ ASSERT_TRUE (typed_schema.Equals (loaded_schema));
183189 ArrowSchemaRelease (&schema);
184190}
185191
@@ -309,4 +315,54 @@ TEST(FileSystemCatalogTest, TestInvalidList) {
309315 " do not support listing tables for system database." );
310316}
311317
318+ TEST (FileSystemCatalogTest, TestValidateTableSchema) {
319+ std::map<std::string, std::string> options;
320+ options[Options::FILE_SYSTEM] = " local" ;
321+ options[Options::FILE_FORMAT] = " orc" ;
322+ ASSERT_OK_AND_ASSIGN (auto core_options, CoreOptions::FromMap (options));
323+ auto dir = UniqueTestDirectory::Create ();
324+ ASSERT_TRUE (dir);
325+ FileSystemCatalog catalog (core_options.GetFileSystem (), dir->Str ());
326+ ASSERT_OK (catalog.CreateDatabase (" db1" , options, /* ignore_if_exists=*/ true ));
327+ arrow::FieldVector fields = {
328+ arrow::field (" f0" , arrow::utf8 ()),
329+ arrow::field (" f1" , arrow::int32 ()),
330+ arrow::field (" f2" , arrow::int32 ()),
331+ arrow::field (" f3" , arrow::float64 ()),
332+ };
333+ arrow::Schema typed_schema (fields);
334+ ::ArrowSchema schema;
335+ ASSERT_TRUE (arrow::ExportSchema (typed_schema, &schema).ok ());
336+ ASSERT_OK (catalog.CreateTable (Identifier (" db1" , " tbl1" ), &schema, {" f1" }, {}, options,
337+ /* ignore_if_exists=*/ false ));
338+
339+ ASSERT_OK_AND_ASSIGN (std::optional<std::shared_ptr<Schema>> table_schema,
340+ catalog.LoadTableSchema (Identifier (" db0" , " tbl0" )));
341+ ASSERT_FALSE (table_schema.has_value ());
342+ ASSERT_OK_AND_ASSIGN (table_schema, catalog.LoadTableSchema (Identifier (" db1" , " tbl1" )));
343+ ASSERT_TRUE (table_schema.has_value ());
344+ ASSERT_EQ (0 , (*table_schema)->Id ());
345+ ASSERT_EQ (3 , (*table_schema)->HighestFieldId ());
346+ ASSERT_EQ (1 , (*table_schema)->PartitionKeys ().size ());
347+ ASSERT_EQ (0 , (*table_schema)->PrimaryKeys ().size ());
348+ ASSERT_EQ (-1 , (*table_schema)->NumBuckets ());
349+ ASSERT_FALSE ((*table_schema)->Comment ().has_value ());
350+ std::vector<std::string> field_names = (*table_schema)->FieldNames ();
351+ std::vector<std::string> expected_field_names = {" f0" , " f1" , " f2" , " f3" };
352+ ASSERT_EQ (field_names, expected_field_names);
353+
354+ ASSERT_OK_AND_ASSIGN (auto arrow_schema, (*table_schema)->GetArrowSchema ());
355+ auto loaded_schema = arrow::ImportSchema (arrow_schema.get ()).ValueOrDie ();
356+ ASSERT_TRUE (typed_schema.Equals (loaded_schema));
357+
358+ ASSERT_OK_AND_ASSIGN (auto fs, FileSystemFactory::Get (" local" , dir->Str (), {}));
359+ ASSERT_OK (fs->Delete (PathUtil::JoinPath (dir->Str (), " db1.db/tbl1/schema/schema-0" )));
360+ ASSERT_OK_AND_ASSIGN (table_schema, catalog.LoadTableSchema (Identifier (" db1" , " tbl1" )));
361+ ASSERT_FALSE (table_schema.has_value ());
362+
363+ ASSERT_NOK_WITH_MSG (catalog.LoadTableSchema (Identifier (" db1" , " tbl$11" )),
364+ " do not support loading schema for system table." );
365+ ArrowSchemaRelease (&schema);
366+ }
367+
312368} // namespace paimon::test
0 commit comments