MCPcopy Create free account
hub / github.com/apache/datafusion / get_data_dir

Function get_data_dir

datafusion/common/src/test_util.rs:279–319  ·  view source on GitHub ↗

Returns a directory path for finding test data. udf_env: name of an environment variable submodule_dir: fallback path (relative to CARGO_MANIFEST_DIR) Returns either: The path referred to in `udf_env` if that variable is set and refers to a directory The submodule_data directory relative to CARGO_MANIFEST_PATH

(
    udf_env: &str,
    submodule_data: &str,
)

Source from the content-addressed store, hash-verified

277/// The path referred to in `udf_env` if that variable is set and refers to a directory
278/// The submodule_data directory relative to CARGO_MANIFEST_PATH
279pub fn get_data_dir(
280 udf_env: &str,
281 submodule_data: &str,
282) -> Result<PathBuf, Box<dyn Error>> {
283 // Try user defined env.
284 if let Ok(dir) = std::env::var(udf_env) {
285 let trimmed = dir.trim().to_string();
286 if !trimmed.is_empty() {
287 let pb = PathBuf::from(trimmed);
288 if pb.is_dir() {
289 return Ok(pb);
290 } else {
291 return Err(format!(
292 "the data dir `{}` defined by env {} not found",
293 pb.display(),
294 udf_env
295 )
296 .into());
297 }
298 }
299 }
300
301 // The env is undefined or its value is trimmed to empty, let's try default dir.
302
303 // env "CARGO_MANIFEST_DIR" is "the directory containing the manifest of your package",
304 // set by `cargo run` or `cargo test`, see:
305 // https://doc.rust-lang.org/cargo/reference/environment-variables.html
306 let dir = env!("CARGO_MANIFEST_DIR");
307
308 let pb = PathBuf::from(dir).join(submodule_data);
309 if pb.is_dir() {
310 Ok(pb)
311 } else {
312 Err(format!(
313 "env `{}` is undefined or has empty value, and the pre-defined data dir `{}` not found\n\
314 HINT: try running `git submodule update --init`",
315 udf_env,
316 pb.display(),
317 ).into())
318 }
319}
320
321#[macro_export]
322macro_rules! create_array {

Callers 4

datafusion_test_dataFunction · 0.85
arrow_test_dataFunction · 0.85
parquet_test_dataFunction · 0.85
test_data_dirFunction · 0.85

Calls 5

trimMethod · 0.80
to_stringMethod · 0.45
is_emptyMethod · 0.45
intoMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…