use crate::execution::context::SessionState;
use crate::prelude::SessionContext;
use datafusion_execution::config::SessionConfig;
use datafusion_execution::runtime_env::RuntimeEnv;
use futures::FutureExt;
use object_store::{memory::InMemory, path::Path, ObjectMeta, ObjectStore};
use std::sync::Arc;
use url::Url;
pub fn register_test_store(ctx: &SessionContext, files: &[(&str, u64)]) {
let url = Url::parse("test://").unwrap();
ctx.register_object_store(&url, make_test_store_and_state(files).0);
}
pub fn make_test_store_and_state(files: &[(&str, u64)]) -> (Arc<InMemory>, SessionState) {
let memory = InMemory::new();
for (name, size) in files {
memory
.put(&Path::from(*name), vec![0; *size as usize].into())
.now_or_never()
.unwrap()
.unwrap();
}
(
Arc::new(memory),
SessionState::new_with_config_rt(
SessionConfig::default(),
Arc::new(RuntimeEnv::default()),
),
)
}
pub fn local_unpartitioned_file(path: impl AsRef<std::path::Path>) -> ObjectMeta {
let location = Path::from_filesystem_path(path.as_ref()).unwrap();
let metadata = std::fs::metadata(path).expect("Local file metadata");
ObjectMeta {
location,
last_modified: metadata.modified().map(chrono::DateTime::from).unwrap(),
size: metadata.len() as usize,
e_tag: None,
version: None,
}
}