2023-08-03 09:44:44 +00:00
|
|
|
#include <Interpreters/removeOnClusterClauseIfNeeded.h>
|
|
|
|
|
|
|
|
#include <Access/AccessControl.h>
|
|
|
|
#include <Access/ReplicatedAccessStorage.h>
|
|
|
|
#include <Common/logger_useful.h>
|
2023-12-12 14:03:49 +00:00
|
|
|
#include <Functions/UserDefined/IUserDefinedSQLObjectsStorage.h>
|
2023-08-03 09:44:44 +00:00
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Parsers/ASTCreateFunctionQuery.h>
|
|
|
|
#include <Parsers/ASTDropFunctionQuery.h>
|
|
|
|
#include <Parsers/ASTQueryWithOnCluster.h>
|
|
|
|
#include <Parsers/Access/ASTCreateQuotaQuery.h>
|
|
|
|
#include <Parsers/Access/ASTCreateRoleQuery.h>
|
|
|
|
#include <Parsers/Access/ASTCreateRowPolicyQuery.h>
|
|
|
|
#include <Parsers/Access/ASTCreateSettingsProfileQuery.h>
|
|
|
|
#include <Parsers/Access/ASTCreateUserQuery.h>
|
|
|
|
#include <Parsers/Access/ASTDropAccessEntityQuery.h>
|
2023-12-05 15:11:32 +00:00
|
|
|
#include <Parsers/Access/ASTGrantQuery.h>
|
2023-08-03 09:44:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
static bool isUserDefinedFunctionQuery(const ASTPtr & query)
|
|
|
|
{
|
|
|
|
return query->as<ASTCreateFunctionQuery>()
|
|
|
|
|| query->as<ASTDropFunctionQuery>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isAccessControlQuery(const ASTPtr & query)
|
|
|
|
{
|
|
|
|
return query->as<ASTCreateUserQuery>()
|
|
|
|
|| query->as<ASTCreateQuotaQuery>()
|
|
|
|
|| query->as<ASTCreateRoleQuery>()
|
|
|
|
|| query->as<ASTCreateRowPolicyQuery>()
|
|
|
|
|| query->as<ASTCreateSettingsProfileQuery>()
|
2023-12-05 15:11:32 +00:00
|
|
|
|| query->as<ASTDropAccessEntityQuery>()
|
|
|
|
|| query->as<ASTGrantQuery>();
|
2023-08-03 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ASTPtr removeOnClusterClauseIfNeeded(const ASTPtr & query, ContextPtr context, const WithoutOnClusterASTRewriteParams & params)
|
|
|
|
{
|
|
|
|
auto * query_on_cluster = dynamic_cast<ASTQueryWithOnCluster *>(query.get());
|
|
|
|
|
|
|
|
if (!query_on_cluster || query_on_cluster->cluster.empty())
|
|
|
|
return query;
|
|
|
|
|
|
|
|
if ((isUserDefinedFunctionQuery(query)
|
|
|
|
&& context->getSettings().ignore_on_cluster_for_replicated_udf_queries
|
2023-12-12 14:03:49 +00:00
|
|
|
&& context->getUserDefinedSQLObjectsStorage().isReplicated())
|
2023-08-03 09:44:44 +00:00
|
|
|
|| (isAccessControlQuery(query)
|
|
|
|
&& context->getSettings().ignore_on_cluster_for_replicated_access_entities_queries
|
|
|
|
&& context->getAccessControl().containsStorage(ReplicatedAccessStorage::STORAGE_TYPE)))
|
|
|
|
{
|
2024-01-23 17:04:50 +00:00
|
|
|
LOG_DEBUG(getLogger("removeOnClusterClauseIfNeeded"), "ON CLUSTER clause was ignored for query {}", query->getID());
|
2023-08-03 09:44:44 +00:00
|
|
|
return query_on_cluster->getRewrittenASTWithoutOnCluster(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
}
|