Merge pull request #67774 from azat/fix-replace-modifier-format

Fix REPLACE modifier formatting (forbid omitting brackets)
This commit is contained in:
Alexey Milovidov 2024-08-05 17:02:00 +00:00 committed by GitHub
commit 809d73d739
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 7 deletions

View File

@ -323,9 +323,7 @@ void ASTColumnsReplaceTransformer::formatImpl(const FormatSettings & settings, F
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "REPLACE" << (is_strict ? " STRICT " : " ") << (settings.hilite ? hilite_none : "");
if (children.size() > 1)
settings.ostr << "(";
settings.ostr << "(";
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
{
if (it != children.begin())
@ -333,9 +331,7 @@ void ASTColumnsReplaceTransformer::formatImpl(const FormatSettings & settings, F
(*it)->formatImpl(settings, state, frame);
}
if (children.size() > 1)
settings.ostr << ")";
settings.ostr << ")";
}
void ASTColumnsReplaceTransformer::appendColumnName(WriteBuffer & ostr) const

View File

@ -1 +1 @@
CREATE VIEW default.my_view\n(\n `Id` UInt32,\n `Object.Key` Array(UInt16),\n `Object.Value` Array(String)\n)\nAS SELECT * REPLACE arrayMap(x -> (x + 1), `Object.Key`) AS `Object.Key`\nFROM default.my_table
CREATE VIEW default.my_view\n(\n `Id` UInt32,\n `Object.Key` Array(UInt16),\n `Object.Value` Array(String)\n)\nAS SELECT * REPLACE (arrayMap(x -> (x + 1), `Object.Key`) AS `Object.Key`)\nFROM default.my_table

View File

@ -0,0 +1,16 @@
SELECT * REPLACE ((1 / 3) / 3 AS dummy)
SELECT * REPLACE ((1 / 3) / 3 AS dummy)
SELECT * REPLACE STRICT (1 AS id, 2 AS value)
FROM
(
SELECT
0 AS id,
1 AS value
)
SELECT * REPLACE STRICT (1 AS id, 2 AS value)
FROM
(
SELECT
0 AS id,
1 AS value
)

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
q=$($CLICKHOUSE_FORMAT <<<"SELECT * REPLACE(1/3/3 AS dummy)")
echo "$q"
$CLICKHOUSE_FORMAT <<<"$q"
# multiple columns
q=$($CLICKHOUSE_FORMAT <<<"SELECT * REPLACE STRICT (1 AS id, 2 AS value) FROM (SELECT 0 id, 1 value)")
echo "$q"
$CLICKHOUSE_FORMAT <<<"$q"