mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Rename row policy's 'name' to 'short_name', 'full_name' to 'name'.
This change simplifies the interface of IAccesEntity.
This commit is contained in:
parent
6f15a0d443
commit
b6fe726777
@ -525,7 +525,7 @@ bool DiskAccessStorage::rebuildLists()
|
||||
|
||||
auto type = entity->getType();
|
||||
auto & name_to_id_map = name_to_id_maps.at(type);
|
||||
auto it_by_name = name_to_id_map.emplace(entity->getFullName(), id).first;
|
||||
auto it_by_name = name_to_id_map.emplace(entity->getName(), id).first;
|
||||
id_to_entry_map.emplace(id, Entry{it_by_name->first, type});
|
||||
}
|
||||
|
||||
@ -609,7 +609,7 @@ UUID DiskAccessStorage::insertImpl(const AccessEntityPtr & new_entity, bool repl
|
||||
|
||||
void DiskAccessStorage::insertNoLock(const UUID & id, const AccessEntityPtr & new_entity, bool replace_if_exists, Notifications & notifications)
|
||||
{
|
||||
const String & name = new_entity->getFullName();
|
||||
const String & name = new_entity->getName();
|
||||
std::type_index type = new_entity->getType();
|
||||
if (!initialized)
|
||||
throw Exception(
|
||||
@ -622,7 +622,7 @@ void DiskAccessStorage::insertNoLock(const UUID & id, const AccessEntityPtr & ne
|
||||
if (it_by_id != id_to_entry_map.end())
|
||||
{
|
||||
const auto & existing_entry = it_by_id->second;
|
||||
throwIDCollisionCannotInsert(id, type, name, existing_entry.entity->getType(), existing_entry.entity->getFullName());
|
||||
throwIDCollisionCannotInsert(id, type, name, existing_entry.entity->getType(), existing_entry.entity->getName());
|
||||
}
|
||||
|
||||
auto & name_to_id_map = name_to_id_maps.at(type);
|
||||
@ -703,7 +703,7 @@ void DiskAccessStorage::updateNoLock(const UUID & id, const UpdateFunc & update_
|
||||
if (*new_entity == *old_entity)
|
||||
return;
|
||||
|
||||
String new_name = new_entity->getFullName();
|
||||
String new_name = new_entity->getName();
|
||||
auto old_name = entry.name;
|
||||
const std::type_index type = entry.type;
|
||||
bool name_changed = (new_name != old_name);
|
||||
|
@ -43,6 +43,6 @@ const char * IAccessEntity::getKeyword(std::type_index type)
|
||||
|
||||
bool IAccessEntity::equal(const IAccessEntity & other) const
|
||||
{
|
||||
return (full_name == other.full_name) && (getType() == other.getType());
|
||||
return (name == other.name) && (getType() == other.getType());
|
||||
}
|
||||
}
|
||||
|
@ -27,15 +27,14 @@ struct IAccessEntity
|
||||
bool isTypeOf() const { return isTypeOf(typeid(EntityType)); }
|
||||
bool isTypeOf(std::type_index type) const { return type == getType(); }
|
||||
|
||||
virtual void setName(const String & name_) { full_name = name_; }
|
||||
virtual String getName() const { return full_name; }
|
||||
String getFullName() const { return full_name; }
|
||||
virtual void setName(const String & name_) { name = name_; }
|
||||
const String & getName() const { return name; }
|
||||
|
||||
friend bool operator ==(const IAccessEntity & lhs, const IAccessEntity & rhs) { return lhs.equal(rhs); }
|
||||
friend bool operator !=(const IAccessEntity & lhs, const IAccessEntity & rhs) { return !(lhs == rhs); }
|
||||
|
||||
protected:
|
||||
String full_name;
|
||||
String name;
|
||||
|
||||
virtual bool equal(const IAccessEntity & other) const;
|
||||
|
||||
|
@ -179,7 +179,7 @@ std::shared_ptr<const EntityType> IAccessStorage::read(const UUID & id) const
|
||||
auto ptr = typeid_cast<std::shared_ptr<const EntityType>>(entity);
|
||||
if (ptr)
|
||||
return ptr;
|
||||
throwBadCast(id, entity->getType(), entity->getFullName(), typeid(EntityType));
|
||||
throwBadCast(id, entity->getType(), entity->getName(), typeid(EntityType));
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ AccessEntityPtr MemoryAccessStorage::readImpl(const UUID & id) const
|
||||
|
||||
String MemoryAccessStorage::readNameImpl(const UUID & id) const
|
||||
{
|
||||
return readImpl(id)->getFullName();
|
||||
return readImpl(id)->getName();
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@ UUID MemoryAccessStorage::insertImpl(const AccessEntityPtr & new_entity, bool re
|
||||
|
||||
void MemoryAccessStorage::insertNoLock(const UUID & id, const AccessEntityPtr & new_entity, bool replace_if_exists, Notifications & notifications)
|
||||
{
|
||||
const String & name = new_entity->getFullName();
|
||||
const String & name = new_entity->getName();
|
||||
std::type_index type = new_entity->getType();
|
||||
|
||||
/// Check that we can insert.
|
||||
@ -81,7 +81,7 @@ void MemoryAccessStorage::insertNoLock(const UUID & id, const AccessEntityPtr &
|
||||
if (it != entries.end())
|
||||
{
|
||||
const auto & existing_entry = it->second;
|
||||
throwIDCollisionCannotInsert(id, type, name, existing_entry.entity->getType(), existing_entry.entity->getFullName());
|
||||
throwIDCollisionCannotInsert(id, type, name, existing_entry.entity->getType(), existing_entry.entity->getName());
|
||||
}
|
||||
|
||||
auto it2 = names.find({name, type});
|
||||
@ -120,7 +120,7 @@ void MemoryAccessStorage::removeNoLock(const UUID & id, Notifications & notifica
|
||||
throwNotFound(id);
|
||||
|
||||
Entry & entry = it->second;
|
||||
const String & name = entry.entity->getFullName();
|
||||
const String & name = entry.entity->getName();
|
||||
std::type_index type = entry.entity->getType();
|
||||
|
||||
prepareNotifications(entry, true, notifications);
|
||||
@ -156,14 +156,14 @@ void MemoryAccessStorage::updateNoLock(const UUID & id, const UpdateFunc & updat
|
||||
|
||||
entry.entity = new_entity;
|
||||
|
||||
if (new_entity->getFullName() != old_entity->getFullName())
|
||||
if (new_entity->getName() != old_entity->getName())
|
||||
{
|
||||
auto it2 = names.find({new_entity->getFullName(), new_entity->getType()});
|
||||
auto it2 = names.find({new_entity->getName(), new_entity->getType()});
|
||||
if (it2 != names.end())
|
||||
throwNameCollisionCannotRename(old_entity->getType(), old_entity->getFullName(), new_entity->getFullName());
|
||||
throwNameCollisionCannotRename(old_entity->getType(), old_entity->getName(), new_entity->getName());
|
||||
|
||||
names.erase({old_entity->getFullName(), old_entity->getType()});
|
||||
names[std::pair{new_entity->getFullName(), new_entity->getType()}] = &entry;
|
||||
names.erase({old_entity->getName(), old_entity->getType()});
|
||||
names[std::pair{new_entity->getName(), new_entity->getType()}] = &entry;
|
||||
}
|
||||
|
||||
prepareNotifications(entry, false, notifications);
|
||||
@ -211,7 +211,7 @@ void MemoryAccessStorage::setAllNoLock(const std::vector<std::pair<UUID, AccessE
|
||||
continue;
|
||||
}
|
||||
}
|
||||
auto it2 = names.find({entity->getFullName(), entity->getType()});
|
||||
auto it2 = names.find({entity->getName(), entity->getType()});
|
||||
if (it2 != names.end())
|
||||
{
|
||||
Entry & entry = *(it2->second);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <Access/RowPolicy.h>
|
||||
#include <Interpreters/Context.h>
|
||||
#include <Common/quoteString.h>
|
||||
#include <boost/range/algorithm/equal.hpp>
|
||||
|
||||
@ -8,71 +7,62 @@ namespace DB
|
||||
{
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int NOT_IMPLEMENTED;
|
||||
extern const int LOGICAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
String RowPolicy::NameParts::getName() const
|
||||
{
|
||||
void generateFullNameImpl(const String & database_, const String & table_name_, const String & policy_name_, String & full_name_)
|
||||
String name;
|
||||
name.reserve(database.length() + table_name.length() + short_name.length() + 6);
|
||||
name += backQuoteIfNeed(short_name);
|
||||
name += " ON ";
|
||||
if (!name.empty())
|
||||
{
|
||||
full_name_.clear();
|
||||
full_name_.reserve(database_.length() + table_name_.length() + policy_name_.length() + 6);
|
||||
full_name_ += backQuoteIfNeed(policy_name_);
|
||||
full_name_ += " ON ";
|
||||
if (!database_.empty())
|
||||
{
|
||||
full_name_ += backQuoteIfNeed(database_);
|
||||
full_name_ += '.';
|
||||
}
|
||||
full_name_ += backQuoteIfNeed(table_name_);
|
||||
name += backQuoteIfNeed(database);
|
||||
name += '.';
|
||||
}
|
||||
name += backQuoteIfNeed(table_name);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
String RowPolicy::FullNameParts::getFullName() const
|
||||
void RowPolicy::setDatabase(const String & database)
|
||||
{
|
||||
String full_name;
|
||||
generateFullNameImpl(database, table_name, policy_name, full_name);
|
||||
return full_name;
|
||||
name_parts.database = database;
|
||||
IAccessEntity::setName(name_parts.getName());
|
||||
}
|
||||
|
||||
|
||||
String RowPolicy::FullNameParts::getFullName(const Context & context) const
|
||||
void RowPolicy::setTableName(const String & table_name)
|
||||
{
|
||||
String full_name;
|
||||
generateFullNameImpl(database.empty() ? context.getCurrentDatabase() : database, table_name, policy_name, full_name);
|
||||
return full_name;
|
||||
name_parts.table_name = table_name;
|
||||
IAccessEntity::setName(name_parts.getName());
|
||||
}
|
||||
|
||||
|
||||
void RowPolicy::setDatabase(const String & database_)
|
||||
void RowPolicy::setShortName(const String & short_name)
|
||||
{
|
||||
database = database_;
|
||||
generateFullNameImpl(database, table_name, policy_name, full_name);
|
||||
name_parts.short_name = short_name;
|
||||
IAccessEntity::setName(name_parts.getName());
|
||||
}
|
||||
|
||||
|
||||
void RowPolicy::setTableName(const String & table_name_)
|
||||
void RowPolicy::setNameParts(const String & short_name, const String & database, const String & table_name)
|
||||
{
|
||||
table_name = table_name_;
|
||||
generateFullNameImpl(database, table_name, policy_name, full_name);
|
||||
name_parts.short_name = short_name;
|
||||
name_parts.database = database;
|
||||
name_parts.table_name = table_name;
|
||||
IAccessEntity::setName(name_parts.getName());
|
||||
}
|
||||
|
||||
|
||||
void RowPolicy::setName(const String & policy_name_)
|
||||
void RowPolicy::setNameParts(const NameParts & name_parts_)
|
||||
{
|
||||
policy_name = policy_name_;
|
||||
generateFullNameImpl(database, table_name, policy_name, full_name);
|
||||
name_parts = name_parts_;
|
||||
IAccessEntity::setName(name_parts.getName());
|
||||
}
|
||||
|
||||
|
||||
void RowPolicy::setFullName(const String & database_, const String & table_name_, const String & policy_name_)
|
||||
void RowPolicy::setName(const String &)
|
||||
{
|
||||
database = database_;
|
||||
table_name = table_name_;
|
||||
policy_name = policy_name_;
|
||||
generateFullNameImpl(database, table_name, policy_name, full_name);
|
||||
throw Exception("RowPolicy::setName() is not implemented", ErrorCodes::NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
|
||||
@ -81,9 +71,8 @@ bool RowPolicy::equal(const IAccessEntity & other) const
|
||||
if (!IAccessEntity::equal(other))
|
||||
return false;
|
||||
const auto & other_policy = typeid_cast<const RowPolicy &>(other);
|
||||
return (database == other_policy.database) && (table_name == other_policy.table_name) && (policy_name == other_policy.policy_name)
|
||||
&& boost::range::equal(conditions, other_policy.conditions) && restrictive == other_policy.restrictive
|
||||
&& (to_roles == other_policy.to_roles);
|
||||
return (name_parts == other_policy.name_parts) && boost::range::equal(conditions, other_policy.conditions)
|
||||
&& restrictive == other_policy.restrictive && (to_roles == other_policy.to_roles);
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,31 +6,34 @@
|
||||
|
||||
namespace DB
|
||||
{
|
||||
class Context;
|
||||
|
||||
|
||||
/** Represents a row level security policy for a table.
|
||||
*/
|
||||
struct RowPolicy : public IAccessEntity
|
||||
{
|
||||
void setDatabase(const String & database_);
|
||||
void setTableName(const String & table_name_);
|
||||
void setName(const String & policy_name_) override;
|
||||
void setFullName(const String & database_, const String & table_name_, const String & policy_name_);
|
||||
|
||||
String getDatabase() const { return database; }
|
||||
String getTableName() const { return table_name; }
|
||||
String getName() const override { return policy_name; }
|
||||
|
||||
struct FullNameParts
|
||||
struct NameParts
|
||||
{
|
||||
String short_name;
|
||||
String database;
|
||||
String table_name;
|
||||
String policy_name;
|
||||
String getFullName() const;
|
||||
String getFullName(const Context & context) const;
|
||||
|
||||
String getName() const;
|
||||
auto toTuple() const { return std::tie(short_name, database, table_name); }
|
||||
friend bool operator ==(const NameParts & left, const NameParts & right) { return left.toTuple() == right.toTuple(); }
|
||||
friend bool operator !=(const NameParts & left, const NameParts & right) { return left.toTuple() != right.toTuple(); }
|
||||
};
|
||||
|
||||
void setShortName(const String & short_name);
|
||||
void setDatabase(const String & database);
|
||||
void setTableName(const String & table_name);
|
||||
void setNameParts(const String & short_name, const String & database, const String & table_name);
|
||||
void setNameParts(const NameParts & name_parts);
|
||||
|
||||
const String & getDatabase() const { return name_parts.database; }
|
||||
const String & getTableName() const { return name_parts.table_name; }
|
||||
const String & getShortName() const { return name_parts.short_name; }
|
||||
const NameParts & getNameParts() const { return name_parts; }
|
||||
|
||||
/// Filter is a SQL conditional expression used to figure out which rows should be visible
|
||||
/// for user or available for modification. If the expression returns NULL or false for some rows
|
||||
/// those rows are silently suppressed.
|
||||
@ -71,9 +74,9 @@ struct RowPolicy : public IAccessEntity
|
||||
ExtendedRoleSet to_roles;
|
||||
|
||||
private:
|
||||
String database;
|
||||
String table_name;
|
||||
String policy_name;
|
||||
void setName(const String & name_) override;
|
||||
|
||||
NameParts name_parts;
|
||||
bool restrictive = false;
|
||||
};
|
||||
|
||||
|
@ -85,7 +85,7 @@ void RowPolicyCache::PolicyInfo::setPolicy(const RowPolicyPtr & policy_)
|
||||
tryLogCurrentException(
|
||||
&Poco::Logger::get("RowPolicy"),
|
||||
String("Could not parse the condition ") + RowPolicy::conditionTypeToString(type) + " of row policy "
|
||||
+ backQuote(policy->getFullName()));
|
||||
+ backQuote(policy->getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ namespace
|
||||
}
|
||||
|
||||
|
||||
UUID generateID(const IAccessEntity & entity) { return generateID(entity.getType(), entity.getFullName()); }
|
||||
UUID generateID(const IAccessEntity & entity) { return generateID(entity.getType(), entity.getName()); }
|
||||
|
||||
UserPtr parseUser(const Poco::Util::AbstractConfiguration & config, const String & user_name)
|
||||
{
|
||||
@ -344,7 +344,7 @@ namespace
|
||||
String filter = (it != user_to_filters.end()) ? it->second : "1";
|
||||
|
||||
auto policy = std::make_shared<RowPolicy>();
|
||||
policy->setFullName(database, table_name, user_name);
|
||||
policy->setNameParts(user_name, database, table_name);
|
||||
policy->conditions[RowPolicy::SELECT_FILTER] = filter;
|
||||
policy->to_roles.add(generateID(typeid(User), user_name));
|
||||
policies.push_back(policy);
|
||||
@ -494,21 +494,21 @@ String UsersConfigAccessStorage::readNameImpl(const UUID & id) const
|
||||
|
||||
UUID UsersConfigAccessStorage::insertImpl(const AccessEntityPtr & entity, bool)
|
||||
{
|
||||
throwReadonlyCannotInsert(entity->getType(), entity->getFullName());
|
||||
throwReadonlyCannotInsert(entity->getType(), entity->getName());
|
||||
}
|
||||
|
||||
|
||||
void UsersConfigAccessStorage::removeImpl(const UUID & id)
|
||||
{
|
||||
auto entity = read(id);
|
||||
throwReadonlyCannotRemove(entity->getType(), entity->getFullName());
|
||||
throwReadonlyCannotRemove(entity->getType(), entity->getName());
|
||||
}
|
||||
|
||||
|
||||
void UsersConfigAccessStorage::updateImpl(const UUID & id, const UpdateFunc &)
|
||||
{
|
||||
auto entity = read(id);
|
||||
throwReadonlyCannotUpdate(entity->getType(), entity->getFullName());
|
||||
throwReadonlyCannotUpdate(entity->getType(), entity->getName());
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
{
|
||||
const String database = policy->getDatabase();
|
||||
const String table_name = policy->getTableName();
|
||||
const String policy_name = policy->getName();
|
||||
const String policy_name = policy->getShortName();
|
||||
database_column->insertData(database.data(), database.length());
|
||||
table_name_column->insertData(table_name.data(), table_name.length());
|
||||
policy_name_column->insertData(policy_name.data(), policy_name.length());
|
||||
@ -123,7 +123,7 @@ public:
|
||||
const auto policy = context.getAccessControlManager().tryRead<RowPolicy>(policy_id);
|
||||
if (policy)
|
||||
{
|
||||
const String policy_name = policy->getName();
|
||||
const String policy_name = policy->getShortName();
|
||||
policy_name_column->insertData(policy_name.data(), policy_name.length());
|
||||
}
|
||||
}
|
||||
|
@ -11,37 +11,20 @@
|
||||
|
||||
namespace DB
|
||||
{
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int LOGICAL_ERROR;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
const String & checkCurrentDatabase(const String & current_database)
|
||||
{
|
||||
if (current_database.empty())
|
||||
throw Exception("No current database", ErrorCodes::LOGICAL_ERROR);
|
||||
return current_database;
|
||||
}
|
||||
|
||||
void updateRowPolicyFromQueryImpl(
|
||||
RowPolicy & policy,
|
||||
const ASTCreateRowPolicyQuery & query,
|
||||
const std::optional<ExtendedRoleSet> & roles_from_query = {},
|
||||
const String & current_database = {})
|
||||
const std::optional<ExtendedRoleSet> & roles_from_query = {})
|
||||
{
|
||||
if (query.alter)
|
||||
{
|
||||
if (!query.new_policy_name.empty())
|
||||
policy.setName(query.new_policy_name);
|
||||
if (!query.new_short_name.empty())
|
||||
policy.setShortName(query.new_short_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
policy.setDatabase(!query.name_parts.database.empty() ? query.name_parts.database : checkCurrentDatabase(current_database));
|
||||
policy.setTableName(query.name_parts.table_name);
|
||||
policy.setName(query.name_parts.policy_name);
|
||||
}
|
||||
policy.setNameParts(query.name_parts);
|
||||
|
||||
if (query.is_restrictive)
|
||||
policy.setRestrictive(*query.is_restrictive);
|
||||
@ -78,29 +61,29 @@ BlockIO InterpreterCreateRowPolicyQuery::execute()
|
||||
if (query.roles)
|
||||
roles_from_query = ExtendedRoleSet{*query.roles, access_control, context.getUserID()};
|
||||
|
||||
const String current_database = context.getCurrentDatabase();
|
||||
if (query.name_parts.database.empty())
|
||||
query.name_parts.database = context.getCurrentDatabase();
|
||||
|
||||
if (query.alter)
|
||||
{
|
||||
auto update_func = [&](const AccessEntityPtr & entity) -> AccessEntityPtr
|
||||
{
|
||||
auto updated_policy = typeid_cast<std::shared_ptr<RowPolicy>>(entity->clone());
|
||||
updateRowPolicyFromQueryImpl(*updated_policy, query, roles_from_query, current_database);
|
||||
updateRowPolicyFromQueryImpl(*updated_policy, query, roles_from_query);
|
||||
return updated_policy;
|
||||
};
|
||||
String full_name = query.name_parts.getFullName(context);
|
||||
if (query.if_exists)
|
||||
{
|
||||
if (auto id = access_control.find<RowPolicy>(full_name))
|
||||
if (auto id = access_control.find<RowPolicy>(query.name_parts.getName()))
|
||||
access_control.tryUpdate(*id, update_func);
|
||||
}
|
||||
else
|
||||
access_control.update(access_control.getID<RowPolicy>(full_name), update_func);
|
||||
access_control.update(access_control.getID<RowPolicy>(query.name_parts.getName()), update_func);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto new_policy = std::make_shared<RowPolicy>();
|
||||
updateRowPolicyFromQueryImpl(*new_policy, query, roles_from_query, current_database);
|
||||
updateRowPolicyFromQueryImpl(*new_policy, query, roles_from_query);
|
||||
|
||||
if (query.if_not_exists)
|
||||
access_control.tryInsert(new_policy);
|
||||
|
@ -47,7 +47,7 @@ namespace
|
||||
|
||||
BlockIO InterpreterDropAccessEntityQuery::execute()
|
||||
{
|
||||
const auto & query = query_ptr->as<const ASTDropAccessEntityQuery &>();
|
||||
auto & query = query_ptr->as<ASTDropAccessEntityQuery &>();
|
||||
auto & access_control = context.getAccessControlManager();
|
||||
|
||||
std::type_index type = getType(query.kind);
|
||||
@ -58,14 +58,17 @@ BlockIO InterpreterDropAccessEntityQuery::execute()
|
||||
|
||||
if (query.kind == Kind::ROW_POLICY)
|
||||
{
|
||||
Strings full_names;
|
||||
boost::range::transform(
|
||||
query.row_policies_names, std::back_inserter(full_names),
|
||||
[this](const RowPolicy::FullNameParts & row_policy_name) { return row_policy_name.getFullName(context); });
|
||||
Strings names;
|
||||
for (auto & name_parts : query.row_policies_name_parts)
|
||||
{
|
||||
if (name_parts.database.empty())
|
||||
name_parts.database = context.getCurrentDatabase();
|
||||
names.emplace_back(name_parts.getName());
|
||||
}
|
||||
if (query.if_exists)
|
||||
access_control.tryRemove(access_control.find<RowPolicy>(full_names));
|
||||
access_control.tryRemove(access_control.find<RowPolicy>(names));
|
||||
else
|
||||
access_control.remove(access_control.getIDs<RowPolicy>(full_names));
|
||||
access_control.remove(access_control.getIDs<RowPolicy>(names));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ namespace
|
||||
bool attach_mode)
|
||||
{
|
||||
auto query = std::make_shared<ASTCreateRowPolicyQuery>();
|
||||
query->name_parts = RowPolicy::FullNameParts{policy.getDatabase(), policy.getTableName(), policy.getName()};
|
||||
query->name_parts = policy.getNameParts();
|
||||
query->attach = attach_mode;
|
||||
|
||||
if (policy.isRestrictive())
|
||||
@ -233,7 +233,7 @@ BlockIO InterpreterShowCreateAccessEntityQuery::execute()
|
||||
|
||||
BlockInputStreamPtr InterpreterShowCreateAccessEntityQuery::executeImpl()
|
||||
{
|
||||
const auto & show_query = query_ptr->as<ASTShowCreateAccessEntityQuery &>();
|
||||
auto & show_query = query_ptr->as<ASTShowCreateAccessEntityQuery &>();
|
||||
|
||||
/// Build a create query.
|
||||
ASTPtr create_query = getCreateQuery(show_query);
|
||||
@ -257,7 +257,7 @@ BlockInputStreamPtr InterpreterShowCreateAccessEntityQuery::executeImpl()
|
||||
}
|
||||
|
||||
|
||||
ASTPtr InterpreterShowCreateAccessEntityQuery::getCreateQuery(const ASTShowCreateAccessEntityQuery & show_query) const
|
||||
ASTPtr InterpreterShowCreateAccessEntityQuery::getCreateQuery(ASTShowCreateAccessEntityQuery & show_query) const
|
||||
{
|
||||
const auto & access_control = context.getAccessControlManager();
|
||||
context.checkAccess(getRequiredAccess());
|
||||
@ -277,7 +277,9 @@ ASTPtr InterpreterShowCreateAccessEntityQuery::getCreateQuery(const ASTShowCreat
|
||||
auto type = getType(show_query.kind);
|
||||
if (show_query.kind == Kind::ROW_POLICY)
|
||||
{
|
||||
RowPolicyPtr policy = access_control.read<RowPolicy>(show_query.row_policy_name.getFullName(context));
|
||||
if (show_query.row_policy_name_parts.database.empty())
|
||||
show_query.row_policy_name_parts.database = context.getCurrentDatabase();
|
||||
RowPolicyPtr policy = access_control.read<RowPolicy>(show_query.row_policy_name_parts.getName());
|
||||
return getCreateQueryImpl(*policy, &access_control, false);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
|
||||
private:
|
||||
BlockInputStreamPtr executeImpl();
|
||||
ASTPtr getCreateQuery(const ASTShowCreateAccessEntityQuery & show_query) const;
|
||||
ASTPtr getCreateQuery(ASTShowCreateAccessEntityQuery & show_query) const;
|
||||
AccessRightsElements getRequiredAccess() const;
|
||||
|
||||
ASTPtr query_ptr;
|
||||
|
@ -49,7 +49,7 @@ String InterpreterShowRowPoliciesQuery::getRewrittenQuery() const
|
||||
filter = "database = " + quoteString(database) + " AND table = " + quoteString(table_name);
|
||||
}
|
||||
|
||||
String expr = table_name.empty() ? "full_name" : "name";
|
||||
String expr = table_name.empty() ? "name" : "short_name";
|
||||
|
||||
return "SELECT " + expr + " AS " + backQuote(getResultDescription()) + " from system.row_policies"
|
||||
+ (filter.empty() ? "" : " WHERE " + filter) + " ORDER BY " + expr;
|
||||
|
@ -12,10 +12,10 @@ namespace
|
||||
{
|
||||
using ConditionType = RowPolicy::ConditionType;
|
||||
|
||||
void formatRenameTo(const String & new_policy_name, const IAST::FormatSettings & settings)
|
||||
void formatRenameTo(const String & new_short_name, const IAST::FormatSettings & settings)
|
||||
{
|
||||
settings.ostr << (settings.hilite ? IAST::hilite_keyword : "") << " RENAME TO " << (settings.hilite ? IAST::hilite_none : "")
|
||||
<< backQuote(new_policy_name);
|
||||
<< backQuote(new_short_name);
|
||||
}
|
||||
|
||||
|
||||
@ -153,14 +153,14 @@ void ASTCreateRowPolicyQuery::formatImpl(const FormatSettings & settings, Format
|
||||
|
||||
const String & database = name_parts.database;
|
||||
const String & table_name = name_parts.table_name;
|
||||
const String & policy_name = name_parts.policy_name;
|
||||
settings.ostr << " " << backQuoteIfNeed(policy_name) << (settings.hilite ? hilite_keyword : "") << " ON "
|
||||
const String & short_name = name_parts.short_name;
|
||||
settings.ostr << " " << backQuoteIfNeed(short_name) << (settings.hilite ? hilite_keyword : "") << " ON "
|
||||
<< (settings.hilite ? hilite_none : "") << (database.empty() ? String{} : backQuoteIfNeed(database) + ".") << table_name;
|
||||
|
||||
formatOnCluster(settings);
|
||||
|
||||
if (!new_policy_name.empty())
|
||||
formatRenameTo(new_policy_name, settings);
|
||||
if (!new_short_name.empty())
|
||||
formatRenameTo(new_short_name, settings);
|
||||
|
||||
if (is_restrictive)
|
||||
formatAsRestrictiveOrPermissive(*is_restrictive, settings);
|
||||
|
@ -36,8 +36,8 @@ public:
|
||||
bool if_not_exists = false;
|
||||
bool or_replace = false;
|
||||
|
||||
RowPolicy::FullNameParts name_parts;
|
||||
String new_policy_name;
|
||||
RowPolicy::NameParts name_parts;
|
||||
String new_short_name;
|
||||
|
||||
std::optional<bool> is_restrictive;
|
||||
using ConditionType = RowPolicy::ConditionType;
|
||||
|
@ -51,15 +51,15 @@ void ASTDropAccessEntityQuery::formatImpl(const FormatSettings & settings, Forma
|
||||
if (kind == Kind::ROW_POLICY)
|
||||
{
|
||||
bool need_comma = false;
|
||||
for (const auto & row_policy_name : row_policies_names)
|
||||
for (const auto & name_parts : row_policies_name_parts)
|
||||
{
|
||||
if (need_comma)
|
||||
settings.ostr << ',';
|
||||
need_comma = true;
|
||||
const String & database = row_policy_name.database;
|
||||
const String & table_name = row_policy_name.table_name;
|
||||
const String & policy_name = row_policy_name.policy_name;
|
||||
settings.ostr << ' ' << backQuoteIfNeed(policy_name) << (settings.hilite ? hilite_keyword : "") << " ON "
|
||||
const String & database = name_parts.database;
|
||||
const String & table_name = name_parts.table_name;
|
||||
const String & short_name = name_parts.short_name;
|
||||
settings.ostr << ' ' << backQuoteIfNeed(short_name) << (settings.hilite ? hilite_keyword : "") << " ON "
|
||||
<< (settings.hilite ? hilite_none : "") << (database.empty() ? String{} : backQuoteIfNeed(database) + ".")
|
||||
<< backQuoteIfNeed(table_name);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
const Kind kind;
|
||||
bool if_exists = false;
|
||||
Strings names;
|
||||
std::vector<RowPolicy::FullNameParts> row_policies_names;
|
||||
std::vector<RowPolicy::NameParts> row_policies_name_parts;
|
||||
|
||||
ASTDropAccessEntityQuery(Kind kind_);
|
||||
String getID(char) const override;
|
||||
|
@ -54,10 +54,10 @@ void ASTShowCreateAccessEntityQuery::formatQueryImpl(const FormatSettings & sett
|
||||
settings.ostr << (settings.hilite ? hilite_keyword : "") << " CURRENT" << (settings.hilite ? hilite_none : "");
|
||||
else if (kind == Kind::ROW_POLICY)
|
||||
{
|
||||
const String & database = row_policy_name.database;
|
||||
const String & table_name = row_policy_name.table_name;
|
||||
const String & policy_name = row_policy_name.policy_name;
|
||||
settings.ostr << ' ' << backQuoteIfNeed(policy_name) << (settings.hilite ? hilite_keyword : "") << " ON "
|
||||
const String & database = row_policy_name_parts.database;
|
||||
const String & table_name = row_policy_name_parts.table_name;
|
||||
const String & short_name = row_policy_name_parts.short_name;
|
||||
settings.ostr << ' ' << backQuoteIfNeed(short_name) << (settings.hilite ? hilite_keyword : "") << " ON "
|
||||
<< (settings.hilite ? hilite_none : "") << (database.empty() ? String{} : backQuoteIfNeed(database) + ".")
|
||||
<< backQuoteIfNeed(table_name);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
String name;
|
||||
bool current_quota = false;
|
||||
bool current_user = false;
|
||||
RowPolicy::FullNameParts row_policy_name;
|
||||
RowPolicy::NameParts row_policy_name_parts;
|
||||
|
||||
ASTShowCreateAccessEntityQuery(Kind kind_);
|
||||
String getID(char) const override;
|
||||
|
@ -21,14 +21,14 @@ namespace
|
||||
{
|
||||
using ConditionType = RowPolicy::ConditionType;
|
||||
|
||||
bool parseRenameTo(IParserBase::Pos & pos, Expected & expected, String & new_policy_name)
|
||||
bool parseRenameTo(IParserBase::Pos & pos, Expected & expected, String & new_short_name)
|
||||
{
|
||||
return IParserBase::wrapParseImpl(pos, [&]
|
||||
{
|
||||
if (!ParserKeyword{"RENAME TO"}.ignore(pos, expected))
|
||||
return false;
|
||||
|
||||
return parseIdentifierOrStringLiteral(pos, expected, new_policy_name);
|
||||
return parseIdentifierOrStringLiteral(pos, expected, new_short_name);
|
||||
});
|
||||
}
|
||||
|
||||
@ -246,22 +246,22 @@ bool ParserCreateRowPolicyQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
|
||||
or_replace = true;
|
||||
}
|
||||
|
||||
RowPolicy::FullNameParts name_parts;
|
||||
RowPolicy::NameParts name_parts;
|
||||
String & database = name_parts.database;
|
||||
String & table_name = name_parts.table_name;
|
||||
String & policy_name = name_parts.policy_name;
|
||||
if (!parseIdentifierOrStringLiteral(pos, expected, policy_name) || !ParserKeyword{"ON"}.ignore(pos, expected)
|
||||
String & short_name = name_parts.short_name;
|
||||
if (!parseIdentifierOrStringLiteral(pos, expected, short_name) || !ParserKeyword{"ON"}.ignore(pos, expected)
|
||||
|| !parseDatabaseAndTableName(pos, expected, database, table_name))
|
||||
return false;
|
||||
|
||||
String new_policy_name;
|
||||
String new_short_name;
|
||||
std::optional<bool> is_restrictive;
|
||||
std::vector<std::pair<ConditionType, ASTPtr>> conditions;
|
||||
String cluster;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (alter && new_policy_name.empty() && parseRenameTo(pos, expected, new_policy_name))
|
||||
if (alter && new_short_name.empty() && parseRenameTo(pos, expected, new_short_name))
|
||||
continue;
|
||||
|
||||
if (!is_restrictive && parseAsRestrictiveOrPermissive(pos, expected, is_restrictive))
|
||||
@ -292,7 +292,7 @@ bool ParserCreateRowPolicyQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
|
||||
query->or_replace = or_replace;
|
||||
query->cluster = std::move(cluster);
|
||||
query->name_parts = std::move(name_parts);
|
||||
query->new_policy_name = std::move(new_policy_name);
|
||||
query->new_short_name = std::move(new_short_name);
|
||||
query->is_restrictive = is_restrictive;
|
||||
query->conditions = std::move(conditions);
|
||||
query->roles = std::move(roles);
|
||||
|
@ -30,25 +30,25 @@ namespace
|
||||
});
|
||||
}
|
||||
|
||||
bool parseRowPolicyNames(IParserBase::Pos & pos, Expected & expected, std::vector<RowPolicy::FullNameParts> & names)
|
||||
bool parseRowPolicyNames(IParserBase::Pos & pos, Expected & expected, std::vector<RowPolicy::NameParts> & name_parts)
|
||||
{
|
||||
return IParserBase::wrapParseImpl(pos, [&]
|
||||
{
|
||||
std::vector<RowPolicy::FullNameParts> res_names;
|
||||
std::vector<RowPolicy::NameParts> res_name_parts;
|
||||
do
|
||||
{
|
||||
Strings policy_names;
|
||||
if (!parseNames(pos, expected, policy_names))
|
||||
Strings short_names;
|
||||
if (!parseNames(pos, expected, short_names))
|
||||
return false;
|
||||
String database, table_name;
|
||||
if (!ParserKeyword{"ON"}.ignore(pos, expected) || !parseDatabaseAndTableName(pos, expected, database, table_name))
|
||||
return false;
|
||||
for (const String & policy_name : policy_names)
|
||||
res_names.push_back({database, table_name, policy_name});
|
||||
for (String & short_name : short_names)
|
||||
res_name_parts.push_back({std::move(short_name), database, table_name});
|
||||
}
|
||||
while (ParserToken{TokenType::Comma}.ignore(pos, expected));
|
||||
|
||||
names = std::move(res_names);
|
||||
name_parts = std::move(res_name_parts);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@ -99,7 +99,7 @@ bool ParserDropAccessEntityQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
|
||||
if_exists = true;
|
||||
|
||||
Strings names;
|
||||
std::vector<RowPolicy::FullNameParts> row_policies_names;
|
||||
std::vector<RowPolicy::NameParts> row_policies_name_parts;
|
||||
|
||||
if ((kind == Kind::USER) || (kind == Kind::ROLE))
|
||||
{
|
||||
@ -108,7 +108,7 @@ bool ParserDropAccessEntityQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
|
||||
}
|
||||
else if (kind == Kind::ROW_POLICY)
|
||||
{
|
||||
if (!parseRowPolicyNames(pos, expected, row_policies_names))
|
||||
if (!parseRowPolicyNames(pos, expected, row_policies_name_parts))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -130,7 +130,7 @@ bool ParserDropAccessEntityQuery::parseImpl(Pos & pos, ASTPtr & node, Expected &
|
||||
query->if_exists = if_exists;
|
||||
query->cluster = std::move(cluster);
|
||||
query->names = std::move(names);
|
||||
query->row_policies_names = std::move(row_policies_names);
|
||||
query->row_policies_name_parts = std::move(row_policies_name_parts);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ bool ParserShowCreateAccessEntityQuery::parseImpl(Pos & pos, ASTPtr & node, Expe
|
||||
String name;
|
||||
bool current_quota = false;
|
||||
bool current_user = false;
|
||||
RowPolicy::FullNameParts row_policy_name;
|
||||
RowPolicy::NameParts row_policy_name_parts;
|
||||
|
||||
if (kind == Kind::USER)
|
||||
{
|
||||
@ -46,10 +46,10 @@ bool ParserShowCreateAccessEntityQuery::parseImpl(Pos & pos, ASTPtr & node, Expe
|
||||
}
|
||||
else if (kind == Kind::ROW_POLICY)
|
||||
{
|
||||
String & database = row_policy_name.database;
|
||||
String & table_name = row_policy_name.table_name;
|
||||
String & policy_name = row_policy_name.policy_name;
|
||||
if (!parseIdentifierOrStringLiteral(pos, expected, policy_name) || !ParserKeyword{"ON"}.ignore(pos, expected)
|
||||
String & database = row_policy_name_parts.database;
|
||||
String & table_name = row_policy_name_parts.table_name;
|
||||
String & short_name = row_policy_name_parts.short_name;
|
||||
if (!parseIdentifierOrStringLiteral(pos, expected, short_name) || !ParserKeyword{"ON"}.ignore(pos, expected)
|
||||
|| !parseDatabaseAndTableName(pos, expected, database, table_name))
|
||||
return false;
|
||||
}
|
||||
@ -82,7 +82,7 @@ bool ParserShowCreateAccessEntityQuery::parseImpl(Pos & pos, ASTPtr & node, Expe
|
||||
query->name = std::move(name);
|
||||
query->current_quota = current_quota;
|
||||
query->current_user = current_user;
|
||||
query->row_policy_name = std::move(row_policy_name);
|
||||
query->row_policy_name_parts = std::move(row_policy_name_parts);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ NamesAndTypesList StorageSystemRowPolicies::getNamesAndTypes()
|
||||
NamesAndTypesList names_and_types{
|
||||
{"database", std::make_shared<DataTypeString>()},
|
||||
{"table", std::make_shared<DataTypeString>()},
|
||||
{"short_name", std::make_shared<DataTypeString>()},
|
||||
{"name", std::make_shared<DataTypeString>()},
|
||||
{"full_name", std::make_shared<DataTypeString>()},
|
||||
{"id", std::make_shared<DataTypeUUID>()},
|
||||
{"source", std::make_shared<DataTypeString>()},
|
||||
{"restrictive", std::make_shared<DataTypeUInt8>()},
|
||||
@ -48,8 +48,8 @@ void StorageSystemRowPolicies::fillData(MutableColumns & res_columns, const Cont
|
||||
size_t i = 0;
|
||||
res_columns[i++]->insert(policy->getDatabase());
|
||||
res_columns[i++]->insert(policy->getTableName());
|
||||
res_columns[i++]->insert(policy->getShortName());
|
||||
res_columns[i++]->insert(policy->getName());
|
||||
res_columns[i++]->insert(policy->getFullName());
|
||||
res_columns[i++]->insert(id);
|
||||
res_columns[i++]->insert(storage ? storage->getStorageName() : "");
|
||||
res_columns[i++]->insert(policy->isRestrictive());
|
||||
|
Loading…
Reference in New Issue
Block a user