|
| 1 | +# delta-rs |
| 2 | + |
| 3 | +This guide provides an introduction to using the Delta Lake Rust library (delta-rs). |
| 4 | + |
| 5 | +## Install dependencies |
| 6 | + |
| 7 | +```toml |
| 8 | +[dependencies] |
| 9 | +deltalake = { version = "0.22.3", features = ["s3"] } |
| 10 | +tokio = "1.42.0" |
| 11 | +``` |
| 12 | + |
| 13 | +## Create table |
| 14 | + |
| 15 | +```rust |
| 16 | +use deltalake::kernel::DataType; |
| 17 | +use deltalake::operations::create::CreateBuilder; |
| 18 | +use std::collections::HashMap; |
| 19 | + |
| 20 | +#[tokio::main()] |
| 21 | +async fn main() { |
| 22 | + // Register AWS S3 handlers for Delta Lake operations. |
| 23 | + deltalake::aws::register_handlers(None); |
| 24 | + |
| 25 | + // Configure S3 storage parameters |
| 26 | + let mut storage_options = HashMap::new(); |
| 27 | + storage_options.insert("AWS_ENDPOINT_URL".to_string(), "http://localhost:5561".to_string()); |
| 28 | + storage_options.insert("AWS_REGION".to_string(), "us-east-1".to_string()); |
| 29 | + storage_options.insert("AWS_ACCESS_KEY_ID".to_string(), "admin".to_string()); |
| 30 | + storage_options.insert("AWS_SECRET_ACCESS_KEY".to_string(), "password".to_string()); |
| 31 | + storage_options.insert("AWS_ALLOW_HTTP".to_string(), "true".to_string()); |
| 32 | + storage_options.insert("AWS_S3_ALLOW_UNSAFE_RENAME".to_string(), "true".to_string()); |
| 33 | + |
| 34 | + // Create table |
| 35 | + CreateBuilder::new() |
| 36 | + .with_location("s3://data-lakehouse/".to_string()) |
| 37 | + .with_storage_options(storage_options) |
| 38 | + .with_column("id", DataType::INTEGER, false, Default::default()) |
| 39 | + .with_column("name", DataType::STRING, false, Default::default()) |
| 40 | + .await |
| 41 | + .expect("Table creation failed"); |
| 42 | +} |
| 43 | + |
| 44 | +``` |
0 commit comments