-
Notifications
You must be signed in to change notification settings - Fork 44
feat: introduce database level ops for cpp bindings #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include <iostream> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| #include "fluss.hpp" | ||
|
|
||
| static void check(const char* step, const fluss::Result& r) { | ||
| if (!r.Ok()) { | ||
| std::cerr << step << " failed: code=" << r.error_code << " msg=" << r.error_message | ||
| << std::endl; | ||
| std::exit(1); | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| const std::string bootstrap = "127.0.0.1:9123"; | ||
| const std::string db_name = "admin_example_db"; | ||
| const std::string table_name = "admin_example_table"; | ||
|
|
||
| // 1) Connect and get Admin | ||
| fluss::Connection conn; | ||
| check("connect", fluss::Connection::Connect(bootstrap, conn)); | ||
|
|
||
| fluss::Admin admin; | ||
| check("get_admin", conn.GetAdmin(admin)); | ||
|
|
||
| // 2) Database operations | ||
| std::cout << "--- Database operations ---" << std::endl; | ||
|
|
||
| bool exists = false; | ||
| check("database_exists (before create)", admin.DatabaseExists(db_name, exists)); | ||
| std::cout << "Database " << db_name << " exists before create: " << (exists ? "yes" : "no") | ||
| << std::endl; | ||
|
|
||
| fluss::DatabaseDescriptor db_desc; | ||
| db_desc.comment = "Example database for Admin API"; | ||
| db_desc.properties["owner"] = "admin_example"; | ||
| check("create_database", admin.CreateDatabase(db_name, db_desc, true)); | ||
|
|
||
| check("database_exists (after create)", admin.DatabaseExists(db_name, exists)); | ||
| std::cout << "Database " << db_name << " exists after create: " << (exists ? "yes" : "no") | ||
| << std::endl; | ||
|
|
||
| fluss::DatabaseInfo db_info; | ||
| check("get_database_info", admin.GetDatabaseInfo(db_name, db_info)); | ||
| std::cout << "Database info: name=" << db_info.database_name | ||
| << " comment=" << db_info.comment << " created_time=" << db_info.created_time | ||
| << std::endl; | ||
|
|
||
| std::vector<std::string> databases; | ||
| check("list_databases", admin.ListDatabases(databases)); | ||
| std::cout << "List databases (" << databases.size() << "): "; | ||
| for (size_t i = 0; i < databases.size(); ++i) { | ||
| if (i > 0) std::cout << ", "; | ||
| std::cout << databases[i]; | ||
| } | ||
| std::cout << std::endl; | ||
|
|
||
| // 3) Table operations in the new database | ||
| std::cout << "--- Table operations ---" << std::endl; | ||
|
|
||
| fluss::TablePath table_path(db_name, table_name); | ||
|
|
||
| bool table_exists_flag = false; | ||
| check("table_exists (before create)", admin.TableExists(table_path, table_exists_flag)); | ||
| std::cout << "Table " << db_name << "." << table_name | ||
| << " exists before create: " << (table_exists_flag ? "yes" : "no") << std::endl; | ||
|
|
||
| auto schema = fluss::Schema::NewBuilder() | ||
| .AddColumn("id", fluss::DataType::Int()) | ||
| .AddColumn("name", fluss::DataType::String()) | ||
| .Build(); | ||
| auto descriptor = fluss::TableDescriptor::NewBuilder() | ||
| .SetSchema(schema) | ||
| .SetBucketCount(1) | ||
| .SetComment("admin example table") | ||
| .Build(); | ||
|
|
||
| check("create_table", admin.CreateTable(table_path, descriptor, true)); | ||
|
|
||
| check("table_exists (after create)", admin.TableExists(table_path, table_exists_flag)); | ||
| std::cout << "Table exists after create: " << (table_exists_flag ? "yes" : "no") << std::endl; | ||
|
|
||
| std::vector<std::string> tables; | ||
| check("list_tables", admin.ListTables(db_name, tables)); | ||
| std::cout << "List tables in " << db_name << " (" << tables.size() << "): "; | ||
| for (size_t i = 0; i < tables.size(); ++i) { | ||
| if (i > 0) std::cout << ", "; | ||
| std::cout << tables[i]; | ||
| } | ||
| std::cout << std::endl; | ||
|
|
||
| // 4) Cleanup: drop table, then drop database | ||
| std::cout << "--- Cleanup ---" << std::endl; | ||
| check("drop_table", admin.DropTable(table_path, true)); | ||
| check("drop_database", admin.DropDatabase(db_name, true, true)); | ||
|
|
||
| check("database_exists (after drop)", admin.DatabaseExists(db_name, exists)); | ||
| std::cout << "Database exists after drop: " << (exists ? "yes" : "no") << std::endl; | ||
|
|
||
| std::cout << "Admin example completed successfully." << std::endl; | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.