Skip to content

Normalize NUL to \0 in sqllogictests#17181

Merged
alamb merged 2 commits into
apache:mainfrom
Jefffrey:normalize_nul_sqllogictest
Aug 14, 2025
Merged

Normalize NUL to \0 in sqllogictests#17181
alamb merged 2 commits into
apache:mainfrom
Jefffrey:normalize_nul_sqllogictest

Conversation

@Jefffrey

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

In the SLT files, change NUL character to \0 string (apparently we already had this for char.slt

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Aug 13, 2025
Comment thread datafusion/sqllogictest/src/engines/conversion.rs
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@Jefffrey
Jefffrey marked this pull request as ready for review August 13, 2025 20:34

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange that Github still renders this as binary for me

Screenshot 2025-08-13 at 4 38 07 PM

🤷

Looks like git still treats them as binary too 🤔

diff --git a/datafusion/sqllogictest/src/engines/conversion.rs b/datafusion/sqllogictest/src/engines/conversion.rs
index 92ab64059..de3acbee9 100644
--- a/datafusion/sqllogictest/src/engines/conversion.rs
+++ b/datafusion/sqllogictest/src/engines/conversion.rs
@@ -35,7 +35,8 @@ pub(crate) fn varchar_to_str(value: &str) -> String {
     if value.is_empty() {
         "(empty)".to_string()
     } else {
-        value.trim_end_matches('\n').to_string()
+        // Escape nulls so that github renders them correctly in the webui
+        value.trim_end_matches('\n').replace("\u{0000}", "\\0")
     }
 }

diff --git a/datafusion/sqllogictest/test_files/expr.slt b/datafusion/sqllogictest/test_files/expr.slt
index f0bf5d76e..eeea3cd39 100644
Binary files a/datafusion/sqllogictest/test_files/expr.slt and b/datafusion/sqllogictest/test_files/expr.slt differ
diff --git a/datafusion/sqllogictest/test_files/spark/string/char.slt b/datafusion/sqllogictest/test_files/spark/string/char.slt
index abf0c7076..299e2a041 100644
Binary files a/datafusion/sqllogictest/test_files/spark/string/char.slt and b/datafusion/sqllogictest/test_files/spark/string/char.slt differ
@Jefffrey

Copy link
Copy Markdown
Contributor Author

It is strange that Github still renders this as binary for me
Screenshot 2025-08-13 at 4 38 07 PM

🤷

Looks like git still treats them as binary too 🤔

diff --git a/datafusion/sqllogictest/src/engines/conversion.rs b/datafusion/sqllogictest/src/engines/conversion.rs
index 92ab64059..de3acbee9 100644
--- a/datafusion/sqllogictest/src/engines/conversion.rs
+++ b/datafusion/sqllogictest/src/engines/conversion.rs
@@ -35,7 +35,8 @@ pub(crate) fn varchar_to_str(value: &str) -> String {
     if value.is_empty() {
         "(empty)".to_string()
     } else {
-        value.trim_end_matches('\n').to_string()
+        // Escape nulls so that github renders them correctly in the webui
+        value.trim_end_matches('\n').replace("\u{0000}", "\\0")
     }
 }

diff --git a/datafusion/sqllogictest/test_files/expr.slt b/datafusion/sqllogictest/test_files/expr.slt
index f0bf5d76e..eeea3cd39 100644
Binary files a/datafusion/sqllogictest/test_files/expr.slt and b/datafusion/sqllogictest/test_files/expr.slt differ
diff --git a/datafusion/sqllogictest/test_files/spark/string/char.slt b/datafusion/sqllogictest/test_files/spark/string/char.slt
index abf0c7076..299e2a041 100644
Binary files a/datafusion/sqllogictest/test_files/spark/string/char.slt and b/datafusion/sqllogictest/test_files/spark/string/char.slt differ

I think only for this diff, since it still has the NUL character. If I check the file after the change, its back to text:

https://github.com/apache/datafusion/blob/dd224c4a6db4d6e2e68f74160c7577a3b122983f/datafusion/sqllogictest/test_files/expr.slt

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Jefffrey

In case anyone else is interested, here is the actua diff of the files, as expected:

(venv) andrewlamb@Andrews-MacBook-Pro-3:~/Software/datafusion$ git diff --text 3b8fabdefd0ad0087fc93f727a8f582e1d74f0c5
diff --git a/datafusion/sqllogictest/src/engines/conversion.rs b/datafusion/sqllogictest/src/engines/conversion.rs
index 92ab64059..de3acbee9 100644
--- a/datafusion/sqllogictest/src/engines/conversion.rs
+++ b/datafusion/sqllogictest/src/engines/conversion.rs
@@ -35,7 +35,8 @@ pub(crate) fn varchar_to_str(value: &str) -> String {
     if value.is_empty() {
         "(empty)".to_string()
     } else {
-        value.trim_end_matches('\n').to_string()
+        // Escape nulls so that github renders them correctly in the webui
+        value.trim_end_matches('\n').replace("\u{0000}", "\\0")
     }
 }

diff --git a/datafusion/sqllogictest/test_files/expr.slt b/datafusion/sqllogictest/test_files/expr.slt
index f0bf5d76e..eeea3cd39 100644
--- a/datafusion/sqllogictest/test_files/expr.slt
+++ b/datafusion/sqllogictest/test_files/expr.slt
@@ -427,7 +427,7 @@ NULL
 query T
 SELECT chr(CAST(0 AS int))
 ----
-^@
+\0

 statement error DataFusion error: Execution error: invalid Unicode scalar value: 9223372036854775807
 SELECT chr(CAST(9223372036854775807 AS bigint))
diff --git a/datafusion/sqllogictest/test_files/spark/string/char.slt b/datafusion/sqllogictest/test_files/spark/string/char.slt
index abf0c7076..299e2a041 100644
--- a/datafusion/sqllogictest/test_files/spark/string/char.slt
+++ b/datafusion/sqllogictest/test_files/spark/string/char.slt
@@ -29,6 +29,6 @@ query T
 SELECT char(a) FROM (VALUES (-1::INT), (0::INT), (65::INT), (321::INT)) AS t(a);
 ----
 (empty)
-^@
+\0
 A
 A
@alamb
alamb merged commit 274cdba into apache:main Aug 14, 2025
27 checks passed
@Jefffrey
Jefffrey deleted the normalize_nul_sqllogictest branch August 14, 2025 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt)

2 participants