patch 4.0
This commit is contained in:
@ -16,14 +16,18 @@
|
||||
#include "sql/engine/expr/ob_expr_result_type_util.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
|
||||
namespace oceanbase {
|
||||
using namespace oceanbase::common;
|
||||
namespace sql {
|
||||
ObExprDesHexStr::ObExprDesHexStr(ObIAllocator& alloc)
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace oceanbase::common;
|
||||
namespace sql
|
||||
{
|
||||
ObExprDesHexStr::ObExprDesHexStr(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_DES_HEX_STR, N_DES_HEX_STR, 1, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprDesHexStr::calc_result_type1(ObExprResType& type, ObExprResType& type1, common::ObExprTypeCtx& type_ctx) const
|
||||
int ObExprDesHexStr::calc_result_type1(ObExprResType &type, ObExprResType &type1,
|
||||
common::ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
int ret = common::OB_SUCCESS;
|
||||
@ -41,50 +45,38 @@ int ObExprDesHexStr::calc_result_type1(ObExprResType& type, ObExprResType& type1
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprDesHexStr::calc_result1(common::ObObj& result, const common::ObObj& obj, common::ObExprCtx& expr_ctx) const
|
||||
{
|
||||
int ret = common::OB_SUCCESS;
|
||||
ObString obj_string;
|
||||
|
||||
if (!obj.is_valid_type() || OB_ISNULL(expr_ctx.calc_buf_)) {
|
||||
ret = common::OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument.", K(ret), K(obj.is_valid_type()), KP(expr_ctx.calc_buf_));
|
||||
} else {
|
||||
obj_string = obj.get_varchar();
|
||||
if (OB_FAIL(deserialize_hex_cstr(obj_string.ptr(), obj_string.length(), *expr_ctx.calc_buf_, result))) {
|
||||
LOG_WARN("deserialize_hex_cstr obj_string failed.", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprDesHexStr::deserialize_hex_cstr(
|
||||
const char* buf, int64_t buf_len, common::ObExprStringBuf& string_buf, common::ObObj& obj)
|
||||
int ObExprDesHexStr::deserialize_hex_cstr(const char *buf,
|
||||
int64_t buf_len,
|
||||
common::ObExprStringBuf &string_buf,
|
||||
common::ObObj &obj)
|
||||
{
|
||||
int ret = common::OB_SUCCESS;
|
||||
|
||||
int64_t pos = 0;
|
||||
int64_t ret_len = 0;
|
||||
char* res_buf = NULL;
|
||||
char *res_buf = NULL;
|
||||
if (OB_ISNULL(buf) || buf_len < 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid arguments.", K(ret), K(buf_len));
|
||||
} else if (NULL == (res_buf = static_cast<char*>(string_buf.alloc(buf_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_ERROR("fail to allocate memory for res_buf.", K(ret), K(buf_len));
|
||||
} else if (buf_len != (ret_len = common::str_to_hex(
|
||||
buf, static_cast<int32_t>(buf_len), res_buf, static_cast<int32_t>(buf_len)))) {
|
||||
} else if (buf_len != (ret_len = common::str_to_hex(buf,
|
||||
static_cast<int32_t>(buf_len),
|
||||
res_buf,
|
||||
static_cast<int32_t>(buf_len)))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("transfer str to hex failed.", K(ret), K(buf), K(buf_len), K(ret_len));
|
||||
} else if (OB_FAIL(obj.deserialize(res_buf, ret_len / 2, pos))) {
|
||||
LOG_WARN("deserialize obj failed.", K(ret), K(buf), K(buf_len), K(pos));
|
||||
LOG_WARN("transfer str to hex failed.",
|
||||
K(ret), K(buf), K(buf_len), K(ret_len));
|
||||
} else if (OB_FAIL(obj.deserialize(res_buf, ret_len/2, pos))) {
|
||||
LOG_WARN("deserialize obj failed.",
|
||||
K(ret), K(buf), K(buf_len), K(pos));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprDesHexStr::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& expr) const
|
||||
int ObExprDesHexStr::cg_expr(ObExprCGCtx &, const ObRawExpr &, ObExpr &expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
CK(1 == expr.arg_cnt_);
|
||||
@ -92,11 +84,13 @@ int ObExprDesHexStr::cg_expr(ObExprCGCtx&, const ObRawExpr&, ObExpr& expr) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprDesHexStr::eval_des_hex_str(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
int ObExprDesHexStr::eval_des_hex_str(
|
||||
const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* in = NULL;
|
||||
ObIAllocator& alloc = ctx.get_reset_tmp_alloc();
|
||||
ObDatum *in= NULL;
|
||||
ObEvalCtx::TempAllocGuard alloc_guard(ctx);
|
||||
ObIAllocator &alloc = alloc_guard.get_allocator();
|
||||
ObObj obj;
|
||||
if (OB_FAIL(expr.eval_param_value(ctx, in))) {
|
||||
LOG_WARN("evaluate parameter failed", K(ret));
|
||||
@ -106,7 +100,7 @@ int ObExprDesHexStr::eval_des_hex_str(const ObExpr& expr, ObEvalCtx& ctx, ObDatu
|
||||
LOG_WARN("unhex or deserialize failed", K(ret));
|
||||
} else {
|
||||
const int64_t len = std::max(128, in->len_ * 2);
|
||||
char* buf = expr.get_str_res_mem(ctx, len);
|
||||
char *buf = expr.get_str_res_mem(ctx, len);
|
||||
int64_t pos = 0;
|
||||
if (OB_ISNULL(buf)) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
@ -120,5 +114,5 @@ int ObExprDesHexStr::eval_des_hex_str(const ObExpr& expr, ObEvalCtx& ctx, ObDatu
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user