forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_expr_atan.cpp
More file actions
73 lines (64 loc) · 2.25 KB
/
ob_expr_atan.cpp
File metadata and controls
73 lines (64 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SQL_ENG
#include "ob_expr_atan.h"
#include "sql/engine/expr/ob_expr_util.h"
#include "share/object/ob_obj_cast.h"
#include "sql/parser/ob_item_type.h"
//#include "sql/engine/expr/ob_expr_promotion_util.h"
#include "sql/session/ob_sql_session_info.h"
#include <math.h>
using namespace oceanbase::common;
using namespace oceanbase::sql;
namespace oceanbase {
namespace sql {
ObExprAtan::ObExprAtan(ObIAllocator& alloc) : ObFuncExprOperator(alloc, T_FUN_SYS_ATAN, N_ATAN, 1, NOT_ROW_DIMENSION)
{}
ObExprAtan::~ObExprAtan()
{}
int ObExprAtan::calc_result_type1(ObExprResType& type, ObExprResType& type1, common::ObExprTypeCtx& type_ctx) const
{
return calc_trig_function_result_type1(type, type1, type_ctx);
}
int ObExprAtan::calc_result1(ObObj& result, const ObObj& obj, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(OB_ISNULL(expr_ctx.calc_buf_))) {
ret = OB_NOT_INIT;
LOG_WARN("varchar buffer not init", K(ret));
} else if (OB_UNLIKELY(obj.is_null())) {
result.set_null();
} else if (obj.is_number()) {
number::ObNumber res_nmb;
if (OB_FAIL(obj.get_number().atan(res_nmb, *(expr_ctx.calc_buf_)))) {
LOG_WARN("fail to calc atan", K(obj), K(ret), K(res_nmb));
} else {
result.set_number(res_nmb);
}
} else if (obj.is_double()) {
double arg = obj.get_double();
double res = atan(arg);
result.set_double(res);
}
return ret;
}
DEF_CALC_TRIGONOMETRIC_EXPR(atan, false, OB_SUCCESS);
int ObExprAtan::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
{
int ret = OB_SUCCESS;
UNUSED(expr_cg_ctx);
UNUSED(raw_expr);
rt_expr.eval_func_ = calc_atan_expr;
return ret;
}
} // namespace sql
} // namespace oceanbase