2019-12-12 14:16:59 +00:00
|
|
|
#pragma once
|
2021-04-10 23:33:54 +00:00
|
|
|
|
2021-05-17 07:30:42 +00:00
|
|
|
#include <Functions/IFunction.h>
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
/// Following class implement IExecutableFunction via IFunction.
|
2019-12-12 14:16:59 +00:00
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
class FunctionToExecutableFunctionAdaptor final : public IExecutableFunction
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-05-15 17:33:15 +00:00
|
|
|
explicit FunctionToExecutableFunctionAdaptor(std::shared_ptr<IFunction> function_) : function(std::move(function_)) {}
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
String getName() const override { return function->getName(); }
|
|
|
|
|
|
|
|
protected:
|
2021-05-15 17:33:15 +00:00
|
|
|
|
|
|
|
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const final
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
2020-10-15 16:52:25 +00:00
|
|
|
return function->executeImpl(arguments, result_type, input_rows_count);
|
2019-12-12 14:16:59 +00:00
|
|
|
}
|
2021-05-15 17:33:15 +00:00
|
|
|
|
|
|
|
ColumnPtr executeDryRunImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const final
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
2020-10-15 16:52:25 +00:00
|
|
|
return function->executeImplDryRun(arguments, result_type, input_rows_count);
|
2019-12-12 14:16:59 +00:00
|
|
|
}
|
2021-05-15 17:33:15 +00:00
|
|
|
|
2019-12-12 14:16:59 +00:00
|
|
|
bool useDefaultImplementationForNulls() const final { return function->useDefaultImplementationForNulls(); }
|
|
|
|
bool useDefaultImplementationForConstants() const final { return function->useDefaultImplementationForConstants(); }
|
|
|
|
bool useDefaultImplementationForLowCardinalityColumns() const final { return function->useDefaultImplementationForLowCardinalityColumns(); }
|
|
|
|
ColumnNumbers getArgumentsThatAreAlwaysConstant() const final { return function->getArgumentsThatAreAlwaysConstant(); }
|
|
|
|
bool canBeExecutedOnDefaultArguments() const override { return function->canBeExecutedOnDefaultArguments(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IFunction> function;
|
|
|
|
};
|
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
/// Following class implement IFunctionBase via IFunction.
|
|
|
|
|
|
|
|
class FunctionToFunctionBaseAdaptor final : public IFunctionBase
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-05-15 17:33:15 +00:00
|
|
|
FunctionToFunctionBaseAdaptor(std::shared_ptr<IFunction> function_, DataTypes arguments_, DataTypePtr result_type_)
|
2020-10-15 16:52:25 +00:00
|
|
|
: function(std::move(function_)), arguments(std::move(arguments_)), result_type(std::move(result_type_)) {}
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
String getName() const override { return function->getName(); }
|
|
|
|
|
|
|
|
const DataTypes & getArgumentTypes() const override { return arguments; }
|
2020-10-15 16:52:25 +00:00
|
|
|
const DataTypePtr & getResultType() const override { return result_type; }
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
|
2020-10-15 16:52:25 +00:00
|
|
|
bool isCompilable() const override { return function->isCompilable(getArgumentTypes()); }
|
2019-12-12 14:16:59 +00:00
|
|
|
|
2021-05-03 22:34:40 +00:00
|
|
|
llvm::Value * compile(llvm::IRBuilderBase & builder, Values values) const override
|
|
|
|
{
|
|
|
|
return function->compile(builder, getArgumentTypes(), std::move(values));
|
|
|
|
}
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
ExecutableFunctionPtr prepare(const ColumnsWithTypeAndName & /*arguments*/) const override
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
2021-05-15 17:33:15 +00:00
|
|
|
return std::make_unique<FunctionToExecutableFunctionAdaptor>(function);
|
2019-12-12 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableForConstantFolding() const override { return function->isSuitableForConstantFolding(); }
|
2021-05-22 12:49:21 +00:00
|
|
|
|
2021-05-24 11:25:02 +00:00
|
|
|
ColumnPtr getConstantResultForNonConstArguments(const ColumnsWithTypeAndName & arguments_, const DataTypePtr & result_type_) const override
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
2021-05-24 11:25:02 +00:00
|
|
|
return function->getConstantResultForNonConstArguments(arguments_, result_type_);
|
2019-12-12 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isStateful() const override { return function->isStateful(); }
|
|
|
|
|
2020-10-14 14:04:50 +00:00
|
|
|
bool isInjective(const ColumnsWithTypeAndName & sample_columns) const override { return function->isInjective(sample_columns); }
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
bool isDeterministic() const override { return function->isDeterministic(); }
|
|
|
|
|
|
|
|
bool isDeterministicInScopeOfQuery() const override { return function->isDeterministicInScopeOfQuery(); }
|
|
|
|
|
|
|
|
bool hasInformationAboutMonotonicity() const override { return function->hasInformationAboutMonotonicity(); }
|
|
|
|
|
|
|
|
Monotonicity getMonotonicityForRange(const IDataType & type, const Field & left, const Field & right) const override
|
|
|
|
{
|
|
|
|
return function->getMonotonicityForRange(type, left, right);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IFunction> function;
|
|
|
|
DataTypes arguments;
|
2020-10-15 16:52:25 +00:00
|
|
|
DataTypePtr result_type;
|
2019-12-12 14:16:59 +00:00
|
|
|
};
|
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
|
|
|
|
/// Following class implement IFunctionOverloadResolver via IFunction.
|
|
|
|
|
|
|
|
class FunctionToOverloadResolverAdaptor : public IFunctionOverloadResolver
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-05-15 17:33:15 +00:00
|
|
|
explicit FunctionToOverloadResolverAdaptor(std::shared_ptr<IFunction> function_) : function(std::move(function_)) {}
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
bool isDeterministic() const override { return function->isDeterministic(); }
|
|
|
|
bool isDeterministicInScopeOfQuery() const override { return function->isDeterministicInScopeOfQuery(); }
|
2020-10-09 07:41:28 +00:00
|
|
|
bool isInjective(const ColumnsWithTypeAndName & columns) const override { return function->isInjective(columns); }
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
String getName() const override { return function->getName(); }
|
|
|
|
bool isStateful() const override { return function->isStateful(); }
|
|
|
|
bool isVariadic() const override { return function->isVariadic(); }
|
|
|
|
size_t getNumberOfArguments() const override { return function->getNumberOfArguments(); }
|
|
|
|
|
|
|
|
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return function->getArgumentsThatAreAlwaysConstant(); }
|
|
|
|
ColumnNumbers getArgumentsThatDontImplyNullableReturnType(size_t number_of_arguments) const override
|
|
|
|
{
|
|
|
|
return function->getArgumentsThatDontImplyNullableReturnType(number_of_arguments);
|
|
|
|
}
|
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override { return function->getReturnTypeImpl(arguments); }
|
|
|
|
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override { return function->getReturnTypeImpl(arguments); }
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
bool useDefaultImplementationForNulls() const override { return function->useDefaultImplementationForNulls(); }
|
|
|
|
bool useDefaultImplementationForLowCardinalityColumns() const override { return function->useDefaultImplementationForLowCardinalityColumns(); }
|
|
|
|
bool canBeExecutedOnLowCardinalityDictionary() const override { return function->canBeExecutedOnLowCardinalityDictionary(); }
|
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type) const override
|
2019-12-12 14:16:59 +00:00
|
|
|
{
|
|
|
|
DataTypes data_types(arguments.size());
|
|
|
|
for (size_t i = 0; i < arguments.size(); ++i)
|
|
|
|
data_types[i] = arguments[i].type;
|
2021-05-15 17:33:15 +00:00
|
|
|
|
|
|
|
return std::make_unique<FunctionToFunctionBaseAdaptor>(function, data_types, result_type);
|
2019-12-12 14:16:59 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
void getLambdaArgumentTypesImpl(DataTypes & arguments) const override { function->getLambdaArgumentTypes(arguments); }
|
2019-12-12 14:16:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<IFunction> function;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|