Merge pull request #72114 from ClickHouse/backport/24.8/72080

Backport #72080 to 24.8: Fix formatting of `MOVE PARTITION ... TO TABLE ...` alter commands
This commit is contained in:
robot-ch-test-poll3 2024-11-20 04:47:29 +01:00 committed by GitHub
commit 9a7e25c2b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -70,8 +70,12 @@ ASTPtr ASTAlterCommand::clone() const
void ASTAlterCommand::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const void ASTAlterCommand::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{ {
scope_guard closing_bracket_guard;
if (format_alter_commands_with_parentheses) if (format_alter_commands_with_parentheses)
{
settings.ostr << "("; settings.ostr << "(";
closing_bracket_guard = make_scope_guard(std::function<void(void)>([&settings]() { settings.ostr << ")"; }));
}
if (type == ASTAlterCommand::ADD_COLUMN) if (type == ASTAlterCommand::ADD_COLUMN)
{ {
@ -498,9 +502,6 @@ void ASTAlterCommand::formatImpl(const FormatSettings & settings, FormatState &
} }
else else
throw Exception(ErrorCodes::UNEXPECTED_AST_STRUCTURE, "Unexpected type of ALTER"); throw Exception(ErrorCodes::UNEXPECTED_AST_STRUCTURE, "Unexpected type of ALTER");
if (format_alter_commands_with_parentheses)
settings.ostr << ")";
} }
void ASTAlterCommand::forEachPointerToChild(std::function<void(void**)> f) void ASTAlterCommand::forEachPointerToChild(std::function<void(void**)> f)

View File

@ -43,3 +43,10 @@ ALTER TABLE a\\n (DROP COLUMN b),\\n (DROP COLUMN c)
""" """
result = node.query(INPUT) result = node.query(INPUT)
assert result == EXPECTED_OUTPUT assert result == EXPECTED_OUTPUT
def test_move_partition_to_table_command():
INPUT = "SELECT formatQuery('ALTER TABLE a MOVE PARTITION tuple() TO TABLE b')"
EXPECTED_OUTPUT = "ALTER TABLE a\\n (MOVE PARTITION tuple() TO TABLE b)\n"
result = node.query(INPUT)
assert result == EXPECTED_OUTPUT