diff --git a/deps/oblib/src/lib/ob_name_def.h b/deps/oblib/src/lib/ob_name_def.h index 09a63a84f755576eabe30ac127bca05b497b07dc..5a33c176842eff7f2482b892830a5ba4fbe0b311 100644 --- a/deps/oblib/src/lib/ob_name_def.h +++ b/deps/oblib/src/lib/ob_name_def.h @@ -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" diff --git a/src/sql/CMakeLists.txt b/src/sql/CMakeLists.txt index 0d9456790102ee7a864d04ec399f6b39f99dc6e4..3e4fe608abd654b28e44ccad97b67c947c1dbd23 100644 --- a/src/sql/CMakeLists.txt +++ b/src/sql/CMakeLists.txt @@ -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 diff --git a/src/sql/engine/expr/ob_expr_eval_functions.cpp b/src/sql/engine/expr/ob_expr_eval_functions.cpp index 82f93c1807e343903739ec16c674d3a0455fcee4..c1ab093a70721674f1765810716b19fe96997f7e 100644 --- a/src/sql/engine/expr/ob_expr_eval_functions.cpp +++ b/src/sql/engine/expr/ob_expr_eval_functions.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)); diff --git a/src/sql/engine/expr/ob_expr_operator_factory.cpp b/src/sql/engine/expr/ob_expr_operator_factory.cpp index 797f27248a93317121f4998bb79fff0ff622dc4a..f6b264483f6e2e9ebbf449aa2f55352b704a78a3 100644 --- a/src/sql/engine/expr/ob_expr_operator_factory.cpp +++ b/src/sql/engine/expr/ob_expr_operator_factory.cpp @@ -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); diff --git a/src/sql/engine/expr/ob_expr_pi.cpp b/src/sql/engine/expr/ob_expr_pi.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c0727511af55d506c7d10304948190e795ed1d5 --- /dev/null +++ b/src/sql/engine/expr/ob_expr_pi.cpp @@ -0,0 +1,68 @@ +// 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 diff --git a/src/sql/engine/expr/ob_expr_pi.h b/src/sql/engine/expr/ob_expr_pi.h new file mode 100644 index 0000000000000000000000000000000000000000..641cc592f79b7765f26dca02446f914800ad5aaa --- /dev/null +++ b/src/sql/engine/expr/ob_expr_pi.h @@ -0,0 +1,34 @@ +// 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_ */ diff --git a/src/sql/parser/ob_item_type.h b/src/sql/parser/ob_item_type.h index b2c73062d0df3058e5226fdf7f7e684ff3fbd030..1a49fa2b1c0fb6b92507a7a1601891d31701f258 100644 --- a/src/sql/parser/ob_item_type.h +++ b/src/sql/parser/ob_item_type.h @@ -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, diff --git a/src/sql/parser/type_name.c b/src/sql/parser/type_name.c index 392218671f9b49e2142a4ba93448fcd80769301f..beb5a643f103a68c499684d2f930368db78b3c93 100644 --- a/src/sql/parser/type_name.c +++ b/src/sql/parser/type_name.c @@ -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";