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 postgresql support for OpenDAL #2815

Merged
merged 15 commits into from
Aug 9, 2023
Merged
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -102,12 +102,16 @@ jobs:
with:
distribution: temurin
java-version: "11"

- name: Setup OCaml toolchain
uses: ./.github/actions/setup-ocaml

- name: Cargo clippy
run: cargo clippy --all-targets --all-features --workspace -- -D warnings

- name: Check diff
run: git diff --exit-code

check_msrv:
runs-on: ubuntu-latest
env:
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/service_test_postgresql.yml
@@ -0,0 +1,85 @@
# 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: Service Test Postgresql

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "core/src/**"
- "core/tests/**"
- "!core/src/docs/**"
- "!core/src/services/**"
- "core/src/services/postgresql/**"
- ".github/workflows/service_test_postgresql.yml"

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

jobs:
postgresql:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: testdb
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v3
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
need-nextest: true

- name: Setup PostgreSQL CLI
run: |
sudo apt -y install postgresql-client
psql -V

- name: Create table
run: |
export PGPASSWORD=password
psql -h localhost -U user -d testdb -c "CREATE TABLE data (key TEXT PRIMARY KEY, value BYTEA);"

- name: Test
shell: bash
working-directory: core
run: cargo nextest run postgresql --features services-postgresql
env:
OPENDAL_POSTGRESQL_TEST: on
OPENDAL_POSTGRESQL_CONNECTION_STRING: postgresql://user:password@localhost:5432/testdb
OPENDAL_POSTGRESQL_TABLE: data
OPENDAL_POSTGRESQL_KEY_FIELD: key
OPENDAL_POSTGRESQL_VALUE_FIELD: value
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 5 additions & 12 deletions bin/oay/Cargo.toml
Expand Up @@ -30,25 +30,21 @@ rust-version.workspace = true
version.workspace = true

[features]
default = [
"frontends-webdav",
"frontends-s3"
]
default = ["frontends-webdav", "frontends-s3"]

frontends-webdav = [
"dep:dav-server",
"dep:bytes",
"dep:futures-util"
]
frontends-s3 = []
frontends-webdav = ["dep:dav-server", "dep:bytes", "dep:futures-util"]

[dependencies]
anyhow = "1"
axum = "0.6"
bytes = { version = "1.4.0", optional = true }
chrono = "0.4.26"
clap = { version = "4", features = ["cargo", "string"] }
dav-server = { version = "0.5.5", optional = true }
dirs = "5.0.0"
futures = "0.3"
futures-util = { version = "0.3.16", optional = true }
opendal.workspace = true
quick-xml = { version = "0.29", features = ["serialize", "overlapped-lists"] }
serde = { version = "1", features = ["derive"] }
Expand All @@ -65,6 +61,3 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
url = "2.3.1"
uuid = { version = "1", features = ["v4", "fast-rng"] }
dav-server = { version = "0.5.5", optional = true }
bytes = { version = "1.4.0", optional = true }
futures-util = { version = "0.3.16", optional = true }
2 changes: 1 addition & 1 deletion bin/oli/Cargo.toml
Expand Up @@ -74,4 +74,4 @@ url = "2.3.1"
[dev-dependencies]
assert_cmd = "2"
predicates = "3"
tempfile = "3.7.1"
tempfile = "3.7.1"
6 changes: 3 additions & 3 deletions bindings/lua/Cargo.toml
Expand Up @@ -29,7 +29,6 @@ rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[features]
default = ["mlua/lua52"]
lua52 = ["mlua", "mlua/lua52"]
Expand All @@ -38,6 +37,7 @@ lua52 = ["mlua", "mlua/lua52"]
crate-type = ["cdylib"]

[dependencies]
mlua = { version = "0.8", features = ["module"], default-features = false, optional = true }
mlua = { version = "0.8", features = [
"module",
], default-features = false, optional = true }
opendal.workspace = true

5 changes: 2 additions & 3 deletions bindings/ocaml/Cargo.toml
Expand Up @@ -32,9 +32,8 @@ crate-type = ["staticlib", "cdylib"]
doc = false

[dependencies]
ocaml = { version = "^1.0.0-beta" }
opendal.workspace = true
ocaml = {version = "^1.0.0-beta"}

[build-dependencies]
ocaml-build = {version = "^1.0.0-beta"}

ocaml-build = { version = "^1.0.0-beta" }
7 changes: 6 additions & 1 deletion core/Cargo.toml
Expand Up @@ -150,6 +150,7 @@ services-oss = [
"reqsign?/reqwest_request",
]
services-persy = ["dep:persy"]
services-postgresql = ["dep:tokio-postgres"]
services-redb = ["dep:redb"]
services-redis = ["dep:redis"]
services-redis-native-tls = ["services-redis", "redis?/tokio-native-tls-comp"]
Expand Down Expand Up @@ -200,7 +201,10 @@ cacache = { version = "11.6", default-features = false, features = [
"tokio-runtime",
"mmap",
], optional = true }
chrono = { version = "0.4.26", default-features = false, features = ["clock", "std"] }
chrono = { version = "0.4.26", default-features = false, features = [
"clock",
"std",
] }
dashmap = { version = "5.4", optional = true }
dirs = { version = "5.0.1", optional = true }
etcd-client = { version = "0.11", optional = true, features = ["tls"] }
Expand Down Expand Up @@ -256,6 +260,7 @@ suppaftp = { version = "4.5", default-features = false, features = [
], optional = true }
tikv-client = { version = "0.2.0", optional = true }
tokio = "1.27"
tokio-postgres = { version = "0.7.8", optional = true }
tracing = { version = "0.1", optional = true }
uuid = { version = "1", features = ["serde", "v4"] }

Expand Down
2 changes: 1 addition & 1 deletion core/src/raw/adapters/kv/api.rs
Expand Up @@ -31,7 +31,7 @@ use crate::Scheme;
/// By implement this trait, any kv service can work as an OpenDAL Service.
#[async_trait]
pub trait Adapter: Send + Sync + Debug + Unpin + 'static {
/// Return the medata of this key value accessor.
/// Return the metadata of this key value accessor.
fn metadata(&self) -> Metadata;

/// Get a key from service.
Expand Down
3 changes: 2 additions & 1 deletion core/src/raw/adapters/mod.rs
Expand Up @@ -43,7 +43,8 @@
//!
//! # Available Adapters
//!
//! - [`kv::Adapter`]: Adapter for Key Value Services like in-memory map, `redis`.
//! - [`kv::Adapter`]: Adapter for Key Value Services like `redis`.
//! - [`typed_kv::Adapter`]: Adapter key key value services that in-memory.

pub mod kv;
pub mod typed_kv;
5 changes: 5 additions & 0 deletions core/src/services/mod.rs
Expand Up @@ -203,3 +203,8 @@ pub use self::tikv::Tikv;
mod foundationdb;
#[cfg(feature = "services-foundationdb")]
pub use self::foundationdb::Foundationdb;

#[cfg(feature = "services-postgresql")]
mod postgresql;
#[cfg(feature = "services-postgresql")]
pub use self::postgresql::Postgresql;