diff --git a/datafusion/sqllogictest/Cargo.toml b/datafusion/sqllogictest/Cargo.toml index f254e0db41e6..7ceabd87855f 100644 --- a/datafusion/sqllogictest/Cargo.toml +++ b/datafusion/sqllogictest/Cargo.toml @@ -51,7 +51,7 @@ object_store = { workspace = true } postgres-protocol = { version = "0.6.7", optional = true } postgres-types = { version = "0.2.8", features = ["derive", "with-chrono-0_4"], optional = true } rust_decimal = { version = "1.36.0", features = ["tokio-pg"] } -sqllogictest = "0.23.0" +sqllogictest = "0.24.0" sqlparser = { workspace = true } tempfile = { workspace = true } thiserror = "2.0.0" diff --git a/datafusion/sqllogictest/bin/sqllogictests.rs b/datafusion/sqllogictest/bin/sqllogictests.rs index be3f1cb251b6..813b40ff7ba9 100644 --- a/datafusion/sqllogictest/bin/sqllogictests.rs +++ b/datafusion/sqllogictest/bin/sqllogictests.rs @@ -21,7 +21,7 @@ use datafusion_sqllogictest::{DataFusion, TestContext}; use futures::stream::StreamExt; use itertools::Itertools; use log::info; -use sqllogictest::strict_column_validator; +use sqllogictest::{strict_column_validator, Normalizer}; use std::ffi::OsStr; use std::fs; use std::path::{Path, PathBuf}; @@ -40,19 +40,24 @@ 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::>(); +fn normalizer(s: &String) -> String { + // 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. + s.trim_end().to_owned() +} + +fn value_validator( + normalizer: Normalizer, + actual: &[Vec], + expected: &[String], +) -> bool { + let expected = expected.iter().map(normalizer).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()) + .map(|str| normalizer(&str)) .collect::>(); actual == expected } @@ -159,6 +164,7 @@ async fn run_test_file(test_file: TestFile) -> Result<()> { )) }); runner.with_column_validator(strict_column_validator); + runner.with_normalizer(normalizer); runner.with_validator(value_validator); runner .run_file_async(path) @@ -178,6 +184,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_normalizer(normalizer); runner.with_validator(value_validator); runner .run_file_async(path) @@ -217,6 +224,7 @@ async fn run_complete_file(test_file: TestFile) -> Result<()> { path, col_separator, value_validator, + normalizer, strict_column_validator, ) .await @@ -246,6 +254,7 @@ async fn run_complete_file_with_postgres(test_file: TestFile) -> Result<()> { path, col_separator, value_validator, + normalizer, strict_column_validator, ) .await