Last active
April 2, 2023 04:05
-
-
Save ylashin/d431db70c0218a5409d5a3cf23614f1e to your computer and use it in GitHub Desktop.
This file contains 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
use deltalake::operations::create::CreateBuilder; | |
use deltalake::{DeltaTable, SchemaDataType}; | |
use std::collections::HashMap; | |
async fn create_table(path: String, backend_config: HashMap<String, String>) -> DeltaTable { | |
let builder = CreateBuilder::new() | |
.with_location(path) | |
.with_storage_options(backend_config) | |
.with_column( | |
"id", | |
SchemaDataType::primitive(String::from("integer")), | |
false, | |
Default::default(), | |
) | |
.with_column( | |
"name", | |
SchemaDataType::primitive(String::from("string")), | |
false, | |
Default::default(), | |
); | |
builder.await.unwrap() | |
} | |
#[tokio::main(flavor = "current_thread")] | |
async fn main() { | |
let s3_storage_location = "s3://delta-root/table1".to_string(); | |
let region = std::env::var("AWS_REGION").unwrap(); | |
let access_key = std::env::var("AWS_ACCESS_KEY_ID").unwrap(); | |
let secret_access_secret = std::env::var("AWS_SECRET_ACCESS_KEY").unwrap(); | |
let mut backend_config: HashMap<String, String> = HashMap::new(); | |
backend_config.insert("AWS_REGION".to_string(), region); | |
backend_config.insert("AWS_ACCESS_KEY_ID".to_string(), access_key); | |
backend_config.insert("AWS_SECRET_ACCESS_KEY".to_string(), secret_access_secret); | |
println!("Creating table"); | |
let table = create_table( | |
s3_storage_location, backend_config | |
).await; | |
println!("Table created with version : {}", table.version()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment