patch 4.0
This commit is contained in:
@ -17,42 +17,56 @@
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
#include "sql/engine/expr/ob_expr_result_type_util.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
using namespace share;
|
||||
namespace sql {
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprToMultiByte::ObExprToMultiByte(ObIAllocator& alloc)
|
||||
ObExprToMultiByte::ObExprToMultiByte(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_TO_MULTI_BYTE, N_TO_MULTI_BYTE, 1, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
{
|
||||
}
|
||||
ObExprToMultiByte::~ObExprToMultiByte()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprToMultiByte::calc_result_type1(ObExprResType& type, ObExprResType& type1, ObExprTypeCtx& type_ctx) const
|
||||
int ObExprToMultiByte::calc_result_type1(ObExprResType &type,
|
||||
ObExprResType &type1,
|
||||
ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObLength length = 0;
|
||||
ObArray<ObExprResType*> params;
|
||||
ObArray<ObExprResType *> params;
|
||||
CK(OB_NOT_NULL(type_ctx.get_session()));
|
||||
OZ(params.push_back(&type1));
|
||||
OZ(aggregate_string_type_and_charset_oracle(*type_ctx.get_session(), params, type, true));
|
||||
// 推导字符集和长度语义
|
||||
OZ(aggregate_string_type_and_charset_oracle(*type_ctx.get_session(),
|
||||
params,
|
||||
type,
|
||||
PREFER_VAR_LEN_CHAR));
|
||||
// clob 是一种比较特殊的类型,当参数为clob时,结果为varchar2, byte 语义
|
||||
if (OB_SUCC(ret) && type1.is_clob()) {
|
||||
type.set_varchar();
|
||||
type.set_length_semantics(LS_BYTE);
|
||||
}
|
||||
CK(LS_CHAR == type.get_length_semantics() || LS_BYTE == type.get_length_semantics());
|
||||
OZ(ObExprResultTypeUtil::deduce_max_string_length_oracle(
|
||||
*type_ctx.get_session(), type1, type.get_length_semantics(), length));
|
||||
// 设置参数的 calc_type
|
||||
OZ(deduce_string_param_calc_type_and_charset(*type_ctx.get_session(),
|
||||
type,
|
||||
params));
|
||||
// 推导结果的长度
|
||||
if (OB_SUCC(ret)) {
|
||||
ObLength length = type1.get_calc_length();
|
||||
int64_t mbmaxlen = 1;
|
||||
if (type1.is_clob()) {
|
||||
type.set_length(length);
|
||||
} else if (LS_BYTE == type.get_length_semantics()) {
|
||||
type.set_length(length * 4);
|
||||
OZ(ObCharset::get_mbmaxlen_by_coll(type.get_collation_type(), mbmaxlen));
|
||||
OX(type.set_length(length * mbmaxlen));
|
||||
} else if (LS_CHAR == type.get_length_semantics()) {
|
||||
type.set_length(length);
|
||||
}
|
||||
}
|
||||
OZ(deduce_string_param_calc_type_and_charset(*type_ctx.get_session(), type, params));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -105,38 +119,6 @@ int calc_to_multi_byte_expr(const ObString &input, const ObCollationType cs_type
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprToMultiByte::calc_result1(ObObj &result,
|
||||
const ObObj &obj,
|
||||
ObExprCtx &expr_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObString src_string;
|
||||
ObCollationType src_collation = obj.get_collation_type();
|
||||
|
||||
if (obj.is_null_oracle()) {
|
||||
result.set_null();
|
||||
} else {
|
||||
CK (OB_NOT_NULL(expr_ctx.calc_buf_));
|
||||
OZ (obj.get_string(src_string));
|
||||
if (OB_SUCC(ret)) {
|
||||
char* buff = NULL;
|
||||
int64_t buff_len = src_string.length() * ObCharset::MAX_MB_LEN;
|
||||
int32_t pos = 0;
|
||||
|
||||
if (OB_ISNULL(buff = static_cast<char*>(expr_ctx.calc_buf_->alloc(buff_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("fail to allocate buffer", K(ret), K(buff_len));
|
||||
} else if (OB_FAIL(calc_to_multi_byte_expr(src_string, src_collation, buff, buff_len, pos))) {
|
||||
LOG_WARN("fail to calc", K(ret));
|
||||
} else {
|
||||
result.set_common_value(ObString(pos, buff));
|
||||
result.set_meta_type(result_type_);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprToMultiByte::cg_expr(ObExprCGCtx &op_cg_ctx,
|
||||
const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
@ -179,5 +161,5 @@ int ObExprToMultiByte::calc_to_multi_byte(const ObExpr &expr,
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user