Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add OpenDAL Compat #5185

Merged
merged 6 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
51 changes: 51 additions & 0 deletions .github/workflows/ci_integration_compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.

name: Integration Compat CI

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "integrations/compat/**"
- "core/**"
- ".github/workflows/ci_integration_compat.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
check_clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: ./.github/actions/setup

- name: Cargo clippy
working-directory: integrations/compat
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Cargo test
working-directory: integrations/compat
run: cargo test --all-features
30 changes: 30 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,29 @@ jobs:
name: object-parquet-docs
path: ./integrations/parquet/target/doc

build-opendal-compat-doc:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: ./.github/actions/setup

- name: Setup Rust Nightly
run: |
rustup toolchain install ${{ env.RUST_DOC_TOOLCHAIN }}
- name: Build opendal_compat doc
working-directory: "integrations/compat"
run: cargo +${{ env.RUST_DOC_TOOLCHAIN }} doc --lib --no-deps --all-features

- name: Upload docs
uses: actions/upload-artifact@v3
with:
name: opendal-compat-docs
path: ./integrations/compat/target/doc

build-website:
runs-on: ubuntu-latest
permissions:
Expand All @@ -479,6 +502,7 @@ jobs:
- build-unftp-sbe-opendal-doc
- build-virtiofs-opendal-doc
- build-parquet-opendal-doc
- build-opendal-compat-doc

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -559,6 +583,12 @@ jobs:
name: object-store-opendal-docs
path: ./website/static/docs/object-store-opendal

- name: Download opendal_compat docs
uses: actions/download-artifact@v3
with:
name: opendal-compat-docs
path: ./website/static/docs/opendal_compat

- name: Download dav-server-opendalfs docs
uses: actions/download-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
# Order here is sensitive, as it will be used to determine the order of publishing
package:
- "core"
- "integrations/compat"
- "integrations/object_store"
- "integrations/parquet"
- "integrations/dav-server"
Expand Down
9 changes: 6 additions & 3 deletions core/src/types/operator/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ pub struct Operator {

/// # Operator basic API.
impl Operator {
pub(crate) fn inner(&self) -> &Accessor {
/// Fetch the internal accessor.
pub fn inner(&self) -> &Accessor {
&self.accessor
}

pub(crate) fn from_inner(accessor: Accessor) -> Self {
/// Convert inner accessor into operator.
pub fn from_inner(accessor: Accessor) -> Self {
let limit = accessor
.info()
.full_capability()
Expand All @@ -86,7 +88,8 @@ impl Operator {
}
}

pub(crate) fn into_inner(self) -> Accessor {
/// Convert operator into inner accessor.
pub fn into_inner(self) -> Accessor {
self.accessor
}

Expand Down
1 change: 1 addition & 0 deletions integrations/compat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cargo.lock
36 changes: 36 additions & 0 deletions integrations/compat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 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]
description = "Apache OpenDAL Compat"
name = "opendal_compat"

authors = ["Apache OpenDAL <[email protected]>"]
edition = "2021"
homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.75"
version = "1.0.0"

[features]
v0_50_to_v0_49 = ["dep:opendal_v0_49", "dep:opendal_v0_50"]

[dependencies]
async-trait = "0.1"
opendal_v0_49 = { package = "opendal", version = "0.49", optional = true }
opendal_v0_50 = { package = "opendal", version = "0.50", optional = true, path = "../../core" }
61 changes: 61 additions & 0 deletions integrations/compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Apache OpenDAL™ Compat integration

[![Build Status]][actions] [![Latest Version]][crates.io] [![Crate Downloads]][crates.io] [![chat]][discord]

[build status]: https://img.shields.io/github/actions/workflow/status/apache/opendal/ci_integration_compat.yml?branch=main
[actions]: https://github.com/apache/opendal/actions?query=branch%3Amain
[latest version]: https://img.shields.io/crates/v/opendal_compat.svg
[crates.io]: https://crates.io/crates/opendal_compat
[crate downloads]: https://img.shields.io/crates/d/opendal_compat.svg
[chat]: https://img.shields.io/discord/1081052318650339399
[discord]: https://opendal.apache.org/discord

`opendal-compat` provides compatibility functions for opendal.

This crate can make it easier to resolve the compatibility issues between different versions of opendal.

## Useful Links

- Documentation: [release](https://docs.rs/opendal_compat/) | [dev](https://opendal.apache.org/docs/opendal_compat/opendal_compat/)

## Examples

Add the following dependencies to your `Cargo.toml` with correct version:

```toml
[dependencies]
opendal_compat = { version = "1", features = ["v0_50_to_v0_49"] }
opendal = { version = "0.50.0" }
opendal_v0_49 = { package="opendal", version = "0.49" }
```

Convert `opendal::Operator` to old opendal `Operator`:

```rust
use opendal_v0_50::Operator;
use opendal_v0_50::services::MemoryConfig;
use opendal_v0_50::Result;

fn i_need_opendal_v0_49_op(op: opendal_v0_49::Operator) {
// do something with old opendal;
}

fn main() -> Result<()> {
let v0_50_op = Operator::from_config(MemoryConfig::default())?.finish();
let v0_49_op = opendal_compat::v0_50_to_v0_49(v0_50_op);
i_need_opendal_v0_49_op(v0_49_op);
Ok(())
}
```

## Branding

The first and most prominent mentions must use the full form: **Apache OpenDAL™** of the name for any individual usage (webpage, handout, slides, etc.) Depending on the context and writing style, you should use the full form of the name sufficiently often to ensure that readers clearly understand the association of both the OpenDAL project and the OpenDAL software product to the ASF as the parent organization.

For more details, see the [Apache Product Name Usage Guide](https://www.apache.org/foundation/marks/guide).

## License and Trademarks

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.
38 changes: 38 additions & 0 deletions integrations/compat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

//! `opendal_compat` provides compatibility functions for opendal.
//!
//! OpenDAL is widely used across the entire big data ecosystem. Various projects may utilize
//! different versions of OpenDAL. This crate provides compatibility functions to assist users
//! in upgrading OpenDAL without altering their existing code, especially for projects that
//! accept OpenDAL Operators.
//!
//! This project is organized by version. Each version has its own module hidden within a feature,
//! and each module contains only one function that converts from the latest version to the
//! previous version.
//!
//! Currently, `opendal_compat` supports the following versions:
//!
//! - [`v0_50_to_v0_49()`]
//!
//! Please refer to the specific function for more information.

#[cfg(feature = "v0_50_to_v0_49")]
mod v0_50_to_v0_49;
#[cfg(feature = "v0_50_to_v0_49")]
pub use v0_50_to_v0_49::v0_50_to_v0_49;
Loading
Loading