ClickHouse/src/Functions/IFunctionAdaptors.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

152 lines
7.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 useDefaultImplementationForNothing() const final { return function->useDefaultImplementationForNothing(); }
bool useDefaultImplementationForConstants() const final { return function->useDefaultImplementationForConstants(); }
bool useDefaultImplementationForLowCardinalityColumns() const final { return function->useDefaultImplementationForLowCardinalityColumns(); }
2021-05-21 00:57:11 +00:00
bool useDefaultImplementationForSparseColumns() const final { return function->useDefaultImplementationForSparseColumns(); }
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(); }
2021-05-24 11:25:02 +00:00
ColumnPtr getConstantResultForNonConstArguments(const ColumnsWithTypeAndName & arguments_, const DataTypePtr & result_type_) const override
{
2021-05-24 11:25:02 +00:00
return function->getConstantResultForNonConstArguments(arguments_, result_type_);
}
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(); }
2021-06-22 16:21:23 +00:00
bool isShortCircuit(ShortCircuitSettings & settings, size_t number_of_arguments) const override { return function->isShortCircuit(settings, number_of_arguments); }
2021-06-22 16:21:23 +00:00
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & args) const override { return function->isSuitableForShortCircuitArgumentsExecution(args); }
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 useDefaultImplementationForNothing() const override { return function->useDefaultImplementationForNothing(); }
bool useDefaultImplementationForLowCardinalityColumns() const override { return function->useDefaultImplementationForLowCardinalityColumns(); }
2021-05-21 00:57:11 +00:00
bool useDefaultImplementationForSparseColumns() const override { return function->useDefaultImplementationForSparseColumns(); }
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); }
2021-06-23 12:19:22 +00:00
const IFunction * getFunction() const { return function.get(); }
private:
std::shared_ptr<IFunction> function;
};
}