Skip to content

Commit

Permalink
feat(query): support DATABEND_DATA_PATH in bendpy and bend-local (#13089
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sundy-li authored Oct 7, 2023
1 parent 96c4c99 commit 5b2b0fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/bendpy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod schema;
mod utils;

use std::env;
use std::path::Path;

use common_config::Config;
use common_config::InnerConfig;
Expand All @@ -37,15 +38,20 @@ use utils::RUNTIME;
/// A Python module implemented in Rust.
#[pymodule]
fn databend(_py: Python, m: &PyModule) -> PyResult<()> {
env::set_var("META_EMBEDDED_DIR", ".databend/_meta");
let data_path = env::var("DATABEND_DATA_PATH").unwrap_or(".databend/".to_string());
let path = Path::new(&data_path);

env::set_var("META_EMBEDDED_DIR", path.join("_meta"));

let mut conf: InnerConfig = Config::load(false).unwrap().try_into().unwrap();
conf.storage.allow_insecure = true;
conf.storage.params = StorageParams::Fs(StorageFsConfig {
root: ".databend/_data".to_string(),
root: path.join("_data").to_str().unwrap().to_owned(),
});

RUNTIME.block_on(async {
MetaEmbedded::init_global_meta_store(".databend/_meta".to_string())
let meta_dir = path.join("_meta");
MetaEmbedded::init_global_meta_store(meta_dir.to_string_lossy().to_string())
.await
.unwrap();
GlobalServices::init(conf.clone()).await.unwrap();
Expand Down
13 changes: 10 additions & 3 deletions src/query/service/src/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) mod helper;
use std::env;
use std::io::stdin;
use std::io::IsTerminal;
use std::path::Path;

use common_config::Config;
use common_config::InnerConfig;
Expand All @@ -35,14 +36,20 @@ use crate::GlobalServices;

pub async fn query_local(query_sql: &str, output_format: &str) -> Result<()> {
let temp_dir = tempfile::tempdir()?;
env::set_var("META_EMBEDDED_DIR", temp_dir.path().join("_meta"));
let p = env::var("DATABEND_DATA_PATH");
let path = match &p {
Ok(p) => Path::new(p),
Err(_) => temp_dir.path(),
};

env::set_var("META_EMBEDDED_DIR", path.join("_meta"));
let mut conf: InnerConfig = Config::load(true).unwrap().try_into().unwrap();
conf.storage.allow_insecure = true;
conf.storage.params = StorageParams::Fs(StorageFsConfig {
root: temp_dir.path().join("_data").to_str().unwrap().to_owned(),
root: path.join("_data").to_str().unwrap().to_owned(),
});

let meta_dir = temp_dir.path().join("_meta");
let meta_dir = path.join("_meta");
MetaEmbedded::init_global_meta_store(meta_dir.to_string_lossy().to_string())
.await
.unwrap();
Expand Down

1 comment on commit 5b2b0fe

@vercel
Copy link

@vercel vercel bot commented on 5b2b0fe Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.