mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Merge pull request #55910 from ClickHouse/remove-cpp-templates
Remove C++ templates, because they are stupid
This commit is contained in:
commit
4351446373
@ -17,39 +17,46 @@ namespace
|
||||
{
|
||||
enum class Kind
|
||||
{
|
||||
CURRENT_PROFILES,
|
||||
ENABLED_PROFILES,
|
||||
DEFAULT_PROFILES,
|
||||
currentProfiles,
|
||||
enabledProfiles,
|
||||
defaultProfiles,
|
||||
};
|
||||
|
||||
template <Kind kind>
|
||||
class FunctionCurrentProfiles : public IFunction
|
||||
String toString(Kind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case Kind::currentProfiles: return "currentProfiles";
|
||||
case Kind::enabledProfiles: return "enabledProfiles";
|
||||
case Kind::defaultProfiles: return "defaultProfiles";
|
||||
}
|
||||
}
|
||||
|
||||
class FunctionProfiles : public IFunction
|
||||
{
|
||||
public:
|
||||
static constexpr auto name = (kind == Kind::CURRENT_PROFILES) ? "currentProfiles" : ((kind == Kind::ENABLED_PROFILES) ? "enabledProfiles" : "defaultProfiles");
|
||||
static FunctionPtr create(const ContextPtr & context) { return std::make_shared<FunctionCurrentProfiles>(context); }
|
||||
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return false; }
|
||||
String getName() const override
|
||||
{
|
||||
return toString(kind);
|
||||
}
|
||||
|
||||
String getName() const override { return name; }
|
||||
|
||||
explicit FunctionCurrentProfiles(const ContextPtr & context)
|
||||
explicit FunctionProfiles(const ContextPtr & context, Kind kind_)
|
||||
: kind(kind_)
|
||||
{
|
||||
const auto & manager = context->getAccessControl();
|
||||
|
||||
std::vector<UUID> profile_ids;
|
||||
if constexpr (kind == Kind::CURRENT_PROFILES)
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
profile_ids = context->getCurrentProfiles();
|
||||
}
|
||||
else if constexpr (kind == Kind::ENABLED_PROFILES)
|
||||
{
|
||||
profile_ids = context->getEnabledProfiles();
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(kind == Kind::DEFAULT_PROFILES);
|
||||
profile_ids = context->getUser()->settings.toProfileIDs();
|
||||
case Kind::currentProfiles: profile_ids = context->getCurrentProfiles(); break;
|
||||
case Kind::enabledProfiles: profile_ids = context->getEnabledProfiles(); break;
|
||||
case Kind::defaultProfiles: profile_ids = context->getUser()->settings.toProfileIDs(); break;
|
||||
}
|
||||
|
||||
profile_names = manager.tryReadNames(profile_ids);
|
||||
@ -75,15 +82,16 @@ namespace
|
||||
}
|
||||
|
||||
private:
|
||||
Kind kind;
|
||||
Strings profile_names;
|
||||
};
|
||||
}
|
||||
|
||||
REGISTER_FUNCTION(CurrentProfiles)
|
||||
REGISTER_FUNCTION(Profiles)
|
||||
{
|
||||
factory.registerFunction<FunctionCurrentProfiles<Kind::CURRENT_PROFILES>>();
|
||||
factory.registerFunction<FunctionCurrentProfiles<Kind::ENABLED_PROFILES>>();
|
||||
factory.registerFunction<FunctionCurrentProfiles<Kind::DEFAULT_PROFILES>>();
|
||||
factory.registerFunction("currentProfiles", [](ContextPtr context){ return std::make_unique<FunctionToOverloadResolverAdaptor>(std::make_shared<FunctionProfiles>(context, Kind::currentProfiles)); });
|
||||
factory.registerFunction("enabledProfiles", [](ContextPtr context){ return std::make_unique<FunctionToOverloadResolverAdaptor>(std::make_shared<FunctionProfiles>(context, Kind::enabledProfiles)); });
|
||||
factory.registerFunction("defaultProfiles", [](ContextPtr context){ return std::make_unique<FunctionToOverloadResolverAdaptor>(std::make_shared<FunctionProfiles>(context, Kind::defaultProfiles)); });
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user