Merge pull request #55887 from ucasfl/fix-union-distinct

Fix normalize ASTSelectWithUnionQuery strip FORMAT of the query
This commit is contained in:
robot-ch-test-poll 2023-10-26 13:53:58 +02:00 committed by GitHub
commit da42f2eb0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -29,7 +29,13 @@ void NormalizeSelectWithUnionQueryMatcher::getSelectsFromUnionListNode(ASTPtr as
void NormalizeSelectWithUnionQueryMatcher::visit(ASTPtr & ast, Data & data)
{
if (auto * select_union = ast->as<ASTSelectWithUnionQuery>())
{
/// The rewrite of ASTSelectWithUnionQuery may strip the format info, so
/// we need to keep and restore it.
auto format = select_union->format;
visit(*select_union, data);
select_union->format = format;
}
}
void NormalizeSelectWithUnionQueryMatcher::visit(ASTSelectWithUnionQuery & ast, Data & data)

View File

@ -0,0 +1,7 @@
┌─1─┐
│ 1 │
└───┘
┌─a─┐
│ 1 │
│ 2 │
└───┘

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
curl -d@- -sS "${CLICKHOUSE_URL}" <<< 'SELECT 1 UNION DISTINCT SELECT 1 FORMAT PrettyCompactMonoBlock'
curl -d@- -sS "${CLICKHOUSE_URL}" <<< 'SELECT * FROM (SELECT 1 as a UNION DISTINCT SELECT 2 as a) ORDER BY a FORMAT PrettyCompactMonoBlock'