diff --git a/crates/examples/Cargo.toml b/crates/examples/Cargo.toml new file mode 100644 index 00000000..ef53f871 --- /dev/null +++ b/crates/examples/Cargo.toml @@ -0,0 +1,39 @@ +# 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. + +[package] +name = "hudi-examples" +version.workspace = true +edition.workspace = true +license.workspace = true +rust-version.workspace = true +keywords.workspace = true +readme.workspace = true +description.workspace = true +homepage.workspace = true +repository.workspace = true + +[dependencies] +hudi = { path = "../hudi", features=["datafusion"] } + +[dev-dependencies] +tokio = { workspace = true, features=["macros"] } +datafusion = { workspace = true } + +[[example]] +name = "hello" +path = "hello.rs" diff --git a/crates/examples/README.md b/crates/examples/README.md new file mode 100644 index 00000000..a6c86dbb --- /dev/null +++ b/crates/examples/README.md @@ -0,0 +1,31 @@ + + +## Examples of how to use hudi-rs + +This directory contains a number of examples showcasing various capabilities of +the `hudi` crate. + +All examples can be executed with: + +``` +HUDI_DATA_PATH=/your/data cargo run --example $name +``` + +A good starting point for the examples would be [`hello`](hello.rs). diff --git a/crates/examples/hello.rs b/crates/examples/hello.rs new file mode 100644 index 00000000..f57d7be3 --- /dev/null +++ b/crates/examples/hello.rs @@ -0,0 +1,20 @@ +use std::sync::Arc; +use std::env::var; + +use datafusion::{ + error::Result, + prelude::{DataFrame, SessionContext}, +}; +use hudi::HudiDataSource; + +#[tokio::main] +async fn main() -> Result<()> { + let data_path = var("HUDI_DATA_PATH").unwrap_or_else(|_| "/your/hudi/data/path".to_string()); + + let ctx = SessionContext::new(); + let hudi = HudiDataSource::new(&data_path).await?; + ctx.register_table("example", Arc::new(hudi))?; + let df: DataFrame = ctx.sql("SELECT * FROM example").await?; + df.show().await?; + Ok(()) +}