ClickHouse/src/Functions/IFunctionAdaptors.h

142 lines
6.1 KiB
C++
Raw Normal View History

#pragma once
2021-05-17 07:30:42 +00:00
#include <Functions/IFunction.h>
namespace DB
{
2021-05-15 17:33:15 +00:00
/// Following class implement IExecutableFunction via IFunction.
2021-05-15 17:33:15 +00:00
class FunctionToExecutableFunctionAdaptor final : public IExecutableFunction
{
public:
2021-05-15 17:33:15 +00:00
explicit FunctionToExecutableFunctionAdaptor(std::shared_ptr<IFunction> function_) : function(std::move(function_)) {}
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
{
2020-10-15 16:52:25 +00:00
return function->executeImpl(arguments, result_type, input_rows_count);
}
2021-05-15 17:33:15 +00:00
ColumnPtr executeDryRunImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const final
{
2020-10-15 16:52:25 +00:00
return function->executeImplDryRun(arguments, result_type, input_rows_count);
}
2021-05-15 17:33:15 +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
{
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_)) {}
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; }
#if USE_EMBEDDED_COMPILER
2020-10-15 16:52:25 +00:00
bool isCompilable() const override { return function->isCompilable(getArgumentTypes()); }
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));
}
#endif
2021-05-15 17:33:15 +00:00
ExecutableFunctionPtr prepare(const ColumnsWithTypeAndName & /*arguments*/) const override
{
2021-05-15 17:33:15 +00:00
return std::make_unique<FunctionToExecutableFunctionAdaptor>(function);
}
bool isSuitableForConstantFolding() const override { return function->isSuitableForConstantFolding(); }
ColumnPtr getConstantResultForArguments(const ColumnsWithTypeAndName & arguments_) const override
{
return function->getConstantResultForArguments(arguments_);
}
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); }
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;
};
2021-05-15 17:33:15 +00:00
/// Following class implement IFunctionOverloadResolver via IFunction.
class FunctionToOverloadResolverAdaptor : public IFunctionOverloadResolver
{
public:
2021-05-15 17:33:15 +00:00
explicit FunctionToOverloadResolverAdaptor(std::shared_ptr<IFunction> function_) : function(std::move(function_)) {}
bool isDeterministic() const override { return function->isDeterministic(); }
bool isDeterministicInScopeOfQuery() const override { return function->isDeterministicInScopeOfQuery(); }
bool isInjective(const ColumnsWithTypeAndName & columns) const override { return function->isInjective(columns); }
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); }
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
{
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);
}
2021-05-15 17:33:15 +00:00
void getLambdaArgumentTypesImpl(DataTypes & arguments) const override { function->getLambdaArgumentTypes(arguments); }
private:
std::shared_ptr<IFunction> function;
};
}