@@ -210,6 +210,77 @@ TEST(FileSystemCatalogTest, TestOptionsSystemTableCatalog) {
210210 " Cannot rename system table" );
211211}
212212
213+ TEST (FileSystemCatalogTest, TestAuditLogAndBinlogSystemTableCatalog) {
214+ std::map<std::string, std::string> options;
215+ options[Options::FILE_SYSTEM] = " local" ;
216+ options[Options::FILE_FORMAT] = " orc" ;
217+ ASSERT_OK_AND_ASSIGN (auto core_options, CoreOptions::FromMap (options));
218+ auto dir = UniqueTestDirectory::Create ();
219+ ASSERT_TRUE (dir);
220+ FileSystemCatalog catalog (core_options.GetFileSystem (), dir->Str ());
221+ ASSERT_OK (catalog.CreateDatabase (" db1" , options, /* ignore_if_exists=*/ true ));
222+
223+ auto typed_schema =
224+ arrow::schema ({arrow::field (" pk" , arrow::utf8 ()), arrow::field (" v" , arrow::int32 (), true )});
225+ ::ArrowSchema schema;
226+ ASSERT_TRUE (arrow::ExportSchema (*typed_schema, &schema).ok ());
227+ ASSERT_OK (catalog.CreateTable (Identifier (" db1" , " tbl1" ), &schema,
228+ /* partition_keys=*/ {}, /* primary_keys=*/ {" pk" }, options,
229+ /* ignore_if_exists=*/ false ));
230+ ArrowSchemaRelease (&schema);
231+
232+ Identifier audit_log_identifier (" db1" , " tbl1$audit_log" );
233+ Identifier binlog_identifier (" db1" , " tbl1$binlog" );
234+ ASSERT_OK_AND_ASSIGN (bool exists, catalog.TableExists (audit_log_identifier));
235+ ASSERT_TRUE (exists);
236+ ASSERT_OK_AND_ASSIGN (exists, catalog.TableExists (binlog_identifier));
237+ ASSERT_TRUE (exists);
238+ ASSERT_OK_AND_ASSIGN (exists, catalog.TableExists (Identifier (" db1" , " tbl1$unknown" )));
239+ ASSERT_FALSE (exists);
240+
241+ ASSERT_OK_AND_ASSIGN (std::shared_ptr<Schema> audit_log_system_schema,
242+ catalog.LoadTableSchema (audit_log_identifier));
243+ ASSERT_TRUE (std::dynamic_pointer_cast<SystemTableSchema>(audit_log_system_schema) != nullptr );
244+ ASSERT_OK_AND_ASSIGN (auto audit_log_c_schema, audit_log_system_schema->GetArrowSchema ());
245+ auto audit_log_schema_result = arrow::ImportSchema (audit_log_c_schema.get ());
246+ ASSERT_TRUE (audit_log_schema_result.ok ()) << audit_log_schema_result.status ().ToString ();
247+ auto audit_log_schema = audit_log_schema_result.ValueUnsafe ();
248+ ASSERT_EQ (audit_log_schema->field_names (), (std::vector<std::string>{" rowkind" , " pk" , " v" }));
249+ ASSERT_EQ (audit_log_schema->field (0 )->type ()->id (), arrow::Type::STRING);
250+ ASSERT_EQ (audit_log_schema->field (1 )->type ()->id (), arrow::Type::STRING);
251+ ASSERT_EQ (audit_log_schema->field (2 )->type ()->id (), arrow::Type::INT32);
252+
253+ ASSERT_OK_AND_ASSIGN (std::shared_ptr<Schema> binlog_system_schema,
254+ catalog.LoadTableSchema (binlog_identifier));
255+ ASSERT_TRUE (std::dynamic_pointer_cast<SystemTableSchema>(binlog_system_schema) != nullptr );
256+ ASSERT_OK_AND_ASSIGN (auto binlog_c_schema, binlog_system_schema->GetArrowSchema ());
257+ auto binlog_schema_result = arrow::ImportSchema (binlog_c_schema.get ());
258+ ASSERT_TRUE (binlog_schema_result.ok ()) << binlog_schema_result.status ().ToString ();
259+ auto binlog_schema = binlog_schema_result.ValueUnsafe ();
260+ ASSERT_EQ (binlog_schema->field_names (), (std::vector<std::string>{" rowkind" , " pk" , " v" }));
261+ ASSERT_EQ (binlog_schema->field (0 )->type ()->id (), arrow::Type::STRING);
262+ ASSERT_EQ (binlog_schema->field (1 )->type ()->id (), arrow::Type::LIST);
263+ ASSERT_EQ (binlog_schema->field (2 )->type ()->id (), arrow::Type::LIST);
264+ auto binlog_pk_type =
265+ std::dynamic_pointer_cast<arrow::ListType>(binlog_schema->field (1 )->type ());
266+ auto binlog_v_type =
267+ std::dynamic_pointer_cast<arrow::ListType>(binlog_schema->field (2 )->type ());
268+ ASSERT_TRUE (binlog_pk_type);
269+ ASSERT_TRUE (binlog_v_type);
270+ ASSERT_EQ (binlog_pk_type->value_type ()->id (), arrow::Type::STRING);
271+ ASSERT_EQ (binlog_v_type->value_type ()->id (), arrow::Type::INT32);
272+
273+ ::ArrowSchema system_create_schema;
274+ ASSERT_TRUE (arrow::ExportSchema (*typed_schema, &system_create_schema).ok ());
275+ ASSERT_NOK_WITH_MSG (
276+ catalog.CreateTable (audit_log_identifier, &system_create_schema, {}, {}, options, false ),
277+ " Cannot create table for system table" );
278+ ArrowSchemaRelease (&system_create_schema);
279+ ASSERT_NOK_WITH_MSG (catalog.DropTable (binlog_identifier, false ), " Cannot drop system table" );
280+ ASSERT_NOK_WITH_MSG (catalog.RenameTable (audit_log_identifier, Identifier (" db1" , " tbl2" ), false ),
281+ " Cannot rename system table" );
282+ }
283+
213284TEST (FileSystemCatalogTest, TestCreateTableWithBlob) {
214285 std::map<std::string, std::string> options;
215286 options[Options::FILE_SYSTEM] = " local" ;
0 commit comments