From 1ee1dfa6377ffd0cec69758f7f85d1f671952b30 Mon Sep 17 00:00:00 2001 From: Matthew Turner Date: Sun, 24 Nov 2024 11:44:45 -0500 Subject: [PATCH] Add local file query --- src/execution/local.rs | 2 ++ tests/cli_cases/basic.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/execution/local.rs b/src/execution/local.rs index 472b72a..8ee694c 100644 --- a/src/execution/local.rs +++ b/src/execution/local.rs @@ -111,6 +111,8 @@ impl ExecutionContext { } // Register Parquet Metadata Function + let session_ctx = session_ctx.enable_url_table(); + session_ctx.register_udtf( "parquet_metadata", Arc::new(datafusion_functions_parquet::ParquetMetadataFunc {}), diff --git a/tests/cli_cases/basic.rs b/tests/cli_cases/basic.rs index 5edfc5f..7f54a70 100644 --- a/tests/cli_cases/basic.rs +++ b/tests/cli_cases/basic.rs @@ -361,3 +361,35 @@ fn test_write_file() { assert!(file.exists()); } + +#[test] +fn test_query_local_file() { + let sql = "SELECT c1 FROM 'data/aggregate_test_100.csv' LIMIT 1".to_string(); + let assert = Command::cargo_bin("dft") + .unwrap() + .arg("-c") + .arg(sql) + .assert() + .success(); + + let expected = " ++----+ +| c1 | ++----+ +| c | ++----+ +"; + + assert.stdout(contains_str(expected)); +} + +#[test] +fn test_query_non_existent_local_file() { + let sql = "SELECT c1 FROM 'data/nofile.csv' LIMIT 1".to_string(); + Command::cargo_bin("dft") + .unwrap() + .arg("-c") + .arg(sql) + .assert() + .failure(); +}