patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -12,7 +12,7 @@
#define USING_LOG_PREFIX SQL_ENG
#include <string.h>
#include "sql/parser/ob_item_type.h"
#include "objit/common/ob_item_type.h"
#include "sql/engine/expr/ob_expr_hex.h"
//#include "sql/engine/expr/ob_expr_promotion_util.h"
#include "sql/engine/expr/ob_expr_operator.h"
@ -24,48 +24,71 @@
using namespace oceanbase::common;
namespace oceanbase {
namespace sql {
namespace oceanbase
{
namespace sql
{
ObExprHex::ObExprHex(ObIAllocator& alloc) : ObStringExprOperator(alloc, T_FUN_SYS_HEX, N_HEX, 1)
{}
ObExprHex::ObExprHex(ObIAllocator &alloc)
: ObStringExprOperator(alloc, T_FUN_SYS_HEX, N_HEX, 1)
{
}
ObExprHex::~ObExprHex()
{}
{
}
int ObExprHex::calc_result_type1(ObExprResType& type, ObExprResType& text, common::ObExprTypeCtx& type_ctx) const
int ObExprHex::calc_result_type1(ObExprResType &type,
ObExprResType &text,
common::ObExprTypeCtx &type_ctx) const
{
int ret = OB_SUCCESS;
type.set_varchar();
common::ObObjType param_type = text.get_type();
const int32_t mbmaxlen = 4;
if (ObTextType == param_type
|| ObMediumTextType == param_type
|| ObLongTextType == param_type) {
type.set_type(ObLongTextType);
type.set_length(OB_MAX_LONGTEXT_LENGTH / mbmaxlen);
} else if (ObTinyTextType ==param_type) {
type.set_type(ObTextType);
type.set_length(OB_MAX_TEXT_LENGTH / mbmaxlen);
} else {
type.set_varchar();
}
type.set_collation_level(common::CS_LEVEL_COERCIBLE);
type.set_collation_type(get_default_collation_type(type.get_type(), *type_ctx.get_session()));
// calc length now...
common::ObObjType param_type = text.get_type();
//calc length now...
common::ObLength length = -1;
if (ob_is_string_type(param_type) || ob_is_enum_or_set_type(param_type)) {
length = 2 * text.get_length() + 1;
} else if (ob_is_numeric_type(param_type) || ob_is_temporal_type(param_type)) {
length = 300; // enough !
} else if (ob_is_numeric_type(param_type) ||
ob_is_temporal_type(param_type)) {
length = 300;//enough !
}
if (length <= 0 || length > common::OB_MAX_VARCHAR_LENGTH) {
length = common::OB_MAX_VARCHAR_LENGTH;
if (type.is_varchar()) {
if (length <= 0 || length > common::OB_MAX_VARCHAR_LENGTH) {
length = common::OB_MAX_VARCHAR_LENGTH;
}
type.set_length(length);
}
type.set_length(length);
if (ob_is_enum_or_set_type(param_type)) {
text.set_calc_type(common::ObVarcharType);
}
CK(NULL != type_ctx.get_session());
if (OB_SUCC(ret) && type_ctx.get_session()->use_static_typing_engine()) {
if (OB_SUCC(ret)) {
if (text.is_number()) {
// accept number
} else if (text.get_type() == ObYearType || text.is_numeric_type()) {
text.set_calc_type(ObUInt64Type);
type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_NO_RANGE_CHECK);
} else {
text.set_calc_type(ObVarcharType);
if (!ob_is_text_tc(param_type)) {
text.set_calc_type(ObVarcharType);
}
ObExprResType tmp_type;
OZ(aggregate_charsets_for_string_result(tmp_type, &text, 1, type_ctx.get_coll_type()));
if (OB_SUCC(ret)) {
@ -77,19 +100,21 @@ int ObExprHex::calc_result_type1(ObExprResType& type, ObExprResType& text, commo
return ret;
}
int ObExprHex::calc(ObObj& result, const ObObj& text, ObCastCtx& cast_ctx)
int ObExprHex::calc(ObObj &result,
const ObObj &text,
ObCastCtx &cast_ctx)
{
int ret = OB_SUCCESS;
if (text.is_null()) {
result.set_null();
} else if (text.get_type() == ObYearType || text.is_numeric_type()) {
} else if (text.get_type() == ObYearType
|| text.is_numeric_type()) {
uint64_t uint_val = 0;
if (OB_FAIL(ObExprHex::get_uint64(text, cast_ctx, uint_val))) {
LOG_WARN("fail to get uint64", K(ret), K(text));
} else if (OB_FAIL(ObHexUtils::hex_for_mysql(uint_val, cast_ctx, result))) {
LOG_WARN("fail to convert to hex", K(ret), K(uint_val));
} else {
}
} else {}
} else {
ObString str;
EXPR_GET_VARCHAR_V2(text, str);
@ -98,32 +123,12 @@ int ObExprHex::calc(ObObj& result, const ObObj& text, ObCastCtx& cast_ctx)
LOG_WARN("invalid input format. need varchar.", K(ret), K(text));
} else if (OB_FAIL(ObHexUtils::hex(str, cast_ctx, result))) {
LOG_WARN("fail to convert to hex", K(ret), K(str));
} else {
}
} else {}
}
return ret;
}
int ObExprHex::calc_result1(common::ObObj& result, const ObObj& text, ObExprCtx& expr_ctx) const
{
int ret = OB_SUCCESS;
if (OB_ISNULL(expr_ctx.calc_buf_)) {
ret = OB_NOT_INIT;
LOG_WARN("varchar buffer not init", K(ret));
} else {
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
cast_ctx.dest_collation_ = text.get_collation_type();
if (OB_FAIL(calc(result, text, cast_ctx))) {
LOG_WARN("fail to calc", K(ret), K(text));
} else if (OB_LIKELY(!result.is_null())) {
result.set_collation(result_type_);
} else {
}
}
return ret;
}
int ObExprHex::get_uint64(const ObObj& obj, ObCastCtx& cast_ctx, uint64_t& out)
int ObExprHex::get_uint64(const ObObj &obj, ObCastCtx &cast_ctx, uint64_t &out)
{
int ret = OB_SUCCESS;
out = 0;
@ -137,7 +142,7 @@ int ObExprHex::get_uint64(const ObObj& obj, ObCastCtx& cast_ctx, uint64_t& out)
return ret;
}
int ObExprHex::number_uint64(const number::ObNumber& num_val, uint64_t& out)
int ObExprHex::number_uint64(const number::ObNumber &num_val, uint64_t &out)
{
int ret = OB_SUCCESS;
int64_t tmp_int = 0;
@ -158,17 +163,17 @@ int ObExprHex::number_uint64(const number::ObNumber& num_val, uint64_t& out)
return ret;
}
int ObExprHex::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& rt_expr) const
int ObExprHex::cg_expr(ObExprCGCtx &, const ObRawExpr &, ObExpr &rt_expr) const
{
int ret = OB_SUCCESS;
rt_expr.eval_func_ = &ObExprHex::eval_hex;
return ret;
}
int ObExprHex::eval_hex(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
int ObExprHex::eval_hex(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
int ret = OB_SUCCESS;
ObDatum* arg = NULL;
ObDatum *arg = NULL;
if (OB_FAIL(expr.eval_param_value(ctx, arg))) {
LOG_WARN("evaluate parameter value failed", K(ret));
} else if (arg->is_null()) {
@ -183,7 +188,7 @@ int ObExprHex::eval_hex(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
val = arg->get_uint();
}
const int64_t max_len = sizeof(uint64_t) * 2 + 1;
char* buf = expr.get_str_res_mem(ctx, max_len);
char *buf = expr.get_str_res_mem(ctx, max_len);
if (OB_ISNULL(buf)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("get memory failed", K(ret));
@ -197,12 +202,14 @@ int ObExprHex::eval_hex(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
}
}
} else {
if (OB_FAIL(ObDatumHexUtils::hex(expr, arg->get_string(), ctx, ctx.get_reset_tmp_alloc(), expr_datum))) {
ObEvalCtx::TempAllocGuard alloc_guard(ctx);
if (OB_FAIL(ObDatumHexUtils::hex(expr, arg->get_string(), ctx,
alloc_guard.get_allocator(), expr_datum))) {
LOG_WARN("to hex failed", K(ret));
}
}
}
return ret;
}
} // namespace sql
} // namespace oceanbase
}
}