Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature](function) support cosh math function #30602

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions be/src/vec/functions/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -388,6 +393,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>();
Expand Down
52 changes: 52 additions & 0 deletions docs/en/docs/sql-manual/sql-functions/numeric-functions/cosh.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion docs/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/asin",
"sql-manual/sql-functions/numeric-functions/acos",
Expand Down Expand Up @@ -1405,4 +1406,4 @@
]
}
]
}
}
52 changes: 52 additions & 0 deletions docs/zh-CN/docs/sql-manual/sql-functions/numeric-functions/cosh.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
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;
Expand Down Expand Up @@ -542,6 +543,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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
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;
Expand Down Expand Up @@ -819,6 +820,10 @@ default R visitCos(Cos cos, C context) {
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);
}
Expand Down
1 change: 1 addition & 0 deletions gensrc/script/doris_builtins_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@
[['conv'], 'VARCHAR', ['VARCHAR', 'TINYINT', 'TINYINT'], 'ALWAYS_NULLABLE'],
[['conv'], 'VARCHAR', ['STRING', 'TINYINT', 'TINYINT'], 'ALWAYS_NULLABLE'],
[['cos'], 'DOUBLE', ['DOUBLE'], ''],
[['cosh'], 'DOUBLE', ['DOUBLE'], ''],

[['degrees'], 'DOUBLE', ['DOUBLE'], ''],

Expand Down
29 changes: 29 additions & 0 deletions regression-test/data/nereids_function_p0/scalar_function/C.out
Original file line number Diff line number Diff line change
Expand Up @@ -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

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