[FEAT MERGE] information_schema enhence
This commit is contained in:
@ -525,11 +525,27 @@ int ObExprCast::get_cast_type(const ObExprResType param_type2,
|
||||
ParseNode parse_node;
|
||||
parse_node.value_ = param.get_int();
|
||||
ObObjType obj_type = static_cast<ObObjType>(parse_node.int16_values_[OB_NODE_CAST_TYPE_IDX]);
|
||||
bool is_explicit_cast = CM_IS_EXPLICIT_CAST(cast_mode);
|
||||
dst_type.set_collation_type(static_cast<ObCollationType>(parse_node.int16_values_[OB_NODE_CAST_COLL_IDX]));
|
||||
dst_type.set_type(obj_type);
|
||||
if (ob_is_string_type(obj_type) || ob_is_lob_locator(obj_type)) {
|
||||
int64_t maxblen = 4;
|
||||
if (ob_is_lob_locator(obj_type)) {
|
||||
// cast(x as char(10)) or cast(x as binary(10))
|
||||
dst_type.set_full_length(parse_node.int32_values_[OB_NODE_CAST_C_LEN_IDX], param_type2.get_accuracy().get_length_semantics());
|
||||
} else if (ob_is_string_type(obj_type)) {
|
||||
dst_type.set_full_length(parse_node.int32_values_[OB_NODE_CAST_C_LEN_IDX], param_type2.get_accuracy().get_length_semantics());
|
||||
if (lib::is_mysql_mode() && is_explicit_cast && !dst_type.is_binary() && !dst_type.is_varbinary()) {
|
||||
if (dst_type.get_length() > OB_MAX_CAST_CHAR_VARCHAR_LENGTH && dst_type.get_length() <= OB_MAX_CAST_CHAR_TEXT_LENGTH) {
|
||||
dst_type.set_type(ObTextType);
|
||||
dst_type.set_length(OB_MAX_CAST_CHAR_TEXT_LENGTH);
|
||||
} else if (dst_type.get_length() > OB_MAX_CAST_CHAR_TEXT_LENGTH && dst_type.get_length() <= OB_MAX_CAST_CHAR_MEDIUMTEXT_LENGTH) {
|
||||
dst_type.set_type(ObMediumTextType);
|
||||
dst_type.set_length(OB_MAX_CAST_CHAR_MEDIUMTEXT_LENGTH);
|
||||
} else if (dst_type.get_length() > OB_MAX_CAST_CHAR_MEDIUMTEXT_LENGTH) {
|
||||
dst_type.set_type(ObLongTextType);
|
||||
dst_type.set_length(OB_MAX_LONGTEXT_LENGTH / maxblen);
|
||||
}
|
||||
}
|
||||
} else if (ob_is_raw(obj_type)) {
|
||||
dst_type.set_length(parse_node.int32_values_[OB_NODE_CAST_C_LEN_IDX]);
|
||||
} else if (ob_is_extend(obj_type)) {
|
||||
|
||||
73
src/sql/engine/expr/ob_expr_current_user_priv.cpp
Normal file
73
src/sql/engine/expr/ob_expr_current_user_priv.cpp
Normal file
@ -0,0 +1,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 "sql/engine/expr/ob_expr_current_user_priv.h"
|
||||
#include "sql/engine/ob_physical_plan_ctx.h"
|
||||
#include "lib/mysqlclient/ob_mysql_result.h"
|
||||
#include "lib/mysqlclient/ob_mysql_transaction.h"
|
||||
#include "lib/string/ob_sql_string.h"
|
||||
#include "lib/mysqlclient/ob_mysql_proxy.h"
|
||||
#include "lib/oblog/ob_log_module.h"
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::sql;
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
ObExprCurrentUserPriv::ObExprCurrentUserPriv(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_CURRENT_USER_PRIV,
|
||||
N_CURRENT_USER_PRIV, 0,
|
||||
NOT_ROW_DIMENSION) {
|
||||
}
|
||||
|
||||
ObExprCurrentUserPriv::~ObExprCurrentUserPriv() {
|
||||
}
|
||||
|
||||
int ObExprCurrentUserPriv::calc_result_type0(ObExprResType &type,
|
||||
ObExprTypeCtx &type_ctx) const {
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(type_ctx);
|
||||
type.set_type(ObIntType);
|
||||
type.set_precision(ObAccuracy::DDL_DEFAULT_ACCURACY[ObIntType].precision_);
|
||||
type.set_scale(ObAccuracy::DDL_DEFAULT_ACCURACY[ObIntType].scale_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprCurrentUserPriv::eval_current_user_priv(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum) {
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(expr);
|
||||
const ObSQLSessionInfo *session_info = NULL;
|
||||
if (OB_ISNULL(session_info = ctx.exec_ctx_.get_my_session())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session info is null", K(ret));
|
||||
} else {
|
||||
const ObPrivSet user_priv_set = session_info->get_user_priv_set();
|
||||
expr_datum.set_int(user_priv_set);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprCurrentUserPriv::cg_expr(ObExprCGCtx &op_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
UNUSED(raw_expr);
|
||||
UNUSED(op_cg_ctx);
|
||||
rt_expr.eval_func_ = ObExprCurrentUserPriv::eval_current_user_priv;
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
}/* ns sql*/
|
||||
}/* ns oceanbase */
|
||||
38
src/sql/engine/expr/ob_expr_current_user_priv.h
Normal file
38
src/sql/engine/expr/ob_expr_current_user_priv.h
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_CURRENT_USER_PRIV_
|
||||
#define OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_CURRENT_USER_PRIV_
|
||||
|
||||
#include "sql/engine/expr/ob_expr_operator.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
class ObExprCurrentUserPriv : public ObFuncExprOperator
|
||||
{
|
||||
public:
|
||||
explicit ObExprCurrentUserPriv(common::ObIAllocator &alloc);
|
||||
virtual ~ObExprCurrentUserPriv();
|
||||
virtual int calc_result_type0(ObExprResType &type,
|
||||
common::ObExprTypeCtx &type_ctx) const;
|
||||
static int eval_current_user_priv(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:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObExprCurrentUserPriv);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif /* OCEANBASE_SQL_ENGINE_EXPR_OB_EXPR_CURRENT_USER_PRIV_ */
|
||||
@ -21,6 +21,7 @@
|
||||
#include "ob_expr_regexp_count.h"
|
||||
#include "ob_expr_conv.h"
|
||||
#include "ob_expr_current_user.h"
|
||||
#include "ob_expr_current_user_priv.h"
|
||||
#include "ob_expr_cur_time.h"
|
||||
#include "ob_expr_database.h"
|
||||
#include "ob_expr_date.h"
|
||||
@ -296,6 +297,7 @@
|
||||
#include "ob_expr_st_contains.h"
|
||||
#include "ob_expr_st_within.h"
|
||||
#include "ob_expr_priv_st_asewkb.h"
|
||||
#include "ob_expr_sql_mode_convert.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
@ -895,7 +897,6 @@ static ObExpr::EvalFunc g_expr_eval_functions[] = {
|
||||
#endif
|
||||
ObExprDayName::calc_dayname, /* 510 */
|
||||
ObExprNullif::eval_nullif_enumset, /* 511 */
|
||||
|
||||
ObExprSTIntersects::eval_st_intersects, /* 512 */
|
||||
ObExprSTX::eval_st_x, /* 513 */
|
||||
ObExprSTY::eval_st_y, /* 514 */
|
||||
@ -941,7 +942,9 @@ static ObExpr::EvalFunc g_expr_eval_functions[] = {
|
||||
ObExprSTWithin::eval_st_within, /* 554 */
|
||||
ObExprPrivSTTransform::eval_priv_st_transform, /* 555 */
|
||||
ObExprSTGeomFromText::eval_st_geomfromtext, /* 556 */
|
||||
ObExprSTArea::eval_st_area /* 557 */
|
||||
ObExprSTArea::eval_st_area, /* 557 */
|
||||
ObExprCurrentUserPriv::eval_current_user_priv, /* 558 */
|
||||
ObExprSqlModeConvert::sql_mode_convert, /* 559 */
|
||||
};
|
||||
|
||||
static ObExpr::EvalBatchFunc g_expr_eval_batch_functions[] = {
|
||||
|
||||
@ -46,6 +46,7 @@
|
||||
#include "sql/engine/expr/ob_expr_convert.h"
|
||||
#include "sql/engine/expr/ob_expr_coalesce.h"
|
||||
#include "sql/engine/expr/ob_expr_current_user.h"
|
||||
#include "sql/engine/expr/ob_expr_current_user_priv.h"
|
||||
#include "sql/engine/expr/ob_expr_nvl.h"
|
||||
#include "sql/engine/expr/ob_expr_concat.h"
|
||||
#include "sql/engine/expr/ob_expr_concat_ws.h"
|
||||
@ -370,6 +371,7 @@
|
||||
#include "sql/engine/expr/ob_expr_st_contains.h"
|
||||
#include "sql/engine/expr/ob_expr_st_within.h"
|
||||
#include "sql/engine/expr/ob_expr_priv_st_asewkb.h"
|
||||
#include "sql/engine/expr/ob_expr_sql_mode_convert.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
namespace oceanbase
|
||||
@ -580,6 +582,7 @@ void ObExprOperatorFactory::register_expr_operators()
|
||||
REG_OP(ObExprNvl);
|
||||
REG_OP(ObExprConcat);
|
||||
REG_OP(ObExprCurrentUser);
|
||||
REG_OP(ObExprCurrentUserPriv);
|
||||
REG_OP(ObExprYear);
|
||||
REG_OP(ObExprOracleDecode);
|
||||
REG_OP(ObExprOracleTrunc);
|
||||
@ -882,6 +885,7 @@ void ObExprOperatorFactory::register_expr_operators()
|
||||
REG_OP(ObExprStatementDigestText);
|
||||
REG_OP(ObExprTimestampToScn);
|
||||
REG_OP(ObExprScnToTimestamp);
|
||||
REG_OP(ObExprSqlModeConvert);
|
||||
#if defined(ENABLE_DEBUG_LOG) || !defined(NDEBUG)
|
||||
// convert input value into an OceanBase error number and throw out as exception
|
||||
REG_OP(ObExprErrno);
|
||||
|
||||
83
src/sql/engine/expr/ob_expr_sql_mode_convert.cpp
Normal file
83
src/sql/engine/expr/ob_expr_sql_mode_convert.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* 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 "sql/engine/expr/ob_expr_sql_mode_convert.h"
|
||||
#include "common/sql_mode/ob_sql_mode_utils.h"
|
||||
|
||||
using namespace oceanbase::common;
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprSqlModeConvert::ObExprSqlModeConvert(ObIAllocator &alloc)
|
||||
: ObStringExprOperator(alloc, T_FUN_SYS_SQL_MODE_CONVERT, N_SQL_MODE_CONVERT, 1)
|
||||
{
|
||||
}
|
||||
|
||||
ObExprSqlModeConvert::~ObExprSqlModeConvert()
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprSqlModeConvert::calc_result_type1(ObExprResType &type,
|
||||
ObExprResType &type1,
|
||||
common::ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
UNUSED(type1);
|
||||
|
||||
int ret = OB_SUCCESS;
|
||||
type.set_varchar();
|
||||
type.set_default_collation_type();
|
||||
type.set_collation_level(CS_LEVEL_SYSCONST);
|
||||
type.set_length(static_cast<common::ObLength>(OB_MAX_SYS_VAR_VAL_LENGTH));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprSqlModeConvert::sql_mode_convert(const ObExpr &expr,
|
||||
ObEvalCtx &ctx,
|
||||
ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum *arg = NULL;
|
||||
if (OB_FAIL(expr.args_[0]->eval(ctx, arg))) {
|
||||
LOG_WARN("eval arg failed", K(ret));
|
||||
} else if (arg->is_null()) {
|
||||
expr_datum.set_null();
|
||||
} else {
|
||||
ObObj int_value;
|
||||
ObObj str_value;
|
||||
int_value.set_uint64(arg->get_uint64());
|
||||
if (OB_FAIL(common::ob_sql_mode_to_str(int_value, str_value, &ctx.get_expr_res_alloc()))) {
|
||||
LOG_WARN("convert sql mode failed", K(ret));
|
||||
} else {
|
||||
expr_datum.set_string(str_value.get_string());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprSqlModeConvert::cg_expr(ObExprCGCtx &op_cg_ctx,
|
||||
const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
UNUSED(raw_expr);
|
||||
UNUSED(op_cg_ctx);
|
||||
rt_expr.eval_func_ = ObExprSqlModeConvert::sql_mode_convert;
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
35
src/sql/engine/expr/ob_expr_sql_mode_convert.h
Normal file
35
src/sql/engine/expr/ob_expr_sql_mode_convert.h
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _OB_EXPR_SQL_MODE_CONVERT_H
|
||||
#define _OB_EXPR_SQL_MODE_CONVERT_H
|
||||
|
||||
#include "sql/engine/expr/ob_expr_operator.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
class ObExprSqlModeConvert : public ObStringExprOperator
|
||||
{
|
||||
public:
|
||||
explicit ObExprSqlModeConvert(common::ObIAllocator &alloc);
|
||||
virtual ~ObExprSqlModeConvert();
|
||||
virtual int calc_result_type1(ObExprResType &type, ObExprResType &type1, common::ObExprTypeCtx &type_ctx) const;
|
||||
static int sql_mode_convert(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:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObExprSqlModeConvert);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user