From 6d38ed411de29002b6ac0730de162d6c0f61b80e Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Fri, 1 Nov 2024 12:22:58 -0400 Subject: [PATCH 1/3] Minor: Document how to test for trailing whitespace --- datafusion/sqllogictest/README.md | 33 +++++++++++++++++++ .../sqllogictest/test_files/functions.slt | 17 ++++++++++ 2 files changed, 50 insertions(+) diff --git a/datafusion/sqllogictest/README.md b/datafusion/sqllogictest/README.md index 5becc75c985a..901fb19e43a2 100644 --- a/datafusion/sqllogictest/README.md +++ b/datafusion/sqllogictest/README.md @@ -102,6 +102,39 @@ SELECT * from foo; Assuming it looks good, check it in! +## Cookbook: Testing for whitespace + +The `sqllogictest` runner will automatically strip trailing whitespace, meaning +it additional effort to verify that trailing whitespace is correctly produced + +For example, the following test can't distinguish between `Andrew` and `Andrew ` +(with trailing space): + +```text +query T +select substr('Andrew Lamb', 1, 7) +---- +Andrew +``` + +To test trailing whitespace, project additional non-whitespace column on the +right. For example, by selecting `'XX'` after the column of interest, the test +can distinguish between `Andrew` and `Andrew `: + +```text +# Note two spaces between `Andrew` and `XX` +query TT +select substr('Andrew Lamb', 1, 7), 'XX'; +---- +Andrew XX + +# Note only one space between `Andrew` and `XX` +query TT +select substr('Andrew Lamb', 1, 6), 'XX'; +---- +Andrew XX +``` + # Reference ## Running tests: Validation Mode diff --git a/datafusion/sqllogictest/test_files/functions.slt b/datafusion/sqllogictest/test_files/functions.slt index 5b6017b08a00..5bc3d2b6b220 100644 --- a/datafusion/sqllogictest/test_files/functions.slt +++ b/datafusion/sqllogictest/test_files/functions.slt @@ -735,3 +735,20 @@ query B select contains('', ''); ---- true + + +## Demonstrate how to test for trailing whitespace +query T +select substr('Andrew Lamb', 1, 7) +---- +Andrew + +query TT +select substr('Andrew Lamb', 1, 7), 'XX' +---- +Andrew XX + +query TT +select substr('Andrew Lamb', 1, 6), 'XX' +---- +Andrew XX From 583cda7bb818f28a2a8b0aff0431866a4feb29de Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Mon, 4 Nov 2024 15:32:25 -0500 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Piotr Findeisen --- datafusion/sqllogictest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datafusion/sqllogictest/README.md b/datafusion/sqllogictest/README.md index 901fb19e43a2..7a9c53ad0b4e 100644 --- a/datafusion/sqllogictest/README.md +++ b/datafusion/sqllogictest/README.md @@ -105,7 +105,7 @@ Assuming it looks good, check it in! ## Cookbook: Testing for whitespace The `sqllogictest` runner will automatically strip trailing whitespace, meaning -it additional effort to verify that trailing whitespace is correctly produced +it requires an additional effort to verify that trailing whitespace is correctly produced For example, the following test can't distinguish between `Andrew` and `Andrew ` (with trailing space): From a813fe14ea3eb5c974173ba5a2f882d6cc345cd8 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Mon, 4 Nov 2024 15:37:47 -0500 Subject: [PATCH 3/3] Use `|` for consistency --- datafusion/sqllogictest/README.md | 14 +++++++------- datafusion/sqllogictest/test_files/functions.slt | 12 ++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/datafusion/sqllogictest/README.md b/datafusion/sqllogictest/README.md index 7a9c53ad0b4e..885e92fee270 100644 --- a/datafusion/sqllogictest/README.md +++ b/datafusion/sqllogictest/README.md @@ -118,21 +118,21 @@ Andrew ``` To test trailing whitespace, project additional non-whitespace column on the -right. For example, by selecting `'XX'` after the column of interest, the test +right. For example, by selecting `'|'` after the column of interest, the test can distinguish between `Andrew` and `Andrew `: ```text -# Note two spaces between `Andrew` and `XX` +# Note two spaces between `Andrew` and `|` query TT -select substr('Andrew Lamb', 1, 7), 'XX'; +select substr('Andrew Lamb', 1, 7), '|' ---- -Andrew XX +Andrew | -# Note only one space between `Andrew` and `XX` +# Note only one space between `Andrew` and `|` query TT -select substr('Andrew Lamb', 1, 6), 'XX'; +select substr('Andrew Lamb', 1, 6), '|' ---- -Andrew XX +Andrew | ``` # Reference diff --git a/datafusion/sqllogictest/test_files/functions.slt b/datafusion/sqllogictest/test_files/functions.slt index 5bc3d2b6b220..a7568d88f797 100644 --- a/datafusion/sqllogictest/test_files/functions.slt +++ b/datafusion/sqllogictest/test_files/functions.slt @@ -738,17 +738,21 @@ true ## Demonstrate how to test for trailing whitespace + +# Note no trailing whitespace query T select substr('Andrew Lamb', 1, 7) ---- Andrew +# Note two spaces between `Andrew` and `|` query TT -select substr('Andrew Lamb', 1, 7), 'XX' +select substr('Andrew Lamb', 1, 7), '|' ---- -Andrew XX +Andrew | +# Note only one space between `Andrew` and `|` query TT -select substr('Andrew Lamb', 1, 6), 'XX' +select substr('Andrew Lamb', 1, 6), '|' ---- -Andrew XX +Andrew |