-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccf95f5
commit 8a6dda1
Showing
7 changed files
with
210 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <Parser/scalar_function_parser/logarithm.h> | ||
|
||
namespace local_engine | ||
{ | ||
|
||
class FunctionParserLn : public FunctionParserLogBase | ||
{ | ||
public: | ||
explicit FunctionParserLn(SerializedPlanParser * plan_parser_) : FunctionParserLogBase(plan_parser_) {} | ||
~FunctionParserLn() override = default; | ||
|
||
static constexpr auto name = "log"; | ||
|
||
String getName() const override { return name; } | ||
String getCHFunctionName() const override { return "log"; } | ||
const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr & actions_dag, const DataTypePtr & data_type) const override | ||
{ | ||
return addColumnToActionsDAG(actions_dag, data_type, 0.0); | ||
} | ||
}; | ||
|
||
static FunctionParserRegister<FunctionParserLn> register_ln; | ||
} |
39 changes: 39 additions & 0 deletions
39
cpp-ch/local-engine/Parser/scalar_function_parser/log10.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <Parser/scalar_function_parser/logarithm.h> | ||
|
||
namespace local_engine | ||
{ | ||
|
||
class FunctionParserLog10 : public FunctionParserLogBase | ||
{ | ||
public: | ||
explicit FunctionParserLog10(SerializedPlanParser * plan_parser_) : FunctionParserLogBase(plan_parser_) {} | ||
~FunctionParserLog10() override = default; | ||
|
||
static constexpr auto name = "log10"; | ||
|
||
String getName() const override { return name; } | ||
String getCHFunctionName() const override { return "log10"; } | ||
const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr & actions_dag, const DataTypePtr & data_type) const override | ||
{ | ||
return addColumnToActionsDAG(actions_dag, data_type, 0.0); | ||
} | ||
}; | ||
|
||
static FunctionParserRegister<FunctionParserLog10> register_log10; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
cpp-ch/local-engine/Parser/scalar_function_parser/log2.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <Parser/scalar_function_parser/logarithm.h> | ||
|
||
namespace local_engine | ||
{ | ||
|
||
class FunctionParserLog2 : public FunctionParserLogBase | ||
{ | ||
public: | ||
explicit FunctionParserLog2(SerializedPlanParser * plan_parser_) : FunctionParserLogBase(plan_parser_) {} | ||
~FunctionParserLog2() override = default; | ||
|
||
static constexpr auto name = "log2"; | ||
|
||
String getName() const override { return name; } | ||
String getCHFunctionName() const override { return "log2"; } | ||
const DB::ActionsDAG::Node * getParameterLowerBound(ActionsDAGPtr & actions_dag, const DataTypePtr & data_type) const override | ||
{ | ||
return addColumnToActionsDAG(actions_dag, data_type, 0.0); | ||
} | ||
}; | ||
|
||
static FunctionParserRegister<FunctionParserLog2> register_log2; | ||
} |
77 changes: 77 additions & 0 deletions
77
cpp-ch/local-engine/Parser/scalar_function_parser/logarithm.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <Parser/FunctionParser.h> | ||
#include <Common/CHUtil.h> | ||
#include <Core/Field.h> | ||
#include <DataTypes/IDataType.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
namespace ErrorCodes | ||
{ | ||
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; | ||
extern const int NOT_IMPLEMENTED; | ||
} | ||
} | ||
|
||
namespace local_engine | ||
{ | ||
class FunctionParserLogBase : public FunctionParser | ||
{ | ||
public: | ||
explicit FunctionParserLogBase(SerializedPlanParser * plan_parser_) : FunctionParser(plan_parser_) {} | ||
~FunctionParserLogBase() override = default; | ||
|
||
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, | ||
ActionsDAGPtr & actions_dag) const override | ||
{ | ||
/* | ||
parse log(x) as | ||
if (x <= c) | ||
null | ||
else | ||
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 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 * 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); | ||
} | ||
}; | ||
|
||
} |