Fix bit type casting inconsistent with mysql
This commit is contained in:
@ -3359,28 +3359,41 @@ CAST_FUNC_NAME(bit, datetime)
|
||||
{
|
||||
GET_SESSION()
|
||||
{
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
uint64_t in_val = child_res->get_uint();
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
} else if (OB_ISNULL(session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is NULL", K(ret));
|
||||
} else {
|
||||
int warning = OB_SUCCESS;
|
||||
ObObjType out_type = expr.datum_meta_.type_;
|
||||
ObString str(pos, buf);
|
||||
ObTimeConvertCtx cvrt_ctx(session->get_timezone_info(), ObTimestampType == out_type);
|
||||
ObScale res_scale;
|
||||
int64_t out_val = 0;
|
||||
if (CAST_FAIL(ObTimeConverter::str_to_datetime(str, cvrt_ctx, out_val, &res_scale))) {
|
||||
LOG_WARN("str_to_datetime failed", K(ret));
|
||||
DEF_IN_OUT_VAL(uint64_t, int64_t, 0);
|
||||
if (CM_IS_COLUMN_CONVERT(expr.extra_)) {
|
||||
// if cast mode is column convert, using bit as int64 to do cast.
|
||||
int64_t int64 = 0;
|
||||
if (OB_FAIL(common_uint_int(expr, ObIntType, in_val, ctx, int64))) {
|
||||
LOG_WARN("common_uint_int failed", K(ret));
|
||||
} else if (OB_UNLIKELY(0 > int64)) {
|
||||
ret = OB_INVALID_DATE_FORMAT;
|
||||
LOG_WARN("invalid date", K(ret), K(int64));
|
||||
} else {
|
||||
SET_RES_DATETIME(out_val);
|
||||
ObTimeConvertCtx cvrt_ctx(session->get_timezone_info(), ObTimestampType == expr.datum_meta_.type_);
|
||||
if (CAST_FAIL(ObTimeConverter::int_to_datetime(int64, 0, cvrt_ctx, out_val))) {
|
||||
LOG_WARN("int_datetime failed", K(ret), K(int64));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// using bit as char array to do cast.
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
} else {
|
||||
ObObjType out_type = expr.datum_meta_.type_;
|
||||
ObString str(pos, buf);
|
||||
ObTimeConvertCtx cvrt_ctx(session->get_timezone_info(), ObTimestampType == out_type);
|
||||
ObScale res_scale;
|
||||
if (CAST_FAIL(ObTimeConverter::str_to_datetime(str, cvrt_ctx, out_val, &res_scale))) {
|
||||
LOG_WARN("str_to_datetime failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
SET_RES_DATETIME(out_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3391,20 +3404,32 @@ CAST_FUNC_NAME(bit, date)
|
||||
{
|
||||
EVAL_ARG()
|
||||
{
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
DEF_IN_OUT_VAL(uint64_t, int32_t, 0);
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
} else {
|
||||
ObString str(pos, buf);
|
||||
if (CAST_FAIL(ObTimeConverter::str_to_date(str, out_val))) {
|
||||
LOG_WARN("str_to_datetime failed", K(ret));
|
||||
} else {
|
||||
SET_RES_DATE(out_val);
|
||||
if (CM_IS_COLUMN_CONVERT(expr.extra_)) {
|
||||
// if cast mode is column convert, using bit as int64 to do cast.
|
||||
int64_t int64 = 0;
|
||||
if (OB_FAIL(common_uint_int(expr, ObIntType, in_val, ctx, int64))) {
|
||||
LOG_WARN("common_uint_int failed", K(ret));
|
||||
} else if (CAST_FAIL(ObTimeConverter::int_to_date(int64, out_val))) {
|
||||
LOG_WARN("int_to_date failed", K(ret), K(int64), K(out_val));
|
||||
}
|
||||
} else {
|
||||
// using bit as char array to do cast.
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
} else {
|
||||
ObString str(pos, buf);
|
||||
if (CAST_FAIL(ObTimeConverter::str_to_date(str, out_val))) {
|
||||
LOG_WARN("str_to_datetime failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
SET_RES_DATE(out_val);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -3414,20 +3439,31 @@ CAST_FUNC_NAME(bit, time)
|
||||
{
|
||||
EVAL_ARG()
|
||||
{
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
DEF_IN_OUT_VAL(uint64_t, int64_t, 0);
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
if (CM_IS_COLUMN_CONVERT(expr.extra_)) {
|
||||
// if cast mode is column convert, using bit as int64 to do cast.
|
||||
int64_t int64 = 0;
|
||||
if (OB_FAIL(common_uint_int(expr, ObIntType, in_val, ctx, int64))) {
|
||||
LOG_WARN("common_uint_int failed", K(ret), K(in_val));
|
||||
} else if (OB_FAIL(common_int_time(expr, int64, res_datum))) {
|
||||
LOG_WARN("common_int_time failed", K(ret), K(out_val));
|
||||
}
|
||||
} else {
|
||||
ObString str(pos, buf);
|
||||
ObScale res_scale;
|
||||
if (CAST_FAIL(ObTimeConverter::str_to_time(str, out_val, &res_scale))) {
|
||||
LOG_WARN("str_to_datetime failed", K(ret));
|
||||
// using bit as char array to do cast.
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
} else {
|
||||
SET_RES_TIME(out_val);
|
||||
ObString str(pos, buf);
|
||||
ObScale res_scale;
|
||||
if (CAST_FAIL(ObTimeConverter::str_to_time(str, out_val, &res_scale))) {
|
||||
LOG_WARN("str_to_datetime failed", K(ret));
|
||||
} else {
|
||||
SET_RES_TIME(out_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3438,20 +3474,13 @@ CAST_FUNC_NAME(bit, year)
|
||||
{
|
||||
EVAL_ARG()
|
||||
{
|
||||
DEF_IN_OUT_VAL(uint64_t, uint8_t, 0);
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
} else {
|
||||
ObString str(pos, buf);
|
||||
if (CAST_FAIL(ObTimeConverter::str_to_year(str, out_val))) {
|
||||
LOG_WARN("str_to_datetime failed", K(ret));
|
||||
} else {
|
||||
SET_RES_YEAR(out_val);
|
||||
}
|
||||
// same as uint to year
|
||||
uint64_t in_val = child_res->get_uint();
|
||||
int64_t out_val = 0;
|
||||
if (OB_FAIL(common_uint_int(expr, ObIntType, in_val, ctx, out_val))) {
|
||||
LOG_WARN("common_uint_int failed", K(ret), K(in_val));
|
||||
} else if (OB_FAIL(common_int_year(expr, out_val, res_datum))) {
|
||||
LOG_WARN("common_int_year failed", K(ret), K(out_val));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -3461,17 +3490,26 @@ CAST_FUNC_NAME(bit, string)
|
||||
{
|
||||
EVAL_ARG()
|
||||
{
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
uint64_t in_val = child_res->get_uint();
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(buf), K(BUF_LEN), K(in_val), K(pos));
|
||||
if (CM_IS_COLUMN_CONVERT(expr.extra_)) {
|
||||
// if cast mode is column convert, using bit as int64 to do cast.
|
||||
ObFastFormatInt ffi(in_val);
|
||||
if (OB_FAIL(common_copy_string_zf(expr, ObString(ffi.length(), ffi.ptr()), ctx, res_datum))) {
|
||||
LOG_WARN("common_copy_string_zf failed", K(ret), K(ObString(ffi.length(), ffi.ptr())));
|
||||
}
|
||||
} else {
|
||||
ObString str(pos, buf);
|
||||
if (OB_FAIL(common_copy_string(expr, str, ctx, res_datum))) {
|
||||
LOG_WARN("common_copy_string failed", K(ret));
|
||||
// using bit as char array to do cast.
|
||||
const int32_t BUF_LEN = (OB_MAX_BIT_LENGTH + 7) / 8;
|
||||
int64_t pos = 0;
|
||||
char buf[BUF_LEN] = {0};
|
||||
ObLengthSemantics length = expr.args_[0]->datum_meta_.length_semantics_;
|
||||
if (OB_FAIL(bit_to_char_array(in_val, length, buf, BUF_LEN, pos))) {
|
||||
LOG_WARN("fail to store val", K(ret), K(in_val), K(length), K(buf), K(BUF_LEN), K(pos));
|
||||
} else {
|
||||
ObString str(pos, buf);
|
||||
if (OB_FAIL(common_copy_string(expr, str, ctx, res_datum))) {
|
||||
LOG_WARN("common_copy_string failed", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user