patch 4.0
This commit is contained in:
@ -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_hextoraw.h"
|
||||
#include "sql/engine/expr/ob_expr_unhex.h"
|
||||
#include "sql/engine/expr/ob_datum_cast.h"
|
||||
@ -22,62 +22,61 @@
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
using namespace oceanbase::common;
|
||||
|
||||
namespace oceanbase {
|
||||
namespace sql {
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprHextoraw::ObExprHextoraw(ObIAllocator& alloc) : ObStringExprOperator(alloc, T_FUN_SYS_HEXTORAW, N_HEXTORAW, 1)
|
||||
ObExprHextoraw::ObExprHextoraw(ObIAllocator &alloc)
|
||||
: ObStringExprOperator(alloc, T_FUN_SYS_HEXTORAW, N_HEXTORAW, 1)
|
||||
{
|
||||
disable_operand_auto_cast();
|
||||
}
|
||||
|
||||
ObExprHextoraw::~ObExprHextoraw()
|
||||
{}
|
||||
|
||||
int ObExprHextoraw::calc_result_type1(ObExprResType& type, ObExprResType& text, ObExprTypeCtx& type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
|
||||
type.set_collation_level(common::CS_LEVEL_NUMERIC);
|
||||
type.set_collation_type(common::CS_TYPE_BINARY);
|
||||
type.set_raw();
|
||||
|
||||
common::ObObjType param_type = text.get_type();
|
||||
common::ObLength length = -1;
|
||||
const int64_t oracle_max_avail_len = 40;
|
||||
if (ob_is_numeric_type(param_type)) {
|
||||
length = oracle_max_avail_len; // enough !
|
||||
} else if (ob_is_string_type(param_type)) {
|
||||
length = text.get_length() / 2 + (text.get_length() % 2);
|
||||
}
|
||||
if (length <= 0 || length > common::OB_MAX_VARCHAR_LENGTH) {
|
||||
length = common::OB_MAX_VARCHAR_LENGTH;
|
||||
}
|
||||
type.set_length(length);
|
||||
return common::OB_SUCCESS;
|
||||
}
|
||||
|
||||
int ObExprHextoraw::calc_result1(common::ObObj& result, const ObObj& text, ObExprCtx& expr_ctx) const
|
||||
int ObExprHextoraw::calc_result_type1(ObExprResType &type, ObExprResType &text,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(expr_ctx.calc_buf_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("varchar buffer not init", K(ret));
|
||||
|
||||
common::ObObjType param_type = text.get_type();
|
||||
if (ob_is_text_tc(param_type)) {
|
||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||
LOG_WARN("lob as param not support in hextoraw", K(ret), K(param_type));
|
||||
} else if (!ob_is_null(param_type)
|
||||
&& !ob_is_raw(param_type)
|
||||
&& !ob_is_string_tc(param_type)
|
||||
&& !ob_is_numeric_type(param_type)) {
|
||||
// TODO:@xiaofeng.lby, to support other param types of hextoraw
|
||||
ret = OB_ERR_INVALID_HEX_NUMBER;
|
||||
LOG_WARN("invalid hex number", K(ret), K(param_type), K(text));
|
||||
} else {
|
||||
EXPR_DEFINE_CAST_CTX(expr_ctx, CM_NONE);
|
||||
cast_ctx.expect_obj_collation_ = CS_TYPE_BINARY;
|
||||
if (OB_FAIL(ObHexUtils::hextoraw(text, cast_ctx, result))) {
|
||||
LOG_WARN("fail to calc", K(ret), K(text));
|
||||
} else if (OB_LIKELY(!result.is_null())) {
|
||||
result.set_collation(result_type_);
|
||||
common::ObLength length = -1;
|
||||
const int64_t oracle_max_avail_len = 40;
|
||||
type.set_collation_level(common::CS_LEVEL_NUMERIC);
|
||||
type.set_collation_type(common::CS_TYPE_BINARY);
|
||||
type.set_raw();
|
||||
if (ob_is_numeric_type(param_type)) {
|
||||
length = oracle_max_avail_len;//enough !
|
||||
} else if (ob_is_string_tc(param_type)) {
|
||||
length = text.get_length() / 2 + (text.get_length() % 2);
|
||||
}
|
||||
if (length <= 0 || length > common::OB_MAX_VARCHAR_LENGTH) {
|
||||
length = common::OB_MAX_VARCHAR_LENGTH;
|
||||
}
|
||||
type.set_length(length);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprHextoraw::calc_hextoraw_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
|
||||
int ObExprHextoraw::calc_hextoraw_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* arg = NULL;
|
||||
ObDatum *arg = NULL;
|
||||
if (OB_UNLIKELY(1 != expr.arg_cnt_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid arg cnt", K(ret), K(expr.arg_cnt_));
|
||||
@ -85,14 +84,15 @@ int ObExprHextoraw::calc_hextoraw_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDat
|
||||
LOG_WARN("eval arg failed", K(ret));
|
||||
} else if (arg->is_null()) {
|
||||
res_datum.set_null();
|
||||
} else if (OB_FAIL(ObDatumHexUtils::hextoraw(
|
||||
expr, *arg, expr.args_[0]->datum_meta_.type_, expr.args_[0]->datum_meta_.cs_type_, ctx, res_datum))) {
|
||||
} else if (OB_FAIL(ObDatumHexUtils::hextoraw(expr, *arg, expr.args_[0]->datum_meta_.type_,
|
||||
expr.args_[0]->datum_meta_.cs_type_, ctx, res_datum))) {
|
||||
LOG_WARN("hextoraw failed", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprHextoraw::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprHextoraw::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(expr_cg_ctx);
|
||||
@ -101,5 +101,5 @@ int ObExprHextoraw::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr,
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user