mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 07:01:59 +00:00
dbms: added function identity [#METR-17251].
This commit is contained in:
parent
aa30036fd4
commit
234367b038
@ -534,6 +534,36 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class FunctionIdentity : public IFunction
|
||||
{
|
||||
public:
|
||||
static constexpr auto name = "identity";
|
||||
static IFunction * create(const Context & context) { return new FunctionIdentity; }
|
||||
|
||||
/// Получить имя функции.
|
||||
String getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/// Получить тип результата по типам аргументов. Если функция неприменима для данных аргументов - кинуть исключение.
|
||||
DataTypePtr getReturnType(const DataTypes & arguments) const
|
||||
{
|
||||
if (arguments.size() != 1)
|
||||
throw Exception("Function " + getName() + " requires exactly one argument.",
|
||||
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||||
|
||||
return arguments.front()->clone();
|
||||
}
|
||||
|
||||
/// Выполнить функцию над блоком.
|
||||
void execute(Block & block, const ColumnNumbers & arguments, size_t result)
|
||||
{
|
||||
block.getByPosition(result).column = block.getByPosition(arguments.front()).column;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FunctionArrayJoin : public IFunction
|
||||
{
|
||||
public:
|
||||
|
@ -325,6 +325,7 @@ void registerFunctionsMiscellaneous(FunctionFactory & factory)
|
||||
factory.registerFunction<FunctionSleep>();
|
||||
factory.registerFunction<FunctionMaterialize>();
|
||||
factory.registerFunction<FunctionIgnore>();
|
||||
factory.registerFunction<FunctionIdentity>();
|
||||
factory.registerFunction<FunctionArrayJoin>();
|
||||
factory.registerFunction<FunctionReplicate>();
|
||||
factory.registerFunction<FunctionBar>();
|
||||
|
1
dbms/tests/queries/0_stateless/00194_identity.reference
Normal file
1
dbms/tests/queries/0_stateless/00194_identity.reference
Normal file
@ -0,0 +1 @@
|
||||
1 1 1
|
1
dbms/tests/queries/0_stateless/00194_identity.sql
Normal file
1
dbms/tests/queries/0_stateless/00194_identity.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT identity(1 AS a) AS b, a, b;
|
Loading…
Reference in New Issue
Block a user