ClickHouse/src/Parsers/ASTShowTablesQuery.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
3.0 KiB
C++
Raw Normal View History

#include <iomanip>
#include <Parsers/ASTShowTablesQuery.h>
#include <Common/quoteString.h>
2020-11-09 16:05:40 +00:00
#include <IO/Operators.h>
namespace DB
{
ASTPtr ASTShowTablesQuery::clone() const
{
auto res = std::make_shared<ASTShowTablesQuery>(*this);
res->children.clear();
cloneOutputOptions(*res);
return res;
}
void ASTShowTablesQuery::formatLike(const FormatSettings & settings) const
{
if (!like.empty())
settings.ostr
<< (settings.hilite ? hilite_keyword : "")
<< (not_like ? " NOT" : "")
<< (case_insensitive_like ? " ILIKE " : " LIKE ")
<< (settings.hilite ? hilite_none : "")
2020-11-09 16:05:40 +00:00
<< DB::quote << like;
}
void ASTShowTablesQuery::formatLimit(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
if (limit_length)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << " LIMIT " << (settings.hilite ? hilite_none : "");
limit_length->formatImpl(settings, state, frame);
}
}
2019-09-15 16:07:27 +00:00
void ASTShowTablesQuery::formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
if (databases)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW DATABASES" << (settings.hilite ? hilite_none : "");
formatLike(settings);
formatLimit(settings, state, frame);
2020-09-07 02:54:59 +00:00
}
2020-06-05 09:13:13 +00:00
else if (clusters)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW CLUSTERS" << (settings.hilite ? hilite_none : "");
formatLike(settings);
formatLimit(settings, state, frame);
2020-06-05 09:13:13 +00:00
}
else if (cluster)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW CLUSTER" << (settings.hilite ? hilite_none : "");
2020-06-08 02:23:57 +00:00
settings.ostr << " " << backQuoteIfNeed(cluster_str);
2020-06-05 09:13:13 +00:00
}
2022-06-23 15:46:27 +00:00
else if (caches)
{
2022-09-19 12:02:51 +00:00
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW FILESYSTEM CACHES" << (settings.hilite ? hilite_none : "");
2022-06-23 15:46:27 +00:00
formatLike(settings);
formatLimit(settings, state, frame);
}
else if (m_settings)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW " << (changed ? "CHANGED " : "") << "SETTINGS" <<
(settings.hilite ? hilite_none : "");
formatLike(settings);
}
else
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW " << (temporary ? "TEMPORARY " : "") <<
(dictionaries ? "DICTIONARIES" : "TABLES") << (settings.hilite ? hilite_none : "");
if (!from.empty())
settings.ostr << (settings.hilite ? hilite_keyword : "") << " FROM " << (settings.hilite ? hilite_none : "")
<< backQuoteIfNeed(from);
2020-09-10 03:03:35 +00:00
formatLike(settings);
if (where_expression)
2020-02-11 11:35:30 +00:00
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << " WHERE " << (settings.hilite ? hilite_none : "");
where_expression->formatImpl(settings, state, frame);
}
2019-09-15 16:07:27 +00:00
2020-09-10 03:03:35 +00:00
formatLimit(settings, state, frame);
}
}
}