Skip to content

Commit

Permalink
Query local files (datafusion-contrib#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmturner authored Nov 24, 2024
1 parent dec8788 commit 7e0d76f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/execution/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}),
Expand Down
32 changes: 32 additions & 0 deletions tests/cli_cases/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 7e0d76f

Please sign in to comment.