Skip to content

Commit

Permalink
lazy static
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyxu committed Feb 27, 2024
1 parent f67e44b commit a6be864
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
File renamed without changes.
47 changes: 24 additions & 23 deletions rust/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[workspace]
members = [
"lance-arrow",
"lance-core",
"lance-datagen",
"lance-file",
"lance-index",
"lance-io",
"lance-linalg",
"lance-table",
"lance-testing",
"lance-test-macros",
"lance",
"java/lance-jni",
"rust/lance",
"rust/lance-arrow",
"rust/lance-core",
"rust/lance-datagen",
"rust/lance-file",
"rust/lance-index",
"rust/lance-io",
"rust/lance-linalg",
"rust/lance-table",
"rust/lance-test-macros",
"rust/lance-testing",
]
# Python package needs to be built by maturin.
resolver = "2"
Expand Down Expand Up @@ -39,18 +40,18 @@ categories = [
rust-version = "1.75"

[workspace.dependencies]
lance = { version = "=0.9.19", path = "./lance" }
lance-arrow = { version = "=0.9.19", path = "./lance-arrow" }
lance-core = { version = "=0.9.19", path = "./lance-core" }
lance-datafusion = { version = "=0.9.19", path = "./lance-datafusion" }
lance-datagen = { version = "=0.9.19", path = "./lance-datagen" }
lance-file = { version = "=0.9.19", path = "./lance-file" }
lance-index = { version = "=0.9.19", path = "./lance-index" }
lance-io = { version = "=0.9.19", path = "./lance-io" }
lance-linalg = { version = "=0.9.19", path = "./lance-linalg" }
lance-table = { version = "=0.9.19", path = "./lance-table" }
lance-test-macros = { version = "=0.9.19", path = "./lance-test-macros" }
lance-testing = { version = "=0.9.19", path = "./lance-testing" }
lance = { version = "=0.9.19", path = "./rust/lance" }
lance-arrow = { version = "=0.9.19", path = "./rust/lance-arrow" }
lance-core = { version = "=0.9.19", path = "./rust/lance-core" }
lance-datafusion = { version = "=0.9.19", path = "./rust/lance-datafusion" }
lance-datagen = { version = "=0.9.19", path = "./rust/lance-datagen" }
lance-file = { version = "=0.9.19", path = "./rust/lance-file" }
lance-index = { version = "=0.9.19", path = "./rust/lance-index" }
lance-io = { version = "=0.9.19", path = "./rust/lance-io" }
lance-linalg = { version = "=0.9.19", path = "./rust/lance-linalg" }
lance-table = { version = "=0.9.19", path = "./rust/lance-table" }
lance-test-macros = { version = "=0.9.19", path = "./rust/lance-test-macros" }
lance-testing = { version = "=0.9.19", path = "./rust/lance-testing" }
approx = "0.5.1"
# Note that this one does not include pyarrow
arrow = { version = "50.0.0", optional = false, features = ["prettyprint"] }
Expand Down
17 changes: 12 additions & 5 deletions java/lance-jni/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
[package]
name = "lance-jni"
version = "0.1.0"
edition = "2021"
edition.workspace = true
repository.workspace = true
readme.workspace = true
license.workspace = true
description = "JNI bindings for Lance Columnar format"
keywords.workspace = true
categories.workspace = true

[lib]
crate-type = ["cdylib"]

[dependencies]
lance = { path="../../rust/lance" }
arrow = { version = "50.0.0", features = ["ffi"] }
tokio = { version = "1.23", features = [
lance.workspace = true
arrow = { workspace = true, features = ["ffi"] }
tokio = { workspace = true, features = [
"rt-multi-thread",
"macros",
"fs",
"sync",
] }
jni = "0.21.1"
snafu = "0.7.4"
snafu.workspace = true
lazy_static.workspace = true
17 changes: 7 additions & 10 deletions java/lance-jni/src/blocking_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
// limitations under the License.

use arrow::array::RecordBatchReader;
use tokio::runtime::Runtime;

use lance::dataset::{Dataset, WriteParams};
use lance::Result;

use crate::RT;

pub struct BlockingDataset {
inner: Dataset,
rt: Runtime,
}

impl BlockingDataset {
Expand All @@ -29,24 +29,21 @@ impl BlockingDataset {
uri: &str,
params: Option<WriteParams>,
) -> Result<Self> {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;

let inner = rt.block_on(Dataset::write(reader, uri, params))?;
Ok(BlockingDataset { inner, rt })
let inner = RT.block_on(Dataset::write(reader, uri, params))?;
Ok(Self { inner })
}
pub fn open(uri: &str) -> Result<Self> {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;

let inner = rt.block_on(Dataset::open(uri))?;
Ok(BlockingDataset { inner, rt })
Ok(Self { inner })
}

pub fn count_rows(&self) -> Result<usize> {
self.rt.block_on(self.inner.count_rows())
RT.block_on(self.inner.count_rows())
}

pub fn close(&self) {}
}
20 changes: 13 additions & 7 deletions java/lance-jni/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ use jni::objects::{JMap, JObject, JString};
use jni::sys::{jint, jlong};
use jni::JNIEnv;
use lance::dataset::{WriteMode, WriteParams};
use lazy_static::lazy_static;

lazy_static! {
static ref RT: tokio::runtime::Runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed to create tokio runtime");
}

#[no_mangle]
pub extern "system" fn Java_com_lancedb_lance_Dataset_writeWithFfiStream<'local>(
Expand Down Expand Up @@ -172,9 +180,8 @@ pub extern "system" fn Java_com_lancedb_lance_Dataset_open<'local>(
_obj: JObject,
path: JString,
) -> JObject<'local> {
let path_str = match jni_helpers::extract_path_str(&mut env, &path) {
Ok(value) => value,
Err(_) => return JObject::null(),
let Ok(path_str) = jni_helpers::extract_path_str(&mut env, &path) else {
return JObject::null();
};

match BlockingDataset::open(&path_str) {
Expand Down Expand Up @@ -211,10 +218,9 @@ pub extern "system" fn Java_com_lancedb_lance_Dataset_releaseNativeDataset(
mut env: JNIEnv,
obj: JObject,
) {
let dataset: BlockingDataset = unsafe {
env
.take_rust_field(obj, "nativeDatasetHandle")
.expect("Failed to take native dataset handle")
let dataset: BlockingDataset = unsafe {
env.take_rust_field(obj, "nativeDatasetHandle")
.expect("Failed to take native dataset handle")
};
dataset.close()
}

0 comments on commit a6be864

Please sign in to comment.