Skip to content

Commit

Permalink
review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinyhZou committed Dec 12, 2023
1 parent a4fb08a commit f003a17
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions cpp-ch/local-engine/Parser/scalar_function_parser/ln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

Expand Down
1 change: 1 addition & 0 deletions cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

Expand Down
21 changes: 11 additions & 10 deletions cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename FirstParameterDataType>
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,
Expand All @@ -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);
}
Expand Down

0 comments on commit f003a17

Please sign in to comment.