-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow testing records with sibling whitespace in SLT tests and add more string tests #13197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<String>], 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::<Vec<_>>(); | ||
let actual = actual | ||
.iter() | ||
.map(|strs| strs.iter().join(" ")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we prob can do this in a sinlge map? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not quite sure what you are suggesting here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm suggesting to have a single collection iteration instead of two
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we can do this in single map. |
||
// Editors do not preserve trailing whitespace, so expected may or may not lack it included | ||
.map(|s| s.trim_end().to_owned()) | ||
.collect::<Vec<_>>(); | ||
actual == expected | ||
} | ||
|
||
/// Sets up an empty directory at test_files/scratch/<name> | ||
/// 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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -816,3 +816,8 @@ query B | |
SELECT starts_with('foobar', 'bar') | ||
---- | ||
false | ||
|
||
query TT | ||
select ' ', '|' | ||
---- | ||
| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a good thing to add in the user documentation (aka https://github.com/apache/datafusion/blob/main/datafusion/sqllogictest/README.md)
I think it would be hard to find here for someone writing sqllogictests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it feels so edge-case'y. but yes, we can add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make a follow on PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slt
/ sqllogictests #13215