Skip to content

Apache DataFusion SQL Query Engine

Permit running `sqllogictest` as a rust test in IDEs (+ use clap for sqllogicttest parsing, accept (and ignore) rust test harness arguments) (#8288)

Andrew Lambe7cc04db68a0
diff --git a/datafusion/sqllogictest/Cargo.toml b/datafusion/sqllogictest/Cargo.toml
index e333dc816f..7085e1ada0 100644
--- a/datafusion/sqllogictest/Cargo.toml
+++ b/datafusion/sqllogictest/Cargo.toml
@@ -36,6 +36,7 @@ async-trait = { workspace = true }
bigdecimal = { workspace = true }
bytes = { version = "1.4.0", optional = true }
chrono = { workspace = true, optional = true }
+clap = { version = "4.4.8", features = ["derive", "env"] }
datafusion = { path = "../core", version = "34.0.0" }
datafusion-common = { workspace = true }
futures = { version = "0.3.28" }
diff --git a/datafusion/sqllogictest/bin/sqllogictests.rs b/datafusion/sqllogictest/bin/sqllogictests.rs
index aeb1cc4ec9..ffae144eae 100644
--- a/datafusion/sqllogictest/bin/sqllogictests.rs
+++ b/datafusion/sqllogictest/bin/sqllogictests.rs
@@ -21,6 +21,7 @@ use std::path::{Path, PathBuf};
#[cfg(target_family = "windows")]
use std::thread;
+use clap::Parser;
use datafusion_sqllogictest::{DataFusion, TestContext};
use futures::stream::StreamExt;
use log::info;
@@ -77,7 +78,8 @@ async fn run_tests() -> Result<()> {
// Enable logging (e.g. set RUST_LOG=debug to see debug logs)
env_logger::init();
- let options = Options::new();
+ let options: Options = clap::Parser::parse();
+ options.warn_on_ignored();
// Run all tests in parallel, reporting failures at the end
//
@@ -88,7 +90,7 @@ async fn run_tests() -> Result<()> {
.map(|test_file| {
tokio::task::spawn(async move {
println!("Running {:?}", test_file.relative_path);
- if options.complete_mode {
+ if options.complete {
run_complete_file(test_file).await?;
} else if options.postgres_runner {
run_test_file_with_postgres(test_file).await?;
@@ -289,49 +291,54 @@ fn read_dir_recursive_impl(dst: &mut Vec<PathBuf>, path: &Path) -> Result<()> {
}
/// Parsed command line options
+///
+/// This structure attempts to mimic the command line options
+/// accepted by IDEs such as CLion that pass arguments
+///
+/// See <https://github.com/apache/arrow-datafusion/issues/8287> for more details
+#[derive(Parser, Debug)]
+#[clap(author, version, about, long_about= None)]
struct Options {
- // regex like
- /// arguments passed to the program which are treated as
- /// cargo test filter (substring match on filenames)
- filters: Vec<String>,
-
- /// Auto complete mode to fill out expected results
- complete_mode: bool,
-
- /// Run Postgres compatibility tests with Postgres runner
+ #[clap(long, help = "Auto complete mode to fill out expected results")]
+ complete: bool,
+
+ #[clap(
+ long,
+ env = "PG_COMPAT",
+ help = "Run Postgres compatibility tests with Postgres runner"
+ )]
postgres_runner: bool,
- /// Include tpch files
+ #[clap(long, env = "INCLUDE_TPCH", help = "Include tpch files")]
include_tpch: bool,
-}
-impl Options {
- fn new() -> Self {
- let args: Vec<_> = std::env::args().collect();
-
- let complete_mode = args.iter().any(|a| a == "--complete");
- let postgres_runner = std::env::var("PG_COMPAT").map_or(false, |_| true);
- let include_tpch = std::env::var("INCLUDE_TPCH").map_or(false, |_| true);
-
- // treat args after the first as filters to run (substring matching)
- let filters = if !args.is_empty() {
- args.into_iter()
- .skip(1)
- // ignore command line arguments like `--complete`
- .filter(|arg| !arg.as_str().starts_with("--"))
- .collect::<Vec<_>>()
- } else {
- vec![]
- };
+ #[clap(
+ action,
+ help = "regex like arguments passed to the program which are treated as cargo test filter (substring match on filenames)"
+ )]
+ filters: Vec<String>,
- Self {
- filters,
- complete_mode,
- postgres_runner,
- include_tpch,
- }
- }
+ #[clap(
+ long,
+ help = "IGNORED (for compatibility with built in rust test runner)"
+ )]
+ format: Option<String>,
+
+ #[clap(
+ short = 'Z',
+ long,
+ help = "IGNORED (for compatibility with built in rust test runner)"
+ )]
+ z_options: Option<String>,
+
+ #[clap(
+ long,
+ help = "IGNORED (for compatibility with built in rust test runner)"
+ )]
+ show_output: bool,
+}
+impl Options {
/// Because this test can be run as a cargo test, commands like
///
/// ```shell
@@ -359,4 +366,19 @@ impl Options {
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
!self.postgres_runner || file_name.starts_with(PG_COMPAT_FILE_PREFIX)
}
+
+ /// Logs warning messages to stdout if any ignored options are passed
+ fn warn_on_ignored(&self) {
+ if self.format.is_some() {
+ println!("WARNING: Ignoring `--format` compatibility option");
+ }
+
+ if self.z_options.is_some() {
+ println!("WARNING: Ignoring `-Z` compatibility option");
+ }
+
+ if self.show_output {
+ println!("WARNING: Ignoring `--show-output` compatibility option");
+ }
+ }
}