Skip to content

Commit dd7b9fa

Browse files
Backport #56274 to 23.9: Fix incomplete query result for UNION in view() function.
1 parent fbf47f0 commit dd7b9fa

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

src/Interpreters/NormalizeSelectWithUnionQueryVisitor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ void NormalizeSelectWithUnionQueryMatcher::getSelectsFromUnionListNode(ASTPtr as
2828

2929
void NormalizeSelectWithUnionQueryMatcher::visit(ASTPtr & ast, Data & data)
3030
{
31-
if (auto * select_union = ast->as<ASTSelectWithUnionQuery>())
31+
if (auto * select_union = ast->as<ASTSelectWithUnionQuery>(); select_union && !select_union->is_normalized)
32+
{
33+
/// The rewrite of ASTSelectWithUnionQuery may strip the format info, so
34+
/// we need to keep and restore it.
35+
auto format = select_union->format;
3236
visit(*select_union, data);
37+
select_union->format = format;
38+
}
3339
}
3440

3541
void NormalizeSelectWithUnionQueryMatcher::visit(ASTSelectWithUnionQuery & ast, Data & data)

tests/analyzer_tech_debt.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
02345_implicit_transaction
8484
02352_grouby_shadows_arg
8585
02354_annoy
86-
02366_union_decimal_conversion
8786
02375_rocksdb_with_filters
8887
02382_join_and_filtering_set
8988
02402_merge_engine_with_view

tests/queries/0_stateless/00612_union_query_with_subquery.reference

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
1
1111
1
1212
2
13+
3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
SELECT * FROM ((SELECT * FROM system.numbers LIMIT 1) UNION ALL SELECT * FROM system.numbers LIMIT 2 UNION ALL (SELECT * FROM system.numbers LIMIT 3)) ORDER BY number;
22
SELECT * FROM (SELECT * FROM system.numbers LIMIT 1 UNION ALL (SELECT * FROM system.numbers LIMIT 2 UNION ALL (SELECT * FROM system.numbers LIMIT 3))) ORDER BY number;
3+
select count() from view(select 1 union all (select 2 union all select 3));

0 commit comments

Comments
 (0)