Skip to content

Improve sqllogictest error reporting #15905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions datafusion/sqllogictest/bin/sqllogictests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use itertools::Itertools;
use log::Level::Info;
use log::{info, log_enabled};
use sqllogictest::{
parse_file, strict_column_validator, AsyncDB, Condition, Normalizer, Record,
Validator,
parse_file, strict_column_validator, AsyncDB, Condition, MakeConnection, Normalizer,
Record, Validator,
};

#[cfg(feature = "postgres")]
Expand All @@ -50,6 +50,7 @@ const TEST_DIRECTORY: &str = "test_files/";
const DATAFUSION_TESTING_TEST_DIRECTORY: &str = "../../datafusion-testing/data/";
const PG_COMPAT_FILE_PREFIX: &str = "pg_compat_";
const SQLITE_PREFIX: &str = "sqlite";
const ERRS_PER_FILE_LIMIT: usize = 10;

pub fn main() -> Result<()> {
tokio::runtime::Builder::new_multi_thread()
Expand Down Expand Up @@ -234,15 +235,45 @@ async fn run_test_file(
runner.with_column_validator(strict_column_validator);
runner.with_normalizer(value_normalizer);
runner.with_validator(validator);
let result = run_file_in_runner(path, runner).await;
pb.finish_and_clear();
result
}

let res = runner
.run_file_async(path)
.await
.map_err(|e| DataFusionError::External(Box::new(e)));
async fn run_file_in_runner<D: AsyncDB, M: MakeConnection<Conn = D>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async fn run_file_in_runner<D: AsyncDB, M: MakeConnection<Conn = D>>(
/// Run the test file specified by `path` using the provided runner.
/// Only first `ERRS_PER_FILE_LIMIT` errors will be displayed.
async fn run_file_in_runner<D: AsyncDB, M: MakeConnection<Conn = D>>(

path: PathBuf,
mut runner: sqllogictest::Runner<D, M>,
) -> Result<()> {
let path = path.canonicalize()?;
let records =
parse_file(&path).map_err(|e| DataFusionError::External(Box::new(e)))?;
let mut errs = vec![];
for record in records.into_iter() {
if let Record::Halt { .. } = record {
break;
}
if let Err(err) = runner.run_async(record).await {
errs.push(format!("{err}"));
}
}

pb.finish_and_clear();
if !errs.is_empty() {
let mut msg = format!("{} errors in file {}\n\n", errs.len(), path.display());
for (i, err) in errs.iter().enumerate() {
if i >= ERRS_PER_FILE_LIMIT {
msg.push_str(&format!(
"... other {} errors in {} not shown ...\n\n",
errs.len() - ERRS_PER_FILE_LIMIT,
path.display()
));
break;
}
msg.push_str(&format!("{}. {err}\n\n", i + 1));
}
return Err(DataFusionError::External(msg.into()));
}

res
Ok(())
}

fn get_record_count(path: &PathBuf, label: String) -> u64 {
Expand Down Expand Up @@ -308,14 +339,9 @@ async fn run_test_file_with_postgres(
runner.with_column_validator(strict_column_validator);
runner.with_normalizer(value_normalizer);
runner.with_validator(validator);
runner
.run_file_async(path)
.await
.map_err(|e| DataFusionError::External(Box::new(e)))?;

let result = run_file_in_runner(path, runner).await;
pb.finish_and_clear();

Ok(())
result
}

#[cfg(not(feature = "postgres"))]
Expand Down