From f41c6b0e6b3bbcdfb57becaca60246d154ac8f6f Mon Sep 17 00:00:00 2001 From: Dmitry Novik Date: Thu, 11 Jan 2024 19:11:42 +0000 Subject: [PATCH] Analyzer: Fix LOGICAL_ERROR in CountDistinctPass --- src/Analyzer/Passes/CountDistinctPass.cpp | 2 ++ .../02962_analyzer_const_in_count_distinct.reference | 1 + .../02962_analyzer_const_in_count_distinct.sql | 8 ++++++++ 3 files changed, 11 insertions(+) create mode 100644 tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.reference create mode 100644 tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.sql diff --git a/src/Analyzer/Passes/CountDistinctPass.cpp b/src/Analyzer/Passes/CountDistinctPass.cpp index 4b64f6c88b0..07a031fe4e8 100644 --- a/src/Analyzer/Passes/CountDistinctPass.cpp +++ b/src/Analyzer/Passes/CountDistinctPass.cpp @@ -61,6 +61,8 @@ public: return; auto & count_distinct_argument_column = count_distinct_arguments_nodes[0]; + if (count_distinct_argument_column->getNodeType() != QueryTreeNodeType::COLUMN) + return; auto & count_distinct_argument_column_typed = count_distinct_argument_column->as(); /// Build subquery SELECT count_distinct_argument_column FROM table_expression GROUP BY count_distinct_argument_column diff --git a/tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.reference b/tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.sql b/tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.sql new file mode 100644 index 00000000000..669018a1308 --- /dev/null +++ b/tests/queries/0_stateless/02962_analyzer_const_in_count_distinct.sql @@ -0,0 +1,8 @@ +set count_distinct_optimization = 1; + +SELECT uniqExact('257') +FROM + (SELECT + number, CAST(number / 9223372036854775806, 'UInt64') AS m + FROM numbers(3) + );