Skip to content

Commit 4148729

Browse files
authored
Support sqllogictest --complete with postgres (#13746)
Before the change, the request to use PostgreSQL was simply ignored when `--complete` flag was present.
1 parent b69fa67 commit 4148729

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

datafusion/sqllogictest/bin/sqllogictests.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@ async fn run_tests() -> Result<()> {
101101
SpawnedTask::spawn(async move {
102102
let file_path = test_file.relative_path.clone();
103103
let start = datafusion::common::instant::Instant::now();
104-
if options.complete {
105-
run_complete_file(test_file).await?;
106-
} else if options.postgres_runner {
107-
run_test_file_with_postgres(test_file).await?;
108-
} else {
109-
run_test_file(test_file).await?;
104+
match (options.postgres_runner, options.complete) {
105+
(false, false) => run_test_file(test_file).await?,
106+
(false, true) => run_complete_file(test_file).await?,
107+
(true, false) => run_test_file_with_postgres(test_file).await?,
108+
(true, true) => run_complete_file_with_postgres(test_file).await?,
110109
}
111110
println!("Executed {:?}. Took {:?}", file_path, start.elapsed());
112111
Ok(()) as Result<()>
@@ -227,6 +226,41 @@ async fn run_complete_file(test_file: TestFile) -> Result<()> {
227226
})
228227
}
229228

229+
#[cfg(feature = "postgres")]
230+
async fn run_complete_file_with_postgres(test_file: TestFile) -> Result<()> {
231+
use datafusion_sqllogictest::Postgres;
232+
let TestFile {
233+
path,
234+
relative_path,
235+
} = test_file;
236+
info!(
237+
"Using complete mode to complete with Postgres runner: {}",
238+
path.display()
239+
);
240+
setup_scratch_dir(&relative_path)?;
241+
let mut runner =
242+
sqllogictest::Runner::new(|| Postgres::connect(relative_path.clone()));
243+
let col_separator = " ";
244+
runner
245+
.update_test_file(
246+
path,
247+
col_separator,
248+
value_validator,
249+
strict_column_validator,
250+
)
251+
.await
252+
// Can't use e directly because it isn't marked Send, so turn it into a string.
253+
.map_err(|e| {
254+
DataFusionError::Execution(format!("Error completing {relative_path:?}: {e}"))
255+
})
256+
}
257+
258+
#[cfg(not(feature = "postgres"))]
259+
async fn run_complete_file_with_postgres(_test_file: TestFile) -> Result<()> {
260+
use datafusion_common::plan_err;
261+
plan_err!("Can not run with postgres as postgres feature is not enabled")
262+
}
263+
230264
/// Represents a parsed test file
231265
#[derive(Debug)]
232266
struct TestFile {

0 commit comments

Comments
 (0)