From cd8810fb05fd108fa0bb6edf9a47f14245aa2cfb Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Fri, 4 Oct 2024 13:12:39 +0000 Subject: [PATCH] Backport #70338 to 24.9: Fix crash when using WITH FILL incorrectly --- src/Analyzer/Resolve/QueryAnalyzer.cpp | 5 +++-- .../0_stateless/03248_with_fill_string_crash.reference | 0 tests/queries/0_stateless/03248_with_fill_string_crash.sql | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/03248_with_fill_string_crash.reference create mode 100644 tests/queries/0_stateless/03248_with_fill_string_crash.sql diff --git a/src/Analyzer/Resolve/QueryAnalyzer.cpp b/src/Analyzer/Resolve/QueryAnalyzer.cpp index 3f88106e8fa..ba1ef850118 100644 --- a/src/Analyzer/Resolve/QueryAnalyzer.cpp +++ b/src/Analyzer/Resolve/QueryAnalyzer.cpp @@ -4019,9 +4019,10 @@ ProjectionNames QueryAnalyzer::resolveSortNodeList(QueryTreeNodePtr & sort_node_ const auto * constant_node = sort_node.getFillTo()->as(); if (!constant_node || !isColumnedAsNumber(constant_node->getResultType())) - throw Exception(ErrorCodes::INVALID_WITH_FILL_EXPRESSION, + throw Exception( + ErrorCodes::INVALID_WITH_FILL_EXPRESSION, "Sort FILL TO expression must be constant with numeric type. Actual {}. In scope {}", - sort_node.getFillFrom()->formatASTForErrorMessage(), + sort_node.getFillTo()->formatASTForErrorMessage(), scope.scope_node->formatASTForErrorMessage()); size_t fill_to_expression_projection_names_size = fill_to_expression_projection_names.size(); diff --git a/tests/queries/0_stateless/03248_with_fill_string_crash.reference b/tests/queries/0_stateless/03248_with_fill_string_crash.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03248_with_fill_string_crash.sql b/tests/queries/0_stateless/03248_with_fill_string_crash.sql new file mode 100644 index 00000000000..ba00640f842 --- /dev/null +++ b/tests/queries/0_stateless/03248_with_fill_string_crash.sql @@ -0,0 +1,7 @@ +CREATE TABLE users (date DateTime, name String, age Int16) ENGINE=MergeTree() ORDER BY date; + +INSERT INTO users VALUES ('2024-01-01', 'John', 33), + ('2024-02-01', 'Ksenia', 48), + ('2024-02-15', 'Alice', 50); + +SELECT * FROM users ORDER BY date WITH FILL TO '2024-02-17' STEP toIntervalHour(1); -- { serverError INVALID_WITH_FILL_EXPRESSION }