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 423adb92d01b..8d3a86d3938e 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/ln.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/ln.cpp @@ -28,6 +28,7 @@ class FunctionParserLn : public FunctionParserLogBase static constexpr auto name = "log"; String getName() const override { return name; } + String getCHFunctionName() const override { return "log"; } DB::Float64 getParameterLowerBoundValue() const override { return 0.0; } }; 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 fade79ace895..9c476c8d7760 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/log10.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/log10.cpp @@ -28,6 +28,7 @@ class FunctionParserLog10 : public FunctionParserLogBase static constexpr auto name = "log10"; String getName() const override { return name; } + String getCHFunctionName() const override { return "log10"; } DB::Float64 getParameterLowerBoundValue() const override { return 0.0; } }; 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 8a877ef5e7a7..886fb1752448 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/log1p.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/log1p.cpp @@ -28,6 +28,7 @@ class FunctionParserLog1p : public FunctionParserLogBase static constexpr auto name = "log1p"; String getName() const override { return name; } + String getCHFunctionName() const override { return "log1p"; } DB::Float64 getParameterLowerBoundValue() const override { return -1.0; } }; 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 5f71f22cc62f..e51675632086 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp @@ -28,6 +28,7 @@ class FunctionParserLog2 : public FunctionParserLogBase static constexpr auto name = "log2"; String getName() const override { return name; } + String getCHFunctionName() const override { return "log2"; } DB::Float64 getParameterLowerBoundValue() const override { return 0.0; } }; 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 1acd22d2c431..36e76dcaa9ad 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h @@ -26,18 +26,21 @@ namespace DB namespace ErrorCodes { extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; + extern const int ILLEGAL_TYPE_OF_ARGUMENT; } } namespace local_engine { +template class FunctionParserLogBase : public FunctionParser { public: explicit FunctionParserLogBase(SerializedPlanParser * plan_parser_) : FunctionParser(plan_parser_) {} ~FunctionParserLogBase() override = default; - virtual DB::Float64 getParameterLowerBoundValue() const { return 0.0; } + virtual Number getParameterLowerBoundValue() const { return 0.0; } + virtual DB::String getCHFunctionName() const { return "log" }; const ActionsDAG::Node * parse( const substrait::Expression_ScalarFunction & substrait_func, @@ -48,24 +51,22 @@ class FunctionParserLogBase : public FunctionParser if (x <= c) null else - log(c) + log(x) */ auto parsed_args = parseFunctionArguments(substrait_func, "", actions_dag); if (parsed_args.size() != 1) throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Function {} requires exactly one arguments", getName()); const auto * arg_node = parsed_args[0]; - const std::string function_name = getName(); - const auto * log_node = toFunctionNode(actions_dag, function_name, {arg_node}); - - auto result_type = log_node->result_type; - auto nullable_result_type = makeNullable(result_type); + + const std::string ch_function_name = getCHFunctionName(); + const auto * log_node = toFunctionNode(actions_dag, ch_function_name, {arg_node}); + auto nullable_result_type = makeNullable(log_node->result_type); const auto * null_const_node = addColumnToActionsDAG(actions_dag, nullable_result_type, Field()); - const auto * nullable_log_node = ActionsDAGUtil::convertNodeType(actions_dag, log_node, nullable_result_type->getName(), log_node->result_name); - const DB::Float64 lowerBound = getParameterLowerBoundValue(); + const Number lowerBound = getParameterLowerBoundValue(); const auto * le_node = toFunctionNode(actions_dag, "lessOrEquals", {arg_node, addColumnToActionsDAG(actions_dag, result_type, lowerBound)}); - const auto * result_node = toFunctionNode(actions_dag, "if", {le_node, null_const_node, nullable_log_node}); + const auto * result_node = toFunctionNode(actions_dag, "if", {le_node, null_const_node, log_node}); return convertNodeTypeIfNeeded(substrait_func, result_node, actions_dag); }