From c6d75d148655f3900ead8e071be0057968422a14 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 19 Feb 2024 08:15:28 +0100 Subject: [PATCH] Attempt to remove a lot of trash --- src/Parsers/ASTAlterQuery.cpp | 7 ++++--- src/Parsers/ASTCheckQuery.h | 7 ++++--- src/Parsers/ASTCreateIndexQuery.cpp | 7 ++++--- src/Parsers/ASTCreateQuery.cpp | 23 ++++++++++++++++++---- src/Parsers/ASTDeleteQuery.cpp | 7 ++++--- src/Parsers/ASTDropIndexQuery.cpp | 7 ++++--- src/Parsers/ASTDropQuery.cpp | 17 ++++++++++++---- src/Parsers/ASTInsertQuery.cpp | 9 +++++++-- src/Parsers/ASTOptimizeQuery.cpp | 11 +++++++++-- src/Parsers/ASTQueryWithTableAndOutput.cpp | 6 ------ src/Parsers/ASTQueryWithTableAndOutput.h | 17 +++++++++++----- src/Parsers/ASTUndropQuery.cpp | 19 ++++++++++++++---- src/Parsers/ASTWatchQuery.h | 21 +++++++++++++------- 13 files changed, 109 insertions(+), 49 deletions(-) diff --git a/src/Parsers/ASTAlterQuery.cpp b/src/Parsers/ASTAlterQuery.cpp index a6543190904..4e4890df32e 100644 --- a/src/Parsers/ASTAlterQuery.cpp +++ b/src/Parsers/ASTAlterQuery.cpp @@ -621,10 +621,11 @@ void ASTAlterQuery::formatQueryImpl(const FormatSettings & settings, FormatState { if (database) { - settings.ostr << indent_str << backQuoteIfNeed(getDatabase()); - settings.ostr << "."; + database->formatImpl(settings, state, frame); + settings.ostr << '.'; } - settings.ostr << indent_str << backQuoteIfNeed(getTable()); + + table->formatImpl(settings, state, frame); } else if (alter_object == AlterObjectType::DATABASE && database) { diff --git a/src/Parsers/ASTCheckQuery.h b/src/Parsers/ASTCheckQuery.h index c9a17ca4a54..5e9032e77fb 100644 --- a/src/Parsers/ASTCheckQuery.h +++ b/src/Parsers/ASTCheckQuery.h @@ -49,10 +49,11 @@ protected: { if (database) { - settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << backQuoteIfNeed(getDatabase()) << (settings.hilite ? hilite_none : ""); - settings.ostr << "."; + database->formatImpl(settings, state, frame); + settings.ostr << '.'; } - settings.ostr << (settings.hilite ? hilite_keyword : "") << indent_str << backQuoteIfNeed(getTable()) << (settings.hilite ? hilite_none : ""); + + table->formatImpl(settings, state, frame); } if (partition) diff --git a/src/Parsers/ASTCreateIndexQuery.cpp b/src/Parsers/ASTCreateIndexQuery.cpp index 4e03dad5b5b..84493ff22f1 100644 --- a/src/Parsers/ASTCreateIndexQuery.cpp +++ b/src/Parsers/ASTCreateIndexQuery.cpp @@ -48,10 +48,11 @@ void ASTCreateIndexQuery::formatQueryImpl(const FormatSettings & settings, Forma { if (database) { - settings.ostr << indent_str << backQuoteIfNeed(getDatabase()); - settings.ostr << "."; + database->formatImpl(settings, state, frame); + settings.ostr << '.'; } - settings.ostr << indent_str << backQuoteIfNeed(getTable()); + + table->formatImpl(settings, state, frame); } formatOnCluster(settings); diff --git a/src/Parsers/ASTCreateQuery.cpp b/src/Parsers/ASTCreateQuery.cpp index 9d5f0bcddbd..6410a78953a 100644 --- a/src/Parsers/ASTCreateQuery.cpp +++ b/src/Parsers/ASTCreateQuery.cpp @@ -298,8 +298,15 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat << (temporary ? "TEMPORARY " : "") << what << " " << (if_not_exists ? "IF NOT EXISTS " : "") - << (settings.hilite ? hilite_none : "") - << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable()); + << (settings.hilite ? hilite_none : ""); + + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); if (uuid != UUIDHelpers::Nil) settings.ostr << (settings.hilite ? hilite_keyword : "") << " UUID " << (settings.hilite ? hilite_none : "") @@ -331,8 +338,16 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat /// Always DICTIONARY settings.ostr << (settings.hilite ? hilite_keyword : "") << action << " DICTIONARY " - << (if_not_exists ? "IF NOT EXISTS " : "") << (settings.hilite ? hilite_none : "") - << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable()); + << (if_not_exists ? "IF NOT EXISTS " : "") << (settings.hilite ? hilite_none : ""); + + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); + if (uuid != UUIDHelpers::Nil) settings.ostr << (settings.hilite ? hilite_keyword : "") << " UUID " << (settings.hilite ? hilite_none : "") << quoteString(toString(uuid)); diff --git a/src/Parsers/ASTDeleteQuery.cpp b/src/Parsers/ASTDeleteQuery.cpp index 09dc4b936ae..1e8303dac62 100644 --- a/src/Parsers/ASTDeleteQuery.cpp +++ b/src/Parsers/ASTDeleteQuery.cpp @@ -36,10 +36,11 @@ void ASTDeleteQuery::formatQueryImpl(const FormatSettings & settings, FormatStat if (database) { - settings.ostr << backQuoteIfNeed(getDatabase()); - settings.ostr << "."; + database->formatImpl(settings, state, frame); + settings.ostr << '.'; } - settings.ostr << backQuoteIfNeed(getTable()); + + table->formatImpl(settings, state, frame); formatOnCluster(settings); diff --git a/src/Parsers/ASTDropIndexQuery.cpp b/src/Parsers/ASTDropIndexQuery.cpp index 6866770d2ab..1a1481ea27f 100644 --- a/src/Parsers/ASTDropIndexQuery.cpp +++ b/src/Parsers/ASTDropIndexQuery.cpp @@ -43,10 +43,11 @@ void ASTDropIndexQuery::formatQueryImpl(const FormatSettings & settings, FormatS { if (database) { - settings.ostr << indent_str << backQuoteIfNeed(getDatabase()); - settings.ostr << "."; + database->formatImpl(settings, state, frame); + settings.ostr << '.'; } - settings.ostr << indent_str << backQuoteIfNeed(getTable()); + + table->formatImpl(settings, state, frame); } formatOnCluster(settings); diff --git a/src/Parsers/ASTDropQuery.cpp b/src/Parsers/ASTDropQuery.cpp index ad1294c6e71..f41f28f745d 100644 --- a/src/Parsers/ASTDropQuery.cpp +++ b/src/Parsers/ASTDropQuery.cpp @@ -32,7 +32,7 @@ ASTPtr ASTDropQuery::clone() const return res; } -void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const +void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const { settings.ostr << (settings.hilite ? hilite_keyword : ""); if (kind == ASTDropQuery::Kind::Drop) @@ -47,7 +47,6 @@ void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState if (temporary) settings.ostr << "TEMPORARY "; - if (!table && database) settings.ostr << "DATABASE "; else if (is_dictionary) @@ -66,9 +65,19 @@ void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState settings.ostr << (settings.hilite ? hilite_none : ""); if (!table && database) - settings.ostr << backQuoteIfNeed(getDatabase()); + { + database->formatImpl(settings, state, frame); + } else - settings.ostr << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable()); + { + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); + } formatOnCluster(settings); diff --git a/src/Parsers/ASTInsertQuery.cpp b/src/Parsers/ASTInsertQuery.cpp index 88e087dd4ee..eb4bcce6578 100644 --- a/src/Parsers/ASTInsertQuery.cpp +++ b/src/Parsers/ASTInsertQuery.cpp @@ -68,8 +68,13 @@ void ASTInsertQuery::formatImpl(const FormatSettings & settings, FormatState & s } else { - settings.ostr << (settings.hilite ? hilite_none : "") - << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable()); + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); } if (columns) diff --git a/src/Parsers/ASTOptimizeQuery.cpp b/src/Parsers/ASTOptimizeQuery.cpp index 173310f7930..d9406a9eca0 100644 --- a/src/Parsers/ASTOptimizeQuery.cpp +++ b/src/Parsers/ASTOptimizeQuery.cpp @@ -7,8 +7,15 @@ namespace DB void ASTOptimizeQuery::formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const { - settings.ostr << (settings.hilite ? hilite_keyword : "") << "OPTIMIZE TABLE " << (settings.hilite ? hilite_none : "") - << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable()); + settings.ostr << (settings.hilite ? hilite_keyword : "") << "OPTIMIZE TABLE " << (settings.hilite ? hilite_none : ""); + + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); formatOnCluster(settings); diff --git a/src/Parsers/ASTQueryWithTableAndOutput.cpp b/src/Parsers/ASTQueryWithTableAndOutput.cpp index a216aeaa11f..85bfe2ae80f 100644 --- a/src/Parsers/ASTQueryWithTableAndOutput.cpp +++ b/src/Parsers/ASTQueryWithTableAndOutput.cpp @@ -64,11 +64,5 @@ void ASTQueryWithTableAndOutput::cloneTableOptions(ASTQueryWithTableAndOutput & cloned.children.push_back(cloned.table); } } -void ASTQueryWithTableAndOutput::formatHelper(const FormatSettings & settings, const char * name) const -{ - settings.ostr << (settings.hilite ? hilite_keyword : "") << name << " " << (settings.hilite ? hilite_none : ""); - settings.ostr << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable()); -} } - diff --git a/src/Parsers/ASTQueryWithTableAndOutput.h b/src/Parsers/ASTQueryWithTableAndOutput.h index 10f0e76f29c..1b8621fb63b 100644 --- a/src/Parsers/ASTQueryWithTableAndOutput.h +++ b/src/Parsers/ASTQueryWithTableAndOutput.h @@ -28,9 +28,6 @@ public: void setTable(const String & name); void cloneTableOptions(ASTQueryWithTableAndOutput & cloned) const; - -protected: - void formatHelper(const FormatSettings & settings, const char * name) const; }; @@ -52,9 +49,19 @@ public: QueryKind getQueryKind() const override { return QueryKind::Show; } protected: - void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override + void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override { - formatHelper(settings, temporary ? AstIDAndQueryNames::QueryTemporary : AstIDAndQueryNames::Query); + settings.ostr << (settings.hilite ? hilite_keyword : "") + << (temporary ? AstIDAndQueryNames::QueryTemporary : AstIDAndQueryNames::Query) + << " " << (settings.hilite ? hilite_none : ""); + + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); } }; diff --git a/src/Parsers/ASTUndropQuery.cpp b/src/Parsers/ASTUndropQuery.cpp index 0b8a18b12c9..9cc4f6682ec 100644 --- a/src/Parsers/ASTUndropQuery.cpp +++ b/src/Parsers/ASTUndropQuery.cpp @@ -19,18 +19,29 @@ ASTPtr ASTUndropQuery::clone() const return res; } -void ASTUndropQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const +void ASTUndropQuery::formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const { settings.ostr << (settings.hilite ? hilite_keyword : ""); settings.ostr << "UNDROP "; settings.ostr << "TABLE "; settings.ostr << (settings.hilite ? hilite_none : ""); - assert (table); + chassert(table); + if (!database) - settings.ostr << backQuoteIfNeed(getTable()); + { + database->formatImpl(settings, state, frame); + } else - settings.ostr << backQuoteIfNeed(getDatabase()) + "." << backQuoteIfNeed(getTable()); + { + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); + } if (uuid != UUIDHelpers::Nil) settings.ostr << (settings.hilite ? hilite_keyword : "") << " UUID " << (settings.hilite ? hilite_none : "") diff --git a/src/Parsers/ASTWatchQuery.h b/src/Parsers/ASTWatchQuery.h index 156fe6828bc..80b675f513f 100644 --- a/src/Parsers/ASTWatchQuery.h +++ b/src/Parsers/ASTWatchQuery.h @@ -40,22 +40,29 @@ public: QueryKind getQueryKind() const override { return QueryKind::Create; } protected: - void formatQueryImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override + void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override { - std::string indent_str = s.one_line ? "" : std::string(4 * frame.indent, ' '); + std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' '); - s.ostr << (s.hilite ? hilite_keyword : "") << "WATCH " << (s.hilite ? hilite_none : "") - << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable()); + settings.ostr << (settings.hilite ? hilite_keyword : "") << "WATCH " << (settings.hilite ? hilite_none : ""); + + if (database) + { + database->formatImpl(settings, state, frame); + settings.ostr << '.'; + } + + table->formatImpl(settings, state, frame); if (is_watch_events) { - s.ostr << " " << (s.hilite ? hilite_keyword : "") << "EVENTS" << (s.hilite ? hilite_none : ""); + settings.ostr << " " << (settings.hilite ? hilite_keyword : "") << "EVENTS" << (settings.hilite ? hilite_none : ""); } if (limit_length) { - s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "LIMIT " << (s.hilite ? hilite_none : ""); - limit_length->formatImpl(s, state, frame); + settings.ostr << (settings.hilite ? hilite_keyword : "") << settings.nl_or_ws << indent_str << "LIMIT " << (settings.hilite ? hilite_none : ""); + limit_length->formatImpl(settings, state, frame); } } };