refresh mysqltest of weight_string expr
This commit is contained in:
@ -62,7 +62,7 @@ int ObExprWeightString::calc_result_typeN(ObExprResType &type,
|
|||||||
if (types_stack[0].get_type() > ObUNumberType &&
|
if (types_stack[0].get_type() > ObUNumberType &&
|
||||||
types_stack[0].get_type() != ObBitType &&
|
types_stack[0].get_type() != ObBitType &&
|
||||||
types_stack[0].get_type() != ObYearType) {
|
types_stack[0].get_type() != ObYearType) {
|
||||||
// 输入不是数字类型时
|
// When the input is not a numeric type, convert to a varchar type
|
||||||
type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_NULL_ON_WARN);
|
type_ctx.set_cast_mode(type_ctx.get_cast_mode() | CM_NULL_ON_WARN);
|
||||||
types_stack[0].set_calc_type(ObVarcharType);
|
types_stack[0].set_calc_type(ObVarcharType);
|
||||||
}
|
}
|
||||||
@ -73,18 +73,17 @@ int ObExprWeightString::calc_result_typeN(ObExprResType &type,
|
|||||||
types_stack[0].get_type() == ObTimestampType ||
|
types_stack[0].get_type() == ObTimestampType ||
|
||||||
types_stack[0].get_type() == ObDateType ||
|
types_stack[0].get_type() == ObDateType ||
|
||||||
types_stack[0].get_type() == ObTimeType ) {
|
types_stack[0].get_type() == ObTimeType ) {
|
||||||
// 日期、时间等类型,max_lenght是输入的类型的长度
|
// For types such as date, time, etc., the max_lenght is the length of the type entered
|
||||||
max_length = types_stack[0].get_length();
|
max_length = types_stack[0].get_length();
|
||||||
} else if (result_length > 0) {
|
} else if (result_length > 0) {
|
||||||
max_length = result_length;
|
max_length = result_length;
|
||||||
} else if (as_binary) {
|
} else if (as_binary) {
|
||||||
// as_binary的情况下,以nweight作为输出结果的max_length
|
// In the case of as_binary, the max_length with nweight as the output result
|
||||||
max_length = nweight;
|
max_length = nweight;
|
||||||
} else {
|
} else {
|
||||||
// 输入为 char的情况下,使用cs->mbmaxlen计算max_length
|
// If the input is others, use cs->mbmaxlen to calculate the max_length
|
||||||
max_length = cs->mbmaxlen * MAX(nweight, types_stack[0].get_length()*cs->mbmaxlen);
|
max_length = cs->mbmaxlen * MAX(nweight, types_stack[0].get_length()*cs->mbmaxlen);
|
||||||
}
|
}
|
||||||
// 推导结果
|
|
||||||
type.set_varchar();
|
type.set_varchar();
|
||||||
type.set_collation_type(CS_TYPE_BINARY);
|
type.set_collation_type(CS_TYPE_BINARY);
|
||||||
type.set_collation_level(coll_level);
|
type.set_collation_level(coll_level);
|
||||||
@ -121,7 +120,6 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
|
|||||||
int64_t max_allowed_packet = 0;
|
int64_t max_allowed_packet = 0;
|
||||||
ObSQLSessionInfo *session = ctx.exec_ctx_.get_my_session();
|
ObSQLSessionInfo *session = ctx.exec_ctx_.get_my_session();
|
||||||
if (arg->is_null()) {
|
if (arg->is_null()) {
|
||||||
// The input string is NULL
|
|
||||||
res_datum.set_null();
|
res_datum.set_null();
|
||||||
} else if (!as_binary && (expr.args_[0]->datum_meta_.type_ <= ObUNumberType ||
|
} else if (!as_binary && (expr.args_[0]->datum_meta_.type_ <= ObUNumberType ||
|
||||||
expr.args_[0]->datum_meta_.type_ == ObBitType ||
|
expr.args_[0]->datum_meta_.type_ == ObBitType ||
|
||||||
@ -156,6 +154,7 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
|
|||||||
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) {
|
if (tmp_length >= max_allowed_packet) {
|
||||||
|
// The return result exceeds the maximum limit and returns NULL.
|
||||||
res_datum.set_null();
|
res_datum.set_null();
|
||||||
} else {
|
} else {
|
||||||
int used_nweights = nweights;
|
int used_nweights = nweights;
|
||||||
@ -169,14 +168,27 @@ int ObExprWeightString::eval_weight_string(const ObExpr &expr, ObEvalCtx &ctx, O
|
|||||||
}
|
}
|
||||||
bool is_valid_unicode_tmp = 1;
|
bool is_valid_unicode_tmp = 1;
|
||||||
char *out_buf = expr.get_str_res_mem(ctx, tmp_length);
|
char *out_buf = expr.get_str_res_mem(ctx, tmp_length);
|
||||||
|
// For the case where the input is an empty string but the nweight is not 0,
|
||||||
|
// the weight_string function will call strnxfrm() to padding the result
|
||||||
|
// eg:
|
||||||
|
// mysql> select HEX(WEIGHT_STRING('' as char(3)));
|
||||||
|
// +-----------------------------------+
|
||||||
|
// | HEX(WEIGHT_STRING('' as char(3))) |
|
||||||
|
// +-----------------------------------+
|
||||||
|
// | 002000200020 |
|
||||||
|
// +-----------------------------------+
|
||||||
|
// However, the strnxfrm requires that the input cannot be a null ptr,
|
||||||
|
// so an empty string is set as the input.
|
||||||
|
const char* tmp_empty_str = "";
|
||||||
if (OB_ISNULL(out_buf)) {
|
if (OB_ISNULL(out_buf)) {
|
||||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
|
LOG_WARN("failed to alloc output buf",K(ret));
|
||||||
} else {
|
} else {
|
||||||
frm_length = cs->coll->strnxfrm(cs,
|
frm_length = cs->coll->strnxfrm(cs,
|
||||||
reinterpret_cast<uchar *>(out_buf),
|
reinterpret_cast<uchar *>(out_buf),
|
||||||
tmp_length,
|
tmp_length,
|
||||||
used_nweights,
|
used_nweights,
|
||||||
reinterpret_cast<const uchar *>(str.ptr()),
|
str.ptr() != NULL? reinterpret_cast<const uchar *>(str.ptr()) : reinterpret_cast<const uchar *>(tmp_empty_str),
|
||||||
input_length,
|
input_length,
|
||||||
flags,
|
flags,
|
||||||
&is_valid_unicode_tmp);
|
&is_valid_unicode_tmp);
|
||||||
|
|||||||
Reference in New Issue
Block a user