Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}