From d134c1521d3ed8b4480f193bfd51c09519ba0d22 Mon Sep 17 00:00:00 2001 From: Salvatore Mesoraca Date: Thu, 11 Jan 2024 11:04:28 +0100 Subject: [PATCH 1/3] Handle signed numeric literals in normalizeQuery This solution is non-ideal, but it's difficult to achieve better results using only the Lexer. Close #57919 --- src/Parsers/queryNormalization.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Parsers/queryNormalization.cpp b/src/Parsers/queryNormalization.cpp index 416e86b1f32..4a9dd8ceb98 100644 --- a/src/Parsers/queryNormalization.cpp +++ b/src/Parsers/queryNormalization.cpp @@ -167,6 +167,8 @@ void normalizeQueryToPODArray(const char * begin, const char * end, PaddedPODArr continue; } } + else if (prev_comma && (token.type == TokenType::Plus || token.type == TokenType::Minus)) + continue; else { if (num_literals_in_sequence > 1) From b32149379f7c65c79aa7bfc77dacfcc2623b9d45 Mon Sep 17 00:00:00 2001 From: Salvatore Mesoraca Date: Thu, 11 Jan 2024 11:18:59 +0100 Subject: [PATCH 2/3] Add tests for new normalizeQuery behavior --- .../0_stateless/01451_normalize_query.reference | 12 ++++++++++++ tests/queries/0_stateless/01451_normalize_query.sql | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/queries/0_stateless/01451_normalize_query.reference b/tests/queries/0_stateless/01451_normalize_query.reference index 339ad34ea77..77e1055c54e 100644 --- a/tests/queries/0_stateless/01451_normalize_query.reference +++ b/tests/queries/0_stateless/01451_normalize_query.reference @@ -23,3 +23,15 @@ SELECT ?.. SELECT ? xyz11 SELECT ?, xyz11 SELECT ?.. +? - ? +?.. +-?.. +? - ?.. +f(-?..) +[-?..] +? + ? +?.. +-?.. +? + ?.. +f(+?..) +[+?..] diff --git a/tests/queries/0_stateless/01451_normalize_query.sql b/tests/queries/0_stateless/01451_normalize_query.sql index 3c01a975712..62c2071885b 100644 --- a/tests/queries/0_stateless/01451_normalize_query.sql +++ b/tests/queries/0_stateless/01451_normalize_query.sql @@ -23,4 +23,15 @@ SELECT normalizeQuery('SELECT 1, ''xyz11'''); SELECT normalizeQuery('SELECT $doc$VALUE$doc$ xyz11'); SELECT normalizeQuery('SELECT $doc$VALUE$doc$, xyz11'); SELECT normalizeQuery('SELECT $doc$VALUE$doc$, ''xyz11'''); - +SELECT normalizeQuery('1 - 2'); +SELECT normalizeQuery('1, -2, 3'); +SELECT normalizeQuery('-1, -2, 3'); +SELECT normalizeQuery('1 - 2, 3, 4'); +SELECT normalizeQuery('f(-2, 3)'); +SELECT normalizeQuery('[-1, 2, 3]'); +SELECT normalizeQuery('1 + 2'); +SELECT normalizeQuery('1, +2, 3'); +SELECT normalizeQuery('-1, +2, 3'); +SELECT normalizeQuery('1 + 2, 3, 4'); +SELECT normalizeQuery('f(+2, 3)'); +SELECT normalizeQuery('[+1, 2, 3]'); From 7b434a77dba67aef635b973ac93863d4bb0ad3a8 Mon Sep 17 00:00:00 2001 From: Salvatore Mesoraca Date: Fri, 12 Jan 2024 16:44:52 +0100 Subject: [PATCH 3/3] Add more tests --- tests/queries/0_stateless/01451_normalize_query.reference | 8 ++++++++ tests/queries/0_stateless/01451_normalize_query.sql | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/queries/0_stateless/01451_normalize_query.reference b/tests/queries/0_stateless/01451_normalize_query.reference index 77e1055c54e..b331e139dc4 100644 --- a/tests/queries/0_stateless/01451_normalize_query.reference +++ b/tests/queries/0_stateless/01451_normalize_query.reference @@ -35,3 +35,11 @@ f(-?..) ? + ?.. f(+?..) [+?..] +?.. + ? +?.. - ?.. +f(+?..), ? +[+?..] - ? +-?.. - [+?..] - ? +(+?..) - ? +-?.. - (+?..) - ? +(+?..) diff --git a/tests/queries/0_stateless/01451_normalize_query.sql b/tests/queries/0_stateless/01451_normalize_query.sql index 62c2071885b..14c74d95019 100644 --- a/tests/queries/0_stateless/01451_normalize_query.sql +++ b/tests/queries/0_stateless/01451_normalize_query.sql @@ -35,3 +35,11 @@ SELECT normalizeQuery('-1, +2, 3'); SELECT normalizeQuery('1 + 2, 3, 4'); SELECT normalizeQuery('f(+2, 3)'); SELECT normalizeQuery('[+1, 2, 3]'); +SELECT normalizeQuery('1, 2, 3 + 4'); +SELECT normalizeQuery('1, 2 - 3, 4'); +SELECT normalizeQuery('f(+2, 3), 1'); +SELECT normalizeQuery('[+1, 2, 3] - 1'); +SELECT normalizeQuery('-1, 1 - [+1, 2, 3] - 1'); +SELECT normalizeQuery('(+1, 2, 3) - 1'); +SELECT normalizeQuery('-1, 1 - (+1, 2, 3) - 1'); +SELECT normalizeQuery('(+1, 2, -3)');