diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/ln.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/ln.cpp index 8d3a86d3938e..452311483d8e 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/ln.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/ln.cpp @@ -29,7 +29,10 @@ class FunctionParserLn : public FunctionParserLogBase String getName() const override { return name; } String getCHFunctionName() const override { return "log"; } - DB::Float64 getParameterLowerBoundValue() const override { return 0.0; } + const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr & actions_dag, const DataTypePtr & data_type) const override + { + return addColumnToActionsDAG(actions_dag, data_type, 0.0); + } }; static FunctionParserRegister register_ln; diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/log10.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/log10.cpp index 9c476c8d7760..191ca1187512 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/log10.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/log10.cpp @@ -29,7 +29,10 @@ class FunctionParserLog10 : public FunctionParserLogBase String getName() const override { return name; } String getCHFunctionName() const override { return "log10"; } - DB::Float64 getParameterLowerBoundValue() const override { return 0.0; } + const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr & actions_dag, const DataTypePtr & data_type) const override + { + return addColumnToActionsDAG(actions_dag, data_type, 0.0); + } }; static FunctionParserRegister register_log10; diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/log1p.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/log1p.cpp index 886fb1752448..d669c1eab88a 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/log1p.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/log1p.cpp @@ -29,7 +29,10 @@ class FunctionParserLog1p : public FunctionParserLogBase String getName() const override { return name; } String getCHFunctionName() const override { return "log1p"; } - DB::Float64 getParameterLowerBoundValue() const override { return -1.0; } + const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr & actions_dag, const DataTypePtr & data_type) const override + { + return addColumnToActionsDAG(actions_dag, data_type, -1.0); + } }; static FunctionParserRegister register_log1p; diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp index e51675632086..463795be9c72 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp @@ -29,7 +29,10 @@ class FunctionParserLog2 : public FunctionParserLogBase String getName() const override { return name; } String getCHFunctionName() const override { return "log2"; } - DB::Float64 getParameterLowerBoundValue() const override { return 0.0; } + const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr & actions_dag, const DataTypePtr & data_type) const override + { + return addColumnToActionsDAG(actions_dag, data_type, 0.0); + } }; static FunctionParserRegister register_log2; diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h b/cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h index 36e76dcaa9ad..f46e6b83136e 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h @@ -26,21 +26,20 @@ namespace DB namespace ErrorCodes { extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; - extern const int ILLEGAL_TYPE_OF_ARGUMENT; + extern const int NOT_IMPLEMENTED; } } namespace local_engine { -template class FunctionParserLogBase : public FunctionParser { public: explicit FunctionParserLogBase(SerializedPlanParser * plan_parser_) : FunctionParser(plan_parser_) {} ~FunctionParserLogBase() override = default; - virtual Number getParameterLowerBoundValue() const { return 0.0; } - virtual DB::String getCHFunctionName() const { return "log" }; + virtual DB::String getCHFunctionName() const { return "log"; } + virtual const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr &, const DataTypePtr &) const { return nullptr; } const ActionsDAG::Node * parse( const substrait::Expression_ScalarFunction & substrait_func, @@ -64,8 +63,11 @@ class FunctionParserLogBase : public FunctionParser auto nullable_result_type = makeNullable(log_node->result_type); const auto * null_const_node = addColumnToActionsDAG(actions_dag, nullable_result_type, Field()); - const Number lowerBound = getParameterLowerBoundValue(); - const auto * le_node = toFunctionNode(actions_dag, "lessOrEquals", {arg_node, addColumnToActionsDAG(actions_dag, result_type, lowerBound)}); + const auto * lower_bound_node = getParameterLowerBound(actions_dag, arg_node->result_type); + if (!lower_bound_node) + throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Vritual function {} may not implement for {}", "getParameterLowerBound", getName()); + + const auto * le_node = toFunctionNode(actions_dag, "lessOrEquals", {arg_node, lower_bound_node}); const auto * result_node = toFunctionNode(actions_dag, "if", {le_node, null_const_node, log_node}); return convertNodeTypeIfNeeded(substrait_func, result_node, actions_dag);