From 5ae6285c42b8ce4af9163e28325f1d47a67af2ce Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Thu, 31 Oct 2024 15:29:07 +0100 Subject: [PATCH] Allow testing values with trailing whitespace in SLT tests --- datafusion/sqllogictest/bin/sqllogictests.rs | 23 +++++++++++++++++-- .../test_files/string/string_literal.slt | 5 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/datafusion/sqllogictest/bin/sqllogictests.rs b/datafusion/sqllogictest/bin/sqllogictests.rs index 2479252a7b5b0..c3e739d146c6c 100644 --- a/datafusion/sqllogictest/bin/sqllogictests.rs +++ b/datafusion/sqllogictest/bin/sqllogictests.rs @@ -22,6 +22,7 @@ use std::path::{Path, PathBuf}; use clap::Parser; use datafusion_sqllogictest::{DataFusion, TestContext}; use futures::stream::StreamExt; +use itertools::Itertools; use log::info; use sqllogictest::strict_column_validator; @@ -39,6 +40,23 @@ pub fn main() -> Result<()> { .block_on(run_tests()) } +fn value_validator(actual: &[Vec], expected: &[String]) -> bool { + let expected = expected + .iter() + // Trailing whitespace from lines in SLT will typically be removed, but do not fail if it is not + // If particular test wants to cover trailing whitespace on a value, + // it should project additional non-whitespace column on the right. + .map(|s| s.trim_end().to_owned()) + .collect::>(); + let actual = actual + .iter() + .map(|strs| strs.iter().join(" ")) + // Editors do not preserve trailing whitespace, so expected may or may not lack it included + .map(|s| s.trim_end().to_owned()) + .collect::>(); + actual == expected +} + /// Sets up an empty directory at test_files/scratch/ /// creating it if needed and clearing any file contents if it exists /// This allows tests for inserting to external tables or copy to @@ -140,6 +158,7 @@ async fn run_test_file(test_file: TestFile) -> Result<()> { )) }); runner.with_column_validator(strict_column_validator); + runner.with_validator(value_validator); runner .run_file_async(path) .await @@ -158,6 +177,7 @@ async fn run_test_file_with_postgres(test_file: TestFile) -> Result<()> { let mut runner = sqllogictest::Runner::new(|| Postgres::connect(relative_path.clone())); runner.with_column_validator(strict_column_validator); + runner.with_validator(value_validator); runner .run_file_async(path) .await @@ -176,7 +196,6 @@ async fn run_complete_file(test_file: TestFile) -> Result<()> { path, relative_path, } = test_file; - use sqllogictest::default_validator; info!("Using complete mode to complete: {}", path.display()); @@ -196,7 +215,7 @@ async fn run_complete_file(test_file: TestFile) -> Result<()> { .update_test_file( path, col_separator, - default_validator, + value_validator, strict_column_validator, ) .await diff --git a/datafusion/sqllogictest/test_files/string/string_literal.slt b/datafusion/sqllogictest/test_files/string/string_literal.slt index 5d847747693d8..80bd7fc59c008 100644 --- a/datafusion/sqllogictest/test_files/string/string_literal.slt +++ b/datafusion/sqllogictest/test_files/string/string_literal.slt @@ -816,3 +816,8 @@ query B SELECT starts_with('foobar', 'bar') ---- false + +query TT +select ' ', '|' +---- + |