2019-12-01 22:01:05 +00:00
|
|
|
#include <Parsers/ASTShowCreateAccessEntityQuery.h>
|
2020-05-30 14:18:08 +00:00
|
|
|
#include <Parsers/ASTRowPolicyName.h>
|
2019-12-01 22:01:05 +00:00
|
|
|
#include <Common/quoteString.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-05-30 14:18:08 +00:00
|
|
|
namespace
|
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
using EntityType = IAccessEntity::Type;
|
2020-05-30 14:18:08 +00:00
|
|
|
using EntityTypeInfo = IAccessEntity::TypeInfo;
|
|
|
|
|
|
|
|
void formatNames(const Strings & names, const IAST::FormatSettings & settings)
|
|
|
|
{
|
|
|
|
bool need_comma = false;
|
|
|
|
for (const auto & name : names)
|
|
|
|
{
|
|
|
|
if (std::exchange(need_comma, true))
|
|
|
|
settings.ostr << ',';
|
|
|
|
settings.ostr << ' ' << backQuoteIfNeed(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-01 22:01:05 +00:00
|
|
|
|
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
String ASTShowCreateAccessEntityQuery::getKeyword() const
|
|
|
|
{
|
|
|
|
size_t total_count = (names.size()) + (row_policy_names ? row_policy_names->size() : 0) + current_user + current_quota;
|
|
|
|
bool multiple = (total_count != 1) || all || !short_name.empty() || database_and_table_name;
|
|
|
|
const auto & type_info = EntityTypeInfo::get(type);
|
|
|
|
return multiple ? type_info.plural_name : type_info.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-01 22:01:05 +00:00
|
|
|
String ASTShowCreateAccessEntityQuery::getID(char) const
|
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
return String("SHOW CREATE ") + getKeyword() + " query";
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ASTPtr ASTShowCreateAccessEntityQuery::clone() const
|
|
|
|
{
|
|
|
|
return std::make_shared<ASTShowCreateAccessEntityQuery>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ASTShowCreateAccessEntityQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const
|
|
|
|
{
|
2020-06-06 07:21:02 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SHOW CREATE " << getKeyword() << (settings.hilite ? hilite_none : "");
|
2019-12-01 22:01:05 +00:00
|
|
|
|
2020-06-06 07:21:02 +00:00
|
|
|
if (!names.empty())
|
|
|
|
formatNames(names, settings);
|
|
|
|
|
|
|
|
if (row_policy_names)
|
2019-11-29 17:22:56 +00:00
|
|
|
{
|
2020-05-30 14:18:08 +00:00
|
|
|
settings.ostr << " ";
|
|
|
|
row_policy_names->format(settings);
|
2019-11-29 17:22:56 +00:00
|
|
|
}
|
2020-06-06 07:21:02 +00:00
|
|
|
|
|
|
|
if (!short_name.empty())
|
|
|
|
settings.ostr << " " << backQuoteIfNeed(short_name);
|
|
|
|
|
|
|
|
if (database_and_table_name)
|
|
|
|
{
|
|
|
|
const String & database = database_and_table_name->first;
|
|
|
|
const String & table_name = database_and_table_name->second;
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " ON " << (settings.hilite ? hilite_none : "");
|
|
|
|
settings.ostr << (database.empty() ? "" : backQuoteIfNeed(database) + ".");
|
|
|
|
settings.ostr << (table_name.empty() ? "*" : backQuoteIfNeed(table_name));
|
|
|
|
}
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|
2020-05-30 14:18:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ASTShowCreateAccessEntityQuery::replaceEmptyDatabaseWithCurrent(const String & current_database)
|
|
|
|
{
|
|
|
|
if (row_policy_names)
|
|
|
|
row_policy_names->replaceEmptyDatabaseWithCurrent(current_database);
|
2020-06-06 07:21:02 +00:00
|
|
|
|
|
|
|
if (database_and_table_name)
|
|
|
|
{
|
|
|
|
String & database = database_and_table_name->first;
|
|
|
|
if (database.empty())
|
|
|
|
database = current_database;
|
|
|
|
}
|
2020-05-30 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 22:01:05 +00:00
|
|
|
}
|