This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
commit 19f57b544e7ce67d6fb3866180faf701c5ca19fc Author: Rohit Satardekar <[email protected]> AuthorDate: Wed Jan 31 10:58:04 2024 +0530 support cosh math function (#30602) Co-authored-by: Rohit Satardekar <[email protected]> --- be/src/vec/functions/math.cpp | 6 ++ .../sql-functions/numeric-functions/cosh.md | 52 +++++++++++++++++ docs/sidebars.json | 3 +- .../sql-functions/numeric-functions/cosh.md | 52 +++++++++++++++++ .../doris/catalog/BuiltinScalarFunctions.java | 2 + .../trees/expressions/functions/scalar/Cosh.java | 68 ++++++++++++++++++++++ .../expressions/visitor/ScalarFunctionVisitor.java | 5 ++ gensrc/script/doris_builtins_functions.py | 1 + .../data/nereids_function_p0/scalar_function/C.out | 29 +++++++++ .../nereids_function_p0/scalar_function/C.groovy | 2 + 10 files changed, 219 insertions(+), 1 deletion(-) diff --git a/be/src/vec/functions/math.cpp b/be/src/vec/functions/math.cpp index 7afdde90860..1ebecd16a4c 100644 --- a/be/src/vec/functions/math.cpp +++ b/be/src/vec/functions/math.cpp @@ -79,6 +79,11 @@ struct CosName { }; using FunctionCos = FunctionMathUnary<UnaryFunctionPlain<CosName, std::cos>>; +struct CoshName { + static constexpr auto name = "cosh"; +}; +using FunctionCosh = FunctionMathUnary<UnaryFunctionPlain<CoshName, std::cosh>>; + struct EImpl { static constexpr auto name = "e"; static constexpr double value = 2.7182818284590452353602874713526624977572470; @@ -393,6 +398,7 @@ void register_function_math(SimpleFunctionFactory& factory) { factory.register_function<FunctionAsin>(); factory.register_function<FunctionAtan>(); factory.register_function<FunctionCos>(); + factory.register_function<FunctionCosh>(); factory.register_alias("ceil", "dceil"); factory.register_alias("ceil", "ceiling"); factory.register_function<FunctionE>(); diff --git a/docs/en/docs/sql-manual/sql-functions/numeric-functions/cosh.md b/docs/en/docs/sql-manual/sql-functions/numeric-functions/cosh.md new file mode 100644 index 00000000000..8309649aed3 --- /dev/null +++ b/docs/en/docs/sql-manual/sql-functions/numeric-functions/cosh.md @@ -0,0 +1,52 @@ +--- +{ + "title": "COSH", + "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. +--> + +## cosh + +### description +#### Syntax + +`DOUBLE cosh(DOUBLE x)` +Returns the hyperbolic cosine of `x`. + +### example + +``` +mysql> select cosh(0); ++---------+ +| cosh(0) | ++---------+ +| 1 | ++---------+ + +mysql> select cosh(1); ++---------------------+ +| cosh(1) | ++---------------------+ +| 1.5430806348152437 | ++---------------------+ +``` + +### keywords + COSH diff --git a/docs/sidebars.json b/docs/sidebars.json index 3acc778678a..f892da7c345 100644 --- a/docs/sidebars.json +++ b/docs/sidebars.json @@ -711,6 +711,7 @@ "sql-manual/sql-functions/numeric-functions/bin", "sql-manual/sql-functions/numeric-functions/sin", "sql-manual/sql-functions/numeric-functions/cos", + "sql-manual/sql-functions/numeric-functions/cosh", "sql-manual/sql-functions/numeric-functions/tan", "sql-manual/sql-functions/numeric-functions/tanh", "sql-manual/sql-functions/numeric-functions/asin", @@ -1406,4 +1407,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/numeric-functions/cosh.md b/docs/zh-CN/docs/sql-manual/sql-functions/numeric-functions/cosh.md new file mode 100644 index 00000000000..b5fa4677b75 --- /dev/null +++ b/docs/zh-CN/docs/sql-manual/sql-functions/numeric-functions/cosh.md @@ -0,0 +1,52 @@ +--- +{ + "title": "COSH", + "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. +--> + +## cosh + +### description +#### Syntax + +`DOUBLE cosh(DOUBLE x)` +返回“x”的双曲余弦. + +### example + +``` +mysql> select cosh(0); ++---------+ +| cosh(0) | ++---------+ +| 1 | ++---------+ + +mysql> select cosh(1); ++---------------------+ +| cosh(1) | ++---------------------+ +| 1.5430806348152437 | ++---------------------+ +``` + +### keywords + COSH diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java index 5eac2d885f1..a650b4791dd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java @@ -119,6 +119,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Conv; import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTo; import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTz; import org.apache.doris.nereids.trees.expressions.functions.scalar.Cos; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Cosh; import org.apache.doris.nereids.trees.expressions.functions.scalar.CosineDistance; import org.apache.doris.nereids.trees.expressions.functions.scalar.CountEqual; import org.apache.doris.nereids.trees.expressions.functions.scalar.CreateMap; @@ -543,6 +544,7 @@ public class BuiltinScalarFunctions implements FunctionHelper { scalar(ConvertTo.class, "convert_to"), scalar(ConvertTz.class, "convert_tz"), scalar(Cos.class, "cos"), + scalar(Cosh.class, "cosh"), scalar(CosineDistance.class, "cosine_distance"), scalar(CountEqual.class, "countequal"), scalar(CreateMap.class, "map"), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cosh.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cosh.java new file mode 100644 index 00000000000..6c590c1050e --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Cosh.java @@ -0,0 +1,68 @@ +// 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. + +package org.apache.doris.nereids.trees.expressions.functions.scalar; + +import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; +import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable; +import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression; +import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; +import org.apache.doris.nereids.types.DoubleType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * ScalarFunction 'cosh'. This class is generated by GenerateFunction. + */ +public class Cosh extends ScalarFunction + implements UnaryExpression, ExplicitlyCastableSignature, PropagateNullable { + + public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( + FunctionSignature.ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE) + ); + + /** + * constructor with 1 argument. + */ + public Cosh(Expression arg) { + super("cosh", arg); + } + + /** + * withChildren. + */ + @Override + public Cosh withChildren(List<Expression> children) { + Preconditions.checkArgument(children.size() == 1); + return new Cosh(children.get(0)); + } + + @Override + public List<FunctionSignature> getSignatures() { + return SIGNATURES; + } + + @Override + public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { + return visitor.visitCosh(this, context); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java index fd72711bfe3..1e2538c025a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java @@ -119,6 +119,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Conv; import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTo; import org.apache.doris.nereids.trees.expressions.functions.scalar.ConvertTz; import org.apache.doris.nereids.trees.expressions.functions.scalar.Cos; +import org.apache.doris.nereids.trees.expressions.functions.scalar.Cosh; import org.apache.doris.nereids.trees.expressions.functions.scalar.CosineDistance; import org.apache.doris.nereids.trees.expressions.functions.scalar.CountEqual; import org.apache.doris.nereids.trees.expressions.functions.scalar.CreateMap; @@ -820,6 +821,10 @@ public interface ScalarFunctionVisitor<R, C> { return visitScalarFunction(cos, context); } + default R visitCosh(Cosh cosh, C context) { + return visitScalarFunction(cosh, context); + } + default R visitCosineDistance(CosineDistance cosineDistance, C context) { return visitScalarFunction(cosineDistance, context); } diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index cb3fc47405e..b31fab21b20 100644 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -1280,6 +1280,7 @@ visible_functions = { [['conv'], 'VARCHAR', ['VARCHAR', 'TINYINT', 'TINYINT'], 'ALWAYS_NULLABLE'], [['conv'], 'VARCHAR', ['STRING', 'TINYINT', 'TINYINT'], 'ALWAYS_NULLABLE'], [['cos'], 'DOUBLE', ['DOUBLE'], ''], + [['cosh'], 'DOUBLE', ['DOUBLE'], ''], [['degrees'], 'DOUBLE', ['DOUBLE'], ''], diff --git a/regression-test/data/nereids_function_p0/scalar_function/C.out b/regression-test/data/nereids_function_p0/scalar_function/C.out index e4b81b7eb71..e36fdc7f374 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/C.out +++ b/regression-test/data/nereids_function_p0/scalar_function/C.out @@ -1101,6 +1101,35 @@ varchar13 0.4535961214255773 0.3623577544766736 +-- !sql_cosh_Double -- +\N +1.0050041680558035 +1.0200667556190759 +1.0453385141288605 +1.0810723718384549 +1.1276259652063807 +1.1854652182422676 +1.255169005630943 +1.3374349463048447 +1.4330863854487745 +1.5430806348152437 +1.6685185538222564 +1.8106555673243747 + +-- !sql_cosh_Double_notnull -- +1.0050041680558035 +1.0200667556190759 +1.0453385141288605 +1.0810723718384549 +1.1276259652063807 +1.1854652182422676 +1.255169005630943 +1.3374349463048447 +1.4330863854487745 +1.5430806348152437 +1.6685185538222564 +1.8106555673243747 + -- !km_bool_tint -- 12 diff --git a/regression-test/suites/nereids_function_p0/scalar_function/C.groovy b/regression-test/suites/nereids_function_p0/scalar_function/C.groovy index 62c1c6877c8..bf072c9ad8c 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/C.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/C.groovy @@ -97,6 +97,8 @@ suite("nereids_scalar_fn_C") { qt_sql_convert_tz_DateTimeV2_Varchar_Varchar_notnull "select convert_tz(kdtmv2s1, 'Asia/Shanghai', 'Europe/Sofia') from fn_test_not_nullable order by kdtmv2s1" qt_sql_cos_Double "select cos(kdbl) from fn_test order by kdbl" qt_sql_cos_Double_notnull "select cos(kdbl) from fn_test_not_nullable order by kdbl" + qt_sql_cosh_Double "select cosh(kdbl) from fn_test order by kdbl" + qt_sql_cosh_Double_notnull "select cosh(kdbl) from fn_test_not_nullable order by kdbl" sql "select current_user() from fn_test" sql "select current_user() from fn_test_not_nullable" qt_km_bool_tint "select count(km_bool_tint) from fn_test " --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
