fix bug of weight_string
This commit is contained in:
@ -19475,7 +19475,7 @@ static size_t ob_strnxfrm_gb18030(const ObCharsetInfo *cs, uchar *dst,
|
|||||||
++src;
|
++src;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ob_strxfrm_pad(cs, ds, dst, de, nweights, flags);
|
return ob_strxfrm_pad_desc_and_reverse(cs, ds, dst, de, nweights, flags, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ob_varlen_encoding_gb18030_for_memcmp(const struct ObCharsetInfo* cs,
|
size_t ob_varlen_encoding_gb18030_for_memcmp(const struct ObCharsetInfo* cs,
|
||||||
|
|||||||
@ -21,6 +21,8 @@
|
|||||||
#include "lib/oblog/ob_log.h"
|
#include "lib/oblog/ob_log.h"
|
||||||
#include "sql/engine/expr/ob_datum_cast.h"
|
#include "sql/engine/expr/ob_datum_cast.h"
|
||||||
#include "ob_expr_util.h"
|
#include "ob_expr_util.h"
|
||||||
|
#include "sql/engine/ob_exec_context.h"
|
||||||
|
#include "sql/session/ob_sql_session_info.h"
|
||||||
|
|
||||||
using namespace oceanbase::common;
|
using namespace oceanbase::common;
|
||||||
|
|
||||||
@ -46,11 +48,6 @@ int ObExprWeightString::calc_result_typeN(ObExprResType &type,
|
|||||||
if (NOT_ROW_DIMENSION != row_dimension_ || ObMaxType == types_stack[0].get_type()) {
|
if (NOT_ROW_DIMENSION != row_dimension_ || ObMaxType == types_stack[0].get_type()) {
|
||||||
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
ret = OB_ERR_INVALID_TYPE_FOR_OP;
|
||||||
} else {
|
} else {
|
||||||
if (types_stack[0].get_type() > ObUNumberType && types_stack[0].get_type() != ObBitType) {
|
|
||||||
// 输入不是数字类型时
|
|
||||||
type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_NULL_ON_WARN);
|
|
||||||
types_stack[0].set_calc_type(ObVarcharType);
|
|
||||||
}
|
|
||||||
uint64_t max_length = OB_MAX_VARBINARY_LENGTH; // The maximum length of the result of WEIGHT_STRING()
|
uint64_t max_length = OB_MAX_VARBINARY_LENGTH; // The maximum length of the result of WEIGHT_STRING()
|
||||||
uint64_t result_length = types_stack[1].get_param().get_int();
|
uint64_t result_length = types_stack[1].get_param().get_int();
|
||||||
uint64_t nweight = types_stack[2].get_param().get_int();
|
uint64_t nweight = types_stack[2].get_param().get_int();
|
||||||
@ -58,8 +55,17 @@ int ObExprWeightString::calc_result_typeN(ObExprResType &type,
|
|||||||
ObCollationLevel coll_level = CS_LEVEL_INVALID;
|
ObCollationLevel coll_level = CS_LEVEL_INVALID;
|
||||||
if (as_binary) {
|
if (as_binary) {
|
||||||
coll_level = CS_LEVEL_IMPLICIT;
|
coll_level = CS_LEVEL_IMPLICIT;
|
||||||
|
type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_NULL_ON_WARN);
|
||||||
|
types_stack[0].set_calc_type(ObVarcharType);
|
||||||
} else {
|
} else {
|
||||||
coll_level = types_stack[0].get_collation_level();
|
coll_level = types_stack[0].get_collation_level();
|
||||||
|
if (types_stack[0].get_type() > ObUNumberType &&
|
||||||
|
types_stack[0].get_type() != ObBitType &&
|
||||||
|
types_stack[0].get_type() != ObYearType) {
|
||||||
|
// 输入不是数字类型时
|
||||||
|
type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_NULL_ON_WARN);
|
||||||
|
types_stack[0].set_calc_type(ObVarcharType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ObCollationType collation_type = types_stack[0].get_collation_type();
|
ObCollationType collation_type = types_stack[0].get_collation_type();
|
||||||
const ObCharsetInfo *cs = ObCharset::get_charset(collation_type);
|
const ObCharsetInfo *cs = ObCharset::get_charset(collation_type);
|
||||||
@ -106,18 +112,32 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
|
|||||||
KP(nweights_arg),
|
KP(nweights_arg),
|
||||||
KP(flags_arg),
|
KP(flags_arg),
|
||||||
KP(as_binary_arg));
|
KP(as_binary_arg));
|
||||||
} else if (arg->is_null() || expr.args_[0]->datum_meta_.type_ <= ObUNumberType || expr.args_[0]->datum_meta_.type_ == ObBitType) {
|
|
||||||
// The input string is NULL or numeric
|
|
||||||
res_datum.set_null();
|
|
||||||
} else if (arg->get_string().length() == 0 && arg->get_string().ptr() == nullptr) {
|
|
||||||
res_datum.set_string(nullptr,0);
|
|
||||||
} else {
|
} else {
|
||||||
const ObString str = arg->get_string();
|
const ObString str = arg->get_string();
|
||||||
uint64_t result_length = result_length_arg->get_int();
|
uint64_t result_length = result_length_arg->get_int();
|
||||||
uint64_t nweights = nweights_arg->get_int();
|
uint64_t nweights = nweights_arg->get_int();
|
||||||
uint64_t flags = flags_arg->get_int();
|
uint64_t flags = flags_arg->get_int();
|
||||||
bool as_binary = as_binary_arg->get_int();
|
bool as_binary = as_binary_arg->get_int();
|
||||||
|
int64_t max_allowed_packet = 0;
|
||||||
|
ObSQLSessionInfo *session = ctx.exec_ctx_.get_my_session();
|
||||||
|
if (arg->is_null()) {
|
||||||
|
// The input string is NULL
|
||||||
|
res_datum.set_null();
|
||||||
|
} else if (!as_binary && (expr.args_[0]->datum_meta_.type_ <= ObUNumberType ||
|
||||||
|
expr.args_[0]->datum_meta_.type_ == ObBitType ||
|
||||||
|
expr.args_[0]->datum_meta_.type_ == ObYearType)) {
|
||||||
|
res_datum.set_null();
|
||||||
|
} else if (arg->get_string().empty() && nweights == 0) {
|
||||||
|
res_datum.set_string(nullptr,0);
|
||||||
|
} else {
|
||||||
|
if (OB_FAIL(session->get_max_allowed_packet(max_allowed_packet))) {
|
||||||
|
if (OB_ENTRY_NOT_EXIST == ret) {
|
||||||
|
ret = OB_SUCCESS;
|
||||||
|
max_allowed_packet = OB_MAX_VARCHAR_LENGTH;
|
||||||
|
} else {
|
||||||
|
LOG_WARN("Failed to get max allow packet size", K(ret));
|
||||||
|
}
|
||||||
|
}
|
||||||
// Get the character set and collation information of the input string
|
// Get the character set and collation information of the input string
|
||||||
ObCollationType collation_type = CS_TYPE_INVALID;
|
ObCollationType collation_type = CS_TYPE_INVALID;
|
||||||
if (as_binary) {
|
if (as_binary) {
|
||||||
@ -135,6 +155,9 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
|
|||||||
} else {
|
} else {
|
||||||
tmp_length = cs->coll->strnxfrmlen(cs, cs->mbmaxlen*MAX(str.length() , nweights));
|
tmp_length = cs->coll->strnxfrmlen(cs, cs->mbmaxlen*MAX(str.length() , nweights));
|
||||||
}
|
}
|
||||||
|
if (tmp_length >= max_allowed_packet) {
|
||||||
|
res_datum.set_null();
|
||||||
|
} else {
|
||||||
int used_nweights = nweights;
|
int used_nweights = nweights;
|
||||||
size_t input_length = str.length();
|
size_t input_length = str.length();
|
||||||
if (used_nweights) {
|
if (used_nweights) {
|
||||||
@ -160,6 +183,8 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
|
|||||||
res_datum.set_string(out_buf,frm_length);
|
res_datum.set_string(out_buf,frm_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user