Skip to content

Commit

Permalink
docs: add the examples crate for rust
Browse files Browse the repository at this point in the history
  • Loading branch information
gohalo committed Aug 31, 2024
1 parent f56603b commit b011441
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
39 changes: 39 additions & 0 deletions crates/examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
31 changes: 31 additions & 0 deletions crates/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
~ 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.
-->

## 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).
20 changes: 20 additions & 0 deletions crates/examples/hello.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit b011441

Please sign in to comment.