diff --git a/src/Interpreters/TreeRewriter.cpp b/src/Interpreters/TreeRewriter.cpp index 73d7d3d004c..153f64402f4 100644 --- a/src/Interpreters/TreeRewriter.cpp +++ b/src/Interpreters/TreeRewriter.cpp @@ -293,13 +293,11 @@ void removeUnneededColumnsFromSelectClause(const ASTSelectQuery * select_query, else { ASTFunction * func = elem->as(); + + /// Never remove untuple. It's result column may be in required columns. + /// It is not easy to analyze untuple here, because types were not calculated yes. if (func && func->name == "untuple") - for (const auto & col : required_result_columns) - if (col.rfind("_ut_", 0) == 0) - { - new_elements.push_back(elem); - break; - } + new_elements.push_back(elem); } } diff --git a/tests/queries/0_stateless/01803_untuple_subquery.reference b/tests/queries/0_stateless/01803_untuple_subquery.reference new file mode 100644 index 00000000000..838ff3aa952 --- /dev/null +++ b/tests/queries/0_stateless/01803_untuple_subquery.reference @@ -0,0 +1,2 @@ +(0.5,'92233720368547758.07',NULL) 1.00 256 \N \N +\N diff --git a/tests/queries/0_stateless/01803_untuple_subquery.sql b/tests/queries/0_stateless/01803_untuple_subquery.sql new file mode 100644 index 00000000000..512b4c561af --- /dev/null +++ b/tests/queries/0_stateless/01803_untuple_subquery.sql @@ -0,0 +1,3 @@ +SELECT (0.5, '92233720368547758.07', NULL), '', '1.00', untuple(('256', NULL)), NULL FROM (SELECT untuple(((NULL, untuple((('0.0000000100', (65536, NULL, (65535, 9223372036854775807), '25.7', (0.00009999999747378752, '10.25', 1048577), 65536)), '0.0000001024', '65537', NULL))), untuple((9223372036854775807, -inf, 0.5)), NULL, -9223372036854775808)), 257, 7, ('0.0001048575', (1024, NULL, (7, 3), (untuple(tuple(-NULL)), NULL, '0.0001048577', NULL), 0)), 0, (0, 0.9998999834060669, '65537'), untuple(tuple('10.25'))); + +SELECT NULL FROM (SELECT untuple((NULL, dummy)));