Added randomASKII function by copying from the currentDatabase Function

This commit is contained in:
BayoNet 2019-11-15 16:28:26 +03:00
parent b6d6fea9e5
commit d226749576
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,54 @@
#include <Functions/IFunction.h>
#include <Functions/FunctionFactory.h>
#include <Interpreters/Context.h>
#include <DataTypes/DataTypeString.h>
#include <Core/Field.h>
namespace DB
{
class FunctionRandomASKII : public IFunction
{
const String db_name;
public:
static constexpr auto name = "randomASKII";
static FunctionPtr create(const Context & context)
{
return std::make_shared<FunctionRandomASKII>(context.getRandomASKII());
}
explicit FunctionRandomASKII(const String & db_name_) : db_name{db_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, db_name);
}
};
void registerFunctionRandomASKII(FunctionFactory & factory)
{
factory.registerFunction<FunctionRandomASKII>();
}
}

View File

@ -52,6 +52,7 @@ void registerFunctionEvalMLMethod(FunctionFactory &);
void registerFunctionBasename(FunctionFactory &);
void registerFunctionTransform(FunctionFactory &);
void registerFunctionGetMacro(FunctionFactory &);
void registerFunctionRandomASKII(FunctionFactory &);
#if USE_ICU
void registerFunctionConvertCharset(FunctionFactory &);
@ -106,6 +107,7 @@ void registerFunctionsMiscellaneous(FunctionFactory & factory)
registerFunctionBasename(factory);
registerFunctionTransform(factory);
registerFunctionGetMacro(factory);
registerFunctionRandomASKII(factory);
#if USE_ICU
registerFunctionConvertCharset(factory);