You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by pa...@apache.org on 2022/09/12 11:58:54 UTC
[doris] branch master updated: [Function](cbrt)Add cbrt function for doris (#12523)
This is an automated email from the ASF dual-hosted git repository.
panxiaolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new c8e9a32bb2 [Function](cbrt)Add cbrt function for doris (#12523)
c8e9a32bb2 is described below
commit c8e9a32bb28297a80c37684982592fa525bcfb1a
Author: TaoZex <45...@users.noreply.github.com>
AuthorDate: Mon Sep 12 19:58:45 2022 +0800
[Function](cbrt)Add cbrt function for doris (#12523)
Add cbrt function for doris
---
be/src/exprs/math_functions.cpp | 1 +
be/src/exprs/math_functions.h | 1 +
be/src/vec/functions/math.cpp | 8 ++-
be/test/vec/function/function_math_test.cpp | 11 +++++
.../sql-functions/math-functions/cbrt.md | 57 ++++++++++++++++++++++
.../sql-functions/math-functions/cbrt.md | 57 ++++++++++++++++++++++
gensrc/script/doris_builtins_functions.py | 2 +
7 files changed, 136 insertions(+), 1 deletion(-)
diff --git a/be/src/exprs/math_functions.cpp b/be/src/exprs/math_functions.cpp
index f21ebb2c62..3247f316c6 100644
--- a/be/src/exprs/math_functions.cpp
+++ b/be/src/exprs/math_functions.cpp
@@ -187,6 +187,7 @@ ONE_ARG_MATH_FN(acos, DoubleVal, DoubleVal, std::acos);
ONE_ARG_MATH_FN(tan, DoubleVal, DoubleVal, std::tan);
ONE_ARG_MATH_FN(atan, DoubleVal, DoubleVal, std::atan);
ONE_ARG_MATH_FN(sqrt, DoubleVal, DoubleVal, std::sqrt);
+ONE_ARG_MATH_FN(cbrt, DoubleVal, DoubleVal, std::cbrt);
ONE_ARG_MATH_FN(ceil, BigIntVal, DoubleVal, std::ceil);
ONE_ARG_MATH_FN(floor, BigIntVal, DoubleVal, std::floor);
ONE_ARG_MATH_FN(exp, DoubleVal, DoubleVal, std::exp);
diff --git a/be/src/exprs/math_functions.h b/be/src/exprs/math_functions.h
index edc4a394a7..9ac791ab61 100644
--- a/be/src/exprs/math_functions.h
+++ b/be/src/exprs/math_functions.h
@@ -88,6 +88,7 @@ public:
const doris_udf::DoubleVal& v);
static doris_udf::DoubleVal sqrt(doris_udf::FunctionContext*, const doris_udf::DoubleVal&);
+ static doris_udf::DoubleVal cbrt(doris_udf::FunctionContext*, const doris_udf::DoubleVal&);
static doris_udf::DoubleVal pow(doris_udf::FunctionContext* ctx,
const doris_udf::DoubleVal& base,
const doris_udf::DoubleVal& exp);
diff --git a/be/src/vec/functions/math.cpp b/be/src/vec/functions/math.cpp
index 6278d33567..417f576a52 100644
--- a/be/src/vec/functions/math.cpp
+++ b/be/src/vec/functions/math.cpp
@@ -266,6 +266,11 @@ struct SqrtName {
};
using FunctionSqrt = FunctionMathUnary<UnaryFunctionVectorized<SqrtName, std::sqrt>>;
+struct CbrtName {
+ static constexpr auto name = "cbrt";
+};
+using FunctionCbrt = FunctionMathUnary<UnaryFunctionVectorized<CbrtName, std::cbrt>>;
+
struct TanName {
static constexpr auto name = "tan";
};
@@ -444,6 +449,7 @@ void register_function_math(SimpleFunctionFactory& factory) {
factory.register_function<FunctionSin>();
factory.register_function<FunctionSqrt>();
factory.register_alias("sqrt", "dsqrt");
+ factory.register_function<FunctionCbrt>();
factory.register_function<FunctionTan>();
factory.register_function<FunctionFloor>();
factory.register_alias("floor", "dfloor");
@@ -460,4 +466,4 @@ void register_function_math(SimpleFunctionFactory& factory) {
factory.register_function<FunctionDegrees>();
factory.register_function<FunctionBin>();
}
-} // namespace doris::vectorized
\ No newline at end of file
+} // namespace doris::vectorized
diff --git a/be/test/vec/function/function_math_test.cpp b/be/test/vec/function/function_math_test.cpp
index 940bbc995e..a93fb02603 100644
--- a/be/test/vec/function/function_math_test.cpp
+++ b/be/test/vec/function/function_math_test.cpp
@@ -108,6 +108,17 @@ TEST(MathFunctionTest, sqrt_test) {
check_function<DataTypeFloat64, true>(func_name, input_types, data_set);
}
+TEST(MathFunctionTest, cbrt_test) {
+ std::string func_name = "cbrt";
+
+ InputTypeSet input_types = {TypeIndex::Float64};
+
+ DataSet data_set = {
+ {{0.0}, 0.0}, {{2.0}, 1.2599210498948734}, {{8.0}, 2.0}, {{-1000.0}, -10.0}};
+
+ check_function<DataTypeFloat64, true>(func_name, input_types, data_set);
+}
+
TEST(MathFunctionTest, tan_test) {
std::string func_name = "tan"; //tan(x)
diff --git a/docs/en/docs/sql-manual/sql-functions/math-functions/cbrt.md b/docs/en/docs/sql-manual/sql-functions/math-functions/cbrt.md
new file mode 100644
index 0000000000..24fcba137e
--- /dev/null
+++ b/docs/en/docs/sql-manual/sql-functions/math-functions/cbrt.md
@@ -0,0 +1,57 @@
+---
+{
+ "title": "cbrt",
+ "language": "en"
+}
+---
+
+<!--
+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.
+-->
+
+## cbrt
+
+### description
+#### Syntax
+
+`DOUBLE cbrt(DOUBLE x)`
+Returns the cube root of x.
+
+### example
+
+```
+mysql> select cbrt(8);
++-----------+
+| cbrt(8.0) |
++-----------+
+| 2 |
++-----------+
+mysql> select cbrt(2.0);
++--------------------+
+| cbrt(2.0) |
++--------------------+
+| 1.2599210498948734 |
++--------------------+
+mysql> select cbrt(-1000.0);
++---------------+
+| cbrt(-1000.0) |
++---------------+
+| -10 |
++---------------+
+```
+
+### keywords
+ CBRT
diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/math-functions/cbrt.md b/docs/zh-CN/docs/sql-manual/sql-functions/math-functions/cbrt.md
new file mode 100644
index 0000000000..73178f2003
--- /dev/null
+++ b/docs/zh-CN/docs/sql-manual/sql-functions/math-functions/cbrt.md
@@ -0,0 +1,57 @@
+---
+{
+ "title": "cbrt",
+ "language": "zh-CN"
+}
+---
+
+<!--
+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.
+-->
+
+## cbrt
+
+### description
+#### Syntax
+
+`DOUBLE cbrt(DOUBLE x)`
+返回`x`的立方根.
+
+### example
+
+```
+mysql> select cbrt(8);
++-----------+
+| cbrt(8.0) |
++-----------+
+| 2 |
++-----------+
+mysql> select cbrt(2.0);
++--------------------+
+| cbrt(2.0) |
++--------------------+
+| 1.2599210498948734 |
++--------------------+
+mysql> select cbrt(-1000.0);
++---------------+
+| cbrt(-1000.0) |
++---------------+
+| -10 |
++---------------+
+```
+
+### keywords
+ CBRT
diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py
index 9b9eafaba9..28f9832d44 100755
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -1715,6 +1715,8 @@ visible_functions = [
[['sqrt', 'dsqrt'], 'DOUBLE', ['DOUBLE'],
'_ZN5doris13MathFunctions4sqrtEPN9doris_udf15FunctionContextERKNS1_9DoubleValE', '', '', 'vec', ''],
+ [['cbrt'], 'DOUBLE', ['DOUBLE'],
+ '_ZN5doris13MathFunctions4cbrtEPN9doris_udf15FunctionContextERKNS1_9DoubleValE', '', '', 'vec', ''],
[['pow', 'power', 'dpow', 'fpow'], 'DOUBLE', ['DOUBLE', 'DOUBLE'],
'_ZN5doris13MathFunctions3powEPN9doris_udf15FunctionContextERKNS1_9DoubleValES6_', '', '', 'vec', ''],
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org