MCPcopy Create free account
hub / github.com/apache/paimon-rust / main

Function main

crates/paimon/examples/rest_catalog_example.rs:80–296  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

78
79#[tokio::main]
80async fn main() {
81 // ==================== Configuration ====================
82 let mut options = Options::new();
83
84 // Basic configuration — replace with your actual server URL and warehouse
85 options.set(CatalogOptions::METASTORE, "rest");
86 options.set(CatalogOptions::WAREHOUSE, "paimon_catalog");
87 options.set(CatalogOptions::URI, "http://sample.net/");
88
89 // --- Authentication (choose one) ---
90
91 // DLF authentication (Alibaba Cloud)
92 options.set(CatalogOptions::TOKEN_PROVIDER, "dlf");
93 options.set("dlf.region", "cn-hangzhou");
94 options.set(
95 "dlf.access-key-id",
96 std::env::var("DLF_ACCESS_KEY_ID").expect("DLF_ACCESS_KEY_ID env var not set"),
97 );
98 options.set(
99 "dlf.access-key-secret",
100 std::env::var("DLF_ACCESS_KEY_SECRET").expect("DLF_ACCESS_KEY_SECRET env var not set"),
101 );
102
103 // ==================== Create RESTCatalog ====================
104 println!("Creating RESTCatalog instance...");
105 let catalog = match CatalogFactory::create(options).await {
106 Ok(catalog) => catalog,
107 Err(err) => {
108 eprintln!("Failed to create RESTCatalog: {err}");
109 return;
110 }
111 };
112
113 // ==================== Part 1: Database Operations ====================
114 println!("\n=== Part 1: Database Operations ===\n");
115
116 // List databases
117 println!("Listing databases...");
118 match catalog.list_databases().await {
119 Ok(databases) => {
120 println!("Databases found: {databases:?}");
121 println!("Total count: {}", databases.len());
122 }
123 Err(err) => {
124 eprintln!("Failed to list databases: {err}");
125 }
126 }
127
128 // Create database
129 println!("\nCreating database 'example_db'...");
130 match catalog
131 .create_database("example_db", false, HashMap::new())
132 .await
133 {
134 Ok(()) => println!("Database created successfully"),
135 Err(err) => eprintln!("Failed to create database: {err}"),
136 }
137

Callers

nothing calls this directly

Calls 15

create_test_schemaFunction · 0.85
array_value_to_stringFunction · 0.85
setMethod · 0.80
new_read_builderMethod · 0.80
new_scanMethod · 0.80
planMethod · 0.80
splitsMethod · 0.80
new_readMethod · 0.80
to_arrowMethod · 0.80
num_rowsMethod · 0.80
columnMethod · 0.80
list_databasesMethod · 0.45

Tested by

no test coverage detected