()
| 78 | |
| 79 | #[tokio::main] |
| 80 | async 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 |
nothing calls this directly
no test coverage detected