提交 05576007 编写于 作者: O obdev 提交者: wangzelin.wzl

Support expr pi in mysql mode

上级 ee48dc4c
......@@ -769,7 +769,7 @@
#define N_LPAD "lpad"
#define N_SPACE "space"
#define N_TRUNCATE "truncate"
#define N_PI "PI"
#define N_PI "pi"
#define N_TIME_STAMP_ADD "timestampadd"
#define N_CONNECT_BY_ROOT "connect_by_root"
#define N_SYS_CONNECT_BY_PATH "sys_connect_by_path"
......
......@@ -346,6 +346,8 @@ ob_set_subtarget(ob_sql engine
engine/expr/ob_expr_repeat.cpp
engine/expr/ob_expr_replace.cpp
engine/expr/ob_expr_translate.cpp
engine/expr/ob_expr_pi.cpp
engine/expr/ob_expr_pi.h
engine/expr/ob_expr_radians.cpp
engine/expr/ob_expr_res_type_map.cpp
engine/expr/ob_expr_result_type_util.cpp
......
......@@ -169,6 +169,7 @@
#include "ob_expr_user_can_access_obj.h"
#include "ob_expr_empty_lob.h"
#include "ob_expr_radians.h"
#include "ob_expr_pi.h"
#include "ob_expr_maketime.h"
#include "ob_expr_to_blob.h"
#include "ob_expr_to_outfile_row.h"
......@@ -629,16 +630,26 @@ static ObExpr::EvalFunc g_expr_eval_functions[] = {
ObExprNlsLower::calc_lower, /* 378 */
ObExprNlsUpper::calc_upper, /* 379 */
ObExprToOutfileRow::to_outfile_str, /* 380 */
NULL, // ObExprIs::calc_is_infinite, /* 381 */
NULL, // ObExprIs::calc_is_nan, /* 382 */
NULL, // ObExprIsNot::calc_is_not_infinite, /* 383 */
NULL, // ObExprIsNot::calc_is_not_nan, /* 384 */
ObExprOracleNullif::eval_nullif_not_null, /* 385 */
NULL, // ObExprNaNvl::eval_nanvl, /* 386 */
ObExprFormat::calc_format_expr, /* 387 */
calc_translate_using_expr, /* 388 */
ObExprQuarter::calc_quater, /* 389 */
ObExprBitLength::calc_bit_length /* 390 */
NULL, // ObExprIs::calc_is_infinite, /* 381 */
NULL, // ObExprIs::calc_is_nan, /* 382 */
NULL, // ObExprIsNot::calc_is_not_infinite, /* 383 */
NULL, // ObExprIsNot::calc_is_not_nan, /* 384 */
ObExprOracleNullif::eval_nullif_not_null, /* 385 */
NULL, // ObExprNaNvl::eval_nanvl, /* 386 */
ObExprFormat::calc_format_expr, /* 387 */
calc_translate_using_expr, /* 388 */
ObExprQuarter::calc_quater, /* 389 */
ObExprBitLength::calc_bit_length, /* 390 */
NULL, // ObExprConvertOracle::calc_convert_oracle_expr, /* 391 */
NULL, // ObExprUnistr::calc_unistr_expr, /* 392 */
NULL, // ObExprAsciistr::calc_asciistr_expr, /* 393 */
NULL, // ObExprAtTimeZone::eval_at_time_zone, /* 394 */
NULL, // ObExprAtLocal::eval_at_local, /* 395 */
NULL, // ObExprToSingleByte::calc_to_single_byte, /* 396 */
NULL, // ObExprToMultiByte::calc_to_multi_byte, /* 397 */
NULL, // ObExprDllUdf::eval_dll_udf, /* 398 */
NULL, // ObExprRawtonhex::calc_rawtonhex_expr, /* 399 */
ObExprPi::eval_pi /* 400 */
};
REG_SER_FUNC_ARRAY(OB_SFA_SQL_EXPR_EVAL, g_expr_eval_functions, ARRAYSIZEOF(g_expr_eval_functions));
......
......@@ -256,6 +256,7 @@
#include "sql/engine/expr/ob_expr_user_can_access_obj.h"
#include "sql/engine/expr/ob_expr_empty_lob.h"
#include "sql/engine/expr/ob_expr_radians.h"
#include "sql/engine/expr/ob_expr_pi.h"
#include "sql/engine/expr/ob_expr_to_outfile_row.h"
#include "sql/engine/expr/ob_expr_format.h"
#include "sql/engine/expr/ob_expr_quarter.h"
......@@ -646,6 +647,7 @@ void ObExprOperatorFactory::register_expr_operators()
REG_OP(ObExprToOutfileRow);
REG_OP(ObExprFormat);
REG_OP(ObExprLog);
REG_OP(ObExprPi);
// register oracle system function
REG_OP_ORCL(ObExprSysConnectByPath);
REG_OP_ORCL(ObExprTimestampNvl);
......
// Copyright 1999-2021 Alibaba Inc. All Rights Reserved.
// Author:
// xiaofeng.lby@alipay.com
// Normalizer:
//
// This file is for implementation of func pi
#define USING_LOG_PREFIX SQL_ENG
#include "sql/engine/expr/ob_expr_pi.h"
#include "sql/session/ob_sql_session_info.h"
using namespace oceanbase::common;
using namespace oceanbase::sql;
namespace oceanbase
{
namespace sql
{
const double ObExprPi::mysql_pi_ = 3.14159265358979323846264338327950288;
ObExprPi::ObExprPi(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_PI, N_PI, 0, NOT_ROW_DIMENSION)
{
}
ObExprPi::~ObExprPi()
{
}
int ObExprPi::calc_result_type0(ObExprResType &type, ObExprTypeCtx &type_ctx) const
{
UNUSED(type_ctx);
type.set_double();
type.set_precision(-1);
type.set_scale(6);
return OB_SUCCESS;
}
int ObExprPi::calc_result0(ObObj &result, ObExprCtx &expr_ctx) const
{
UNUSED(expr_ctx);
int ret = OB_SUCCESS;
result.set_double(mysql_pi_);
return ret;
}
int ObExprPi::eval_pi(const ObExpr &expr, ObEvalCtx &ctx,
ObDatum &expr_datum)
{
UNUSED(expr);
UNUSED(ctx);
int ret = OB_SUCCESS;
expr_datum.set_double(mysql_pi_);
return ret;
}
int ObExprPi::cg_expr(ObExprCGCtx &op_cg_ctx, const ObRawExpr &raw_expr,
ObExpr &rt_expr) const
{
UNUSED(op_cg_ctx);
UNUSED(raw_expr);
rt_expr.eval_func_ = ObExprPi::eval_pi;
return OB_SUCCESS;
}
} //namespace sql
} //namespace oceanbase
// Copyright 1999-2021 Alibaba Inc. All Rights Reserved.
// Author:
// xiaofeng.lby@alipay.com
//
// This file is for implementation of func pi
#ifndef OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_PI_
#define OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_PI_
#include "sql/engine/expr/ob_expr_operator.h"
namespace oceanbase
{
namespace sql
{
class ObExprPi : public ObFuncExprOperator
{
public:
explicit ObExprPi(common::ObIAllocator &alloc);
virtual ~ObExprPi();
virtual int calc_result_type0(ObExprResType &type, common::ObExprTypeCtx &type_ctx) const;
virtual int calc_result0(common::ObObj &result, common::ObExprCtx &expr_ctx) const;
static int eval_pi(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum);
virtual int cg_expr(ObExprCGCtx &op_cg_ctx,
const ObRawExpr &raw_expr,
ObExpr &rt_expr) const override;
private:
const static double mysql_pi_;
DISALLOW_COPY_AND_ASSIGN(ObExprPi);
};
}
}
#endif /* OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_PI_ */
......@@ -425,6 +425,7 @@ typedef enum ObItemType {
// T_FUN_SYS_COT = 710, 710 has ben taken on master
T_FUN_SYS_QUARTER = 711,
T_FUN_SYS_BIT_LENGTH = 712,
T_FUN_SYS_PI = 713,
///< @note add new mysql only function type before this line
T_MYSQL_ONLY_SYS_MAX_OP = 800,
......
......@@ -370,6 +370,7 @@ const char* get_type_name(int type)
// case T_FUN_SYS_COT : return "T_FUN_SYS_COT"; 710 has ben taken on master
case T_FUN_SYS_QUARTER : return "T_FUN_SYS_QUARTER";
case T_FUN_SYS_BIT_LENGTH : return "T_FUN_SYS_BIT_LENGTH";
case T_FUN_SYS_PI : return "T_FUN_SYS_PI";
case T_MYSQL_ONLY_SYS_MAX_OP : return "T_MYSQL_ONLY_SYS_MAX_OP";
case T_FUN_SYS_CONNECT_BY_PATH : return "T_FUN_SYS_CONNECT_BY_PATH";
case T_FUN_SYS_SYSTIMESTAMP : return "T_FUN_SYS_SYSTIMESTAMP";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册