mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
New function currentUser() implemented
This commit is contained in:
parent
8b9284be24
commit
e227611f01
54
dbms/src/Functions/currentUser.cpp
Normal file
54
dbms/src/Functions/currentUser.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include <Functions/IFunction.h>
|
||||
#include <Functions/FunctionFactory.h>
|
||||
#include <Interpreters/Context.h>
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class FunctionCurrentUser : public IFunction
|
||||
{
|
||||
const String user_name;
|
||||
|
||||
public:
|
||||
static constexpr auto name = "currentUser";
|
||||
static FunctionPtr create(const Context & context)
|
||||
{
|
||||
return std::make_shared<FunctionCurrentUser>(context.getClientInfo().current_user);
|
||||
}
|
||||
|
||||
explicit FunctionCurrentUser(const String & user_name_) : user_name{user_name_}
|
||||
{
|
||||
}
|
||||
|
||||
String getName() const override
|
||||
{
|
||||
return name;
|
||||
}
|
||||
size_t getNumberOfArguments() const override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
DataTypePtr getReturnTypeImpl(const DataTypes & /*arguments*/) const override
|
||||
{
|
||||
return std::make_shared<DataTypeString>();
|
||||
}
|
||||
|
||||
bool isDeterministic() const override { return false; }
|
||||
|
||||
void executeImpl(Block & block, const ColumnNumbers &, size_t result, size_t input_rows_count) override
|
||||
{
|
||||
block.getByPosition(result).column = DataTypeString().createColumnConst(input_rows_count, user_name);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void registerFunctionCurrentUser(FunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction<FunctionCurrentUser>();
|
||||
factory.registerAlias("user", FunctionCurrentUser::name, FunctionFactory::CaseSensitive);
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ namespace DB
|
||||
class FunctionFactory;
|
||||
|
||||
void registerFunctionCurrentDatabase(FunctionFactory &);
|
||||
void registerFunctionCurrentUser(FunctionFactory &);
|
||||
void registerFunctionHostName(FunctionFactory &);
|
||||
void registerFunctionVisibleWidth(FunctionFactory &);
|
||||
void registerFunctionToTypeName(FunctionFactory &);
|
||||
@ -56,6 +57,7 @@ void registerFunctionConvertCharset(FunctionFactory &);
|
||||
void registerFunctionsMiscellaneous(FunctionFactory & factory)
|
||||
{
|
||||
registerFunctionCurrentDatabase(factory);
|
||||
registerFunctionCurrentUser(factory);
|
||||
registerFunctionHostName(factory);
|
||||
registerFunctionVisibleWidth(factory);
|
||||
registerFunctionToTypeName(factory);
|
||||
|
@ -0,0 +1,3 @@
|
||||
1
|
||||
1
|
||||
1
|
@ -0,0 +1,4 @@
|
||||
-- since actual user name is unknown, have to perform just smoke tests
|
||||
select currentUser() IS NOT NULL;
|
||||
select length(currentUser()) > 0;
|
||||
select currentUser() = user();
|
Loading…
Reference in New Issue
Block a user