This is an automated email from the ASF dual-hosted git repository.

liuneng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 9499349a0 [CH] Support csc/sec/cot function (#5239)
9499349a0 is described below

commit 9499349a07eff402f3124d752d977cae9b3766c6
Author: exmy <[email protected]>
AuthorDate: Tue Apr 2 18:12:42 2024 +0800

    [CH] Support csc/sec/cot function (#5239)
    
    What changes were proposed in this pull request?
    Support csc/sec/cot function
    
    How was this patch tested?
    PASS CI
---
 .../Parser/scalar_function_parser/cot.cpp          | 62 ++++++++++++++++++++++
 .../Parser/scalar_function_parser/csc.cpp          | 62 ++++++++++++++++++++++
 .../Parser/scalar_function_parser/sec.cpp          | 62 ++++++++++++++++++++++
 .../gluten/expression/ExpressionMappings.scala     |  1 +
 .../utils/clickhouse/ClickHouseTestSettings.scala  |  1 -
 .../utils/clickhouse/ClickHouseTestSettings.scala  |  5 +-
 .../apache/gluten/expression/ExpressionNames.scala |  1 +
 7 files changed, 189 insertions(+), 5 deletions(-)

diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/cot.cpp 
b/cpp-ch/local-engine/Parser/scalar_function_parser/cot.cpp
new file mode 100644
index 000000000..84eaa3ea6
--- /dev/null
+++ b/cpp-ch/local-engine/Parser/scalar_function_parser/cot.cpp
@@ -0,0 +1,62 @@
+/*
+ * 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 <DataTypes/IDataType.h>
+
+namespace DB
+{
+
+namespace ErrorCodes
+{
+    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
+}
+}
+
+namespace local_engine
+{
+
+class FunctionParserCot : public FunctionParser
+{
+public:
+    explicit FunctionParserCot(SerializedPlanParser * plan_parser_) : 
FunctionParser(plan_parser_) { }
+    ~FunctionParserCot() override = default;
+
+    static constexpr auto name = "cot";
+
+    String getName() const override { return name; }
+
+    const ActionsDAG::Node * parse(
+        const substrait::Expression_ScalarFunction & substrait_func,
+        ActionsDAGPtr & actions_dag) const override
+    {
+        /// parse cot(x) as 1 / tan(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 * x = parsed_args[0];
+        const auto * tan_node = toFunctionNode(actions_dag, "tan", {x});
+        const auto * one_const_node = addColumnToActionsDAG(actions_dag, 
std::make_shared<DataTypeFloat64>(), 1.0);
+        const auto * result_node = toFunctionNode(actions_dag, "divide", 
{one_const_node, tan_node});
+
+        return convertNodeTypeIfNeeded(substrait_func, result_node, 
actions_dag);;
+    }
+};
+
+static FunctionParserRegister<FunctionParserCot> register_cot;
+
+}
diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/csc.cpp 
b/cpp-ch/local-engine/Parser/scalar_function_parser/csc.cpp
new file mode 100644
index 000000000..b63a76ed5
--- /dev/null
+++ b/cpp-ch/local-engine/Parser/scalar_function_parser/csc.cpp
@@ -0,0 +1,62 @@
+/*
+ * 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 <DataTypes/IDataType.h>
+
+namespace DB
+{
+
+namespace ErrorCodes
+{
+    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
+}
+}
+
+namespace local_engine
+{
+
+class FunctionParserCsc : public FunctionParser
+{
+public:
+    explicit FunctionParserCsc(SerializedPlanParser * plan_parser_) : 
FunctionParser(plan_parser_) { }
+    ~FunctionParserCsc() override = default;
+
+    static constexpr auto name = "csc";
+
+    String getName() const override { return name; }
+
+    const ActionsDAG::Node * parse(
+        const substrait::Expression_ScalarFunction & substrait_func,
+        ActionsDAGPtr & actions_dag) const override
+    {
+        /// parse csc(x) as 1 / sin(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 * x = parsed_args[0];
+        const auto * sin_node = toFunctionNode(actions_dag, "sin", {x});
+        const auto * one_const_node = addColumnToActionsDAG(actions_dag, 
std::make_shared<DataTypeFloat64>(), 1.0);
+        const auto * result_node = toFunctionNode(actions_dag, "divide", 
{one_const_node, sin_node});
+
+        return convertNodeTypeIfNeeded(substrait_func, result_node, 
actions_dag);;
+    }
+};
+
+static FunctionParserRegister<FunctionParserCsc> register_csc;
+
+}
diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/sec.cpp 
b/cpp-ch/local-engine/Parser/scalar_function_parser/sec.cpp
new file mode 100644
index 000000000..70765e07d
--- /dev/null
+++ b/cpp-ch/local-engine/Parser/scalar_function_parser/sec.cpp
@@ -0,0 +1,62 @@
+/*
+ * 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 <DataTypes/IDataType.h>
+
+namespace DB
+{
+
+namespace ErrorCodes
+{
+    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
+}
+}
+
+namespace local_engine
+{
+
+class FunctionParserSec : public FunctionParser
+{
+public:
+    explicit FunctionParserSec(SerializedPlanParser * plan_parser_) : 
FunctionParser(plan_parser_) { }
+    ~FunctionParserSec() override = default;
+
+    static constexpr auto name = "sec";
+
+    String getName() const override { return name; }
+
+    const ActionsDAG::Node * parse(
+        const substrait::Expression_ScalarFunction & substrait_func,
+        ActionsDAGPtr & actions_dag) const override
+    {
+        /// parse sec(x) as 1 / cos(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 * x = parsed_args[0];
+        const auto * cos_node = toFunctionNode(actions_dag, "cos", {x});
+        const auto * one_const_node = addColumnToActionsDAG(actions_dag, 
std::make_shared<DataTypeFloat64>(), 1.0);
+        const auto * result_node = toFunctionNode(actions_dag, "divide", 
{one_const_node, cos_node});
+
+        return convertNodeTypeIfNeeded(substrait_func, result_node, 
actions_dag);;
+    }
+};
+
+static FunctionParserRegister<FunctionParserSec> register_sec;
+
+}
diff --git 
a/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala
 
b/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala
index ec6fbd047..768df4783 100644
--- 
a/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala
+++ 
b/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala
@@ -117,6 +117,7 @@ object ExpressionMappings {
     Sig[Sinh](SINH),
     Sig[Tan](TAN),
     Sig[Tanh](TANH),
+    Sig[Cot](COT),
     Sig[BitwiseNot](BITWISE_NOT),
     Sig[BitwiseAnd](BITWISE_AND),
     Sig[BitwiseOr](BITWISE_OR),
diff --git 
a/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
 
b/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index b7c64fa5d..8bae61559 100644
--- 
a/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++ 
b/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -838,7 +838,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
     .exclude("SPARK-35871: Literal.create(value, dataType) should support 
fields")
     .excludeGlutenTest("default")
   enableSuite[GlutenMathExpressionsSuite]
-    .exclude("cot")
     .exclude("tanh")
     .exclude("ceil")
     .exclude("floor")
diff --git 
a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
 
b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index 60f911a1a..e59ca3f0d 100644
--- 
a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++ 
b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -404,7 +404,7 @@ class ClickHouseTestSettings extends BackendTestSettings {
     .exclude("SPARK-33907: bad json input with json pruning optimization: 
GetStructField")
     .exclude("SPARK-33907: json pruning optimization with corrupt record 
field")
     .exclude("SPARK-33907: bad json input with json pruning optimization: 
GetArrayStructFields")
-  enableSuite[GlutenMathFunctionsSuite].exclude("csc").exclude("sec")
+  enableSuite[GlutenMathFunctionsSuite]
   enableSuite[GlutenMetadataCacheSuite].exclude(
     "SPARK-16336,SPARK-27961 Suggest fixing FileNotFoundException")
   enableSuite[GlutenMiscFunctionsSuite]
@@ -843,9 +843,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
     .exclude("SPARK-35871: Literal.create(value, dataType) should support 
fields")
     .exclude("SPARK-37967: Literal.create support ObjectType")
   enableSuite[GlutenMathExpressionsSuite]
-    .exclude("csc")
-    .exclude("sec")
-    .exclude("cot")
     .exclude("tanh")
     .exclude("ceil")
     .exclude("floor")
diff --git 
a/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala
 
b/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala
index f800e5251..59a6810ab 100644
--- 
a/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala
+++ 
b/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala
@@ -140,6 +140,7 @@ object ExpressionNames {
   final val SINH = "sinh"
   final val TAN = "tan"
   final val TANH = "tanh"
+  final val COT = "cot"
   final val BITWISE_NOT = "bitwise_not"
   final val BITWISE_AND = "bitwise_and"
   final val BITWISE_OR = "bitwise_or"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to