Skip to content

Commit

Permalink
ensure example works
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Jun 7, 2024
1 parent 56567b3 commit 48c6fa9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 55 deletions.
5 changes: 3 additions & 2 deletions integrations/object_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ async-trait = "0.1"
bytes = "1"
futures = "0.3"
futures-util = "0.3"
object_store = "0.10.0"
object_store = "0.10"
opendal = { version = "0.47.0", path = "../../core" }
pin-project = "1.1"
send_wrapper = { version = "0.6", features = ["futures"], optional = true }
tokio = { version = "1", default-features = false }

[dev-dependencies]
opendal = { version = "0.47.0", path = "../../core", features = [
"services-memory",
"services-memory",
"services-s3",
] }
tokio = { version = "1", features = ["fs", "macros", "rt-multi-thread"] }
70 changes: 17 additions & 53 deletions integrations/object_store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,32 @@ The `OpendalStore` uses the `opendal` crate to interact with the underlying obje

## Examples

first you need to add the following dependencies to your `Cargo.toml`:
Firstly, you need to add the following dependencies to your `Cargo.toml`:

```toml
[dependencies]
object_store = "0.9.0"
object_store_opendal = "0.43.1"
object_store = "0.10.0"
object_store_opendal = "0.44.0"
opendal = { version = "0.47.0", features = ["services-s3"] }
```

> the current version we support is object store 0.9
> [!NOTE]
>
> The current version we support is object store 0.10.
Then you can use the `OpendalStore` as follows:

```rust
use std::sync::Arc;

use bytes::Bytes;
use object_store::path::Path;
use object_store::ObjectStore;
use object_store_opendal::OpendalStore;
use opendal::{services::S3, Builder, Operator};

async fn operate_object_store() {
let builder = S3::from_map(
vec![
("access_key".to_string(), "my_access_key".to_string()),
("secret_key".to_string(), "my_secret_key".to_string()),
("endpoint".to_string(), "my_endpoint".to_string()),
("region".to_string(), "my_region".to_string()),
]
.into_iter()
.collect(),
);

// Create a new operator
let operator = Operator::new(builder).unwrap().finish();

// Create a new object store
let object_store = Arc::new(OpendalStore::new(operator));

let path = Path::from("data/nested/test.txt");
let bytes = Bytes::from_static(b"hello, world! I am nested.");

object_store.put(&path, bytes.clone().into()).await.unwrap();

let content = object_store.get(&path).await.unwrap().bytes().await.unwrap();

assert_eq!(content, bytes);
}
```
Then you can use the `OpendalStore` as in the [example](examples/basic.rs).

## API

The `OpendalStore` implements the `ObjectStore` trait, which provides the following methods:

| Method | Description | link |
| --- | --- | --- |
| `put` | Put an object into the store. | [put](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.put) |
| `get` | Get an object from the store. | [get](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.get) |
| `get_range` | Get a range of bytes from an object in the store. | [get_range](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.get_range) |
| `head` | Get the metadata of an object in the store. | [head](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.head) |
| `delete` | Delete an object from the store. | [delete](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.delete) |
| `list` | List objects in the store. | [list](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.list) |
| `list_with_offset` | List objects in the store with an offset. | [list_with_offset](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.list_with_offset) |
| `list_with_delimiter` | List objects in the store with a delimiter. | [list_with_delimiter](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.list_with_delimiter) |
| Method | Description | link |
|-----------------------|---------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| `put` | Put an object into the store. | [put](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.put) |
| `get` | Get an object from the store. | [get](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.get) |
| `get_range` | Get a range of bytes from an object in the store. | [get_range](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.get_range) |
| `head` | Get the metadata of an object in the store. | [head](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.head) |
| `delete` | Delete an object from the store. | [delete](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.delete) |
| `list` | List objects in the store. | [list](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.list) |
| `list_with_offset` | List objects in the store with an offset. | [list_with_offset](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.list_with_offset) |
| `list_with_delimiter` | List objects in the store with a delimiter. | [list_with_delimiter](https://docs.rs/object_store/0.9.0/object_store/trait.ObjectStore.html#tymethod.list_with_delimiter) |
43 changes: 43 additions & 0 deletions integrations/object_store/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::sync::Arc;

use bytes::Bytes;
use object_store::path::Path;
use object_store::ObjectStore;
use object_store_opendal::OpendalStore;
use opendal::{Builder, Operator};
use opendal::services::S3;

#[tokio::main]
async fn main() {
let builder = S3::from_map(
vec![
("access_key".to_string(), "my_access_key".to_string()),
("secret_key".to_string(), "my_secret_key".to_string()),
("endpoint".to_string(), "my_endpoint".to_string()),
("region".to_string(), "my_region".to_string()),
]
.into_iter()
.collect(),
);

// Create a new operator
let operator = Operator::new(builder).unwrap().finish();

// Create a new object store
let object_store = Arc::new(OpendalStore::new(operator));

let path = Path::from("data/nested/test.txt");
let bytes = Bytes::from_static(b"hello, world! I am nested.");

object_store.put(&path, bytes.clone().into()).await.unwrap();

let content = object_store
.get(&path)
.await
.unwrap()
.bytes()
.await
.unwrap();

assert_eq!(content, bytes);
}

0 comments on commit 48c6fa9

Please sign in to comment.