Merge pull request #46232 from aiven-sal/aiven-sal/format

ASTFunction: never rewrite tuple function as literal when formatting
This commit is contained in:
Alexey Milovidov 2023-02-11 05:56:08 +03:00 committed by GitHub
commit c6dc39f9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -1019,7 +1019,8 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
if (!written && arguments->children.size() >= 2 && name == "tuple"sv)
{
settings.ostr << (settings.hilite ? hilite_operator : "") << '(' << (settings.hilite ? hilite_none : "");
settings.ostr << (settings.hilite ? hilite_operator : "") << ((frame.need_parens && !alias.empty()) ? "tuple" : "") << '('
<< (settings.hilite ? hilite_none : "");
for (size_t i = 0; i < arguments->children.size(); ++i)
{
if (i != 0)

View File

@ -0,0 +1,4 @@
SELECT (1, 2, 3)
SELECT (1, 2, 3) AS x
SELECT (1, 2, 3).1
SELECT (tuple(1, 2, 3) AS x).1

View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
echo "select (tuple(1, 2, 3));" | "$CLICKHOUSE_FORMAT"
echo "select (tuple(1, 2, 3) as x);" | "$CLICKHOUSE_FORMAT"
echo "select (tuple(1, 2, 3)).1;" | "$CLICKHOUSE_FORMAT"
echo "select (tuple(1, 2, 3) as x).1;" | "$CLICKHOUSE_FORMAT"