mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Merge pull request #6470 from alex-krash/function_user
Function currentUser()
This commit is contained in:
commit
7a439e269f
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().initial_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::CaseInsensitive);
|
||||
}
|
||||
|
||||
}
|
@ -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,4 @@
|
||||
1
|
||||
1
|
||||
1 1
|
||||
1
|
@ -0,0 +1,5 @@
|
||||
-- since actual user name is unknown, have to perform just smoke tests
|
||||
select currentUser() IS NOT NULL;
|
||||
select length(currentUser()) > 0;
|
||||
select currentUser() = user(), currentUser() = USER();
|
||||
select currentUser() = initial_user from system.processes where query like '%$!@#%';
|
@ -102,6 +102,9 @@ Sleeps 'seconds' seconds on each row. You can specify an integer or a floating-p
|
||||
Returns the name of the current database.
|
||||
You can use this function in table engine parameters in a CREATE TABLE query where you need to specify the database.
|
||||
|
||||
## currentUser()
|
||||
Returns the login of authorized user (initiator of query execution).
|
||||
|
||||
## isFinite(x)
|
||||
|
||||
Accepts Float32 and Float64 and returns UInt8 equal to 1 if the argument is not infinite and not a NaN, otherwise 0.
|
||||
|
@ -97,6 +97,9 @@ SELECT visibleWidth(NULL)
|
||||
Возвращает имя текущей базы данных.
|
||||
Эта функция может использоваться в параметрах движка таблицы в запросе CREATE TABLE там, где нужно указать базу данных.
|
||||
|
||||
## currentUser()
|
||||
Возвращает логин пользователя, от имени которого исполняется запрос. В случае распределённого запроса, возвращается имя пользователя - инициатора запроса.
|
||||
|
||||
## isFinite(x)
|
||||
Принимает Float32 или Float64 и возвращает UInt8, равный 1, если аргумент не бесконечный и не NaN, иначе 0.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user