From 97d4fb01f437fca13d6c82cac4e0ae415bd9332b Mon Sep 17 00:00:00 2001 From: zhongyuankai <872237106@qq.com> Date: Tue, 26 Mar 2024 09:17:58 +0800 Subject: [PATCH] fix test --- src/Parsers/ASTDropQuery.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Parsers/ASTDropQuery.cpp b/src/Parsers/ASTDropQuery.cpp index 6e872d8e6b8..e59ce43287f 100644 --- a/src/Parsers/ASTDropQuery.cpp +++ b/src/Parsers/ASTDropQuery.cpp @@ -78,10 +78,19 @@ void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState if (it != list.children.begin()) settings.ostr << ", "; - auto identifier = dynamic_pointer_cast(*it); - settings.ostr << (identifier->name_parts.size() == 2 - ? backQuoteIfNeed(identifier->name_parts[0]) + "." + backQuoteIfNeed(identifier->name_parts[1]) - : backQuoteIfNeed(identifier->name_parts[0])); + auto identifier = dynamic_pointer_cast(*it); + if (!identifier) + throw Exception(ErrorCodes::SYNTAX_ERROR, "Unexpected ASTIdentifier type for list of table names."); + + if (auto db = identifier->getDatabase()) + { + db->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + auto tb = identifier->getTable(); + chassert(tb); + tb->formatImpl(settings, state, frame); } } else @@ -122,16 +131,12 @@ ASTs ASTDropQuery::getRewrittenASTWithoutMultipleTables() query.database_and_tables = nullptr; query.children.clear(); - auto database_and_table = dynamic_pointer_cast(child); - if (database_and_table->name_parts.size() == 2) - { - query.database = std::make_shared(database_and_table->name_parts[0]); - query.table = std::make_shared(database_and_table->name_parts[1]); - } - else - { - query.table = std::make_shared(database_and_table->name_parts[0]); - } + auto database_and_table = dynamic_pointer_cast(child); + if (!database_and_table) + throw Exception(ErrorCodes::SYNTAX_ERROR, "Unexpected ASTIdentifier type for list of table names."); + + query.database = database_and_table->getDatabase(); + query.table = database_and_table->getTable(); if (query.database) query.children.push_back(query.database);