2019-06-29 16:58:32 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <Parsers/ASTShowTablesQuery.h>
|
2019-10-08 18:42:22 +00:00
|
|
|
#include <Common/quoteString.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2019-06-29 16:58:32 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ASTPtr ASTShowTablesQuery::clone() const
|
|
|
|
{
|
|
|
|
auto res = std::make_shared<ASTShowTablesQuery>(*this);
|
|
|
|
res->children.clear();
|
|
|
|
cloneOutputOptions(*res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-09-09 03:24:47 +00:00
|
|
|
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;
|
2020-09-09 03:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-06-29 16:58:32 +00:00
|
|
|
{
|
|
|
|
if (databases)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW DATABASES" << (settings.hilite ? hilite_none : "");
|
2020-09-09 03:24:47 +00:00
|
|
|
formatLike(settings);
|
|
|
|
formatLimit(settings, state, frame);
|
2020-09-07 02:54:59 +00:00
|
|
|
|
2019-06-29 16:58:32 +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 : "");
|
2020-09-09 03:24:47 +00:00
|
|
|
formatLike(settings);
|
|
|
|
formatLimit(settings, state, frame);
|
2020-07-05 15:57:59 +00:00
|
|
|
|
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);
|
|
|
|
}
|
2020-12-14 02:33:51 +00:00
|
|
|
else if (m_settings)
|
|
|
|
{
|
2020-12-15 06:44:39 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW " << (changed ? "CHANGED " : "") << "SETTINGS" <<
|
|
|
|
(settings.hilite ? hilite_none : "");
|
2020-12-14 02:33:51 +00:00
|
|
|
formatLike(settings);
|
|
|
|
}
|
2019-06-29 16:58:32 +00:00
|
|
|
else
|
|
|
|
{
|
2019-10-11 13:21:52 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW " << (temporary ? "TEMPORARY " : "") <<
|
|
|
|
(dictionaries ? "DICTIONARIES" : "TABLES") << (settings.hilite ? hilite_none : "");
|
2019-06-29 16:58:32 +00:00
|
|
|
|
|
|
|
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);
|
2020-07-05 15:57:59 +00:00
|
|
|
|
2020-09-09 03:24:47 +00:00
|
|
|
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);
|
2019-06-29 16:58:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|