fix: old engine distinct boolean type
This commit is contained in:
1
deps/oblib/src/rpc/obmysql/ob_mysql_global.h
vendored
1
deps/oblib/src/rpc/obmysql/ob_mysql_global.h
vendored
@ -88,6 +88,7 @@ namespace obmysql {
|
|||||||
#define OB_MYSQL_BINCMP_FLAG (1 << 17)
|
#define OB_MYSQL_BINCMP_FLAG (1 << 17)
|
||||||
#define OB_MYSQL_GET_FIXED_FIELDS_FLAG (1 << 18)
|
#define OB_MYSQL_GET_FIXED_FIELDS_FLAG (1 << 18)
|
||||||
#define OB_MYSQL_FIELD_IN_PART_FUNC_FLAG (1 << 19)
|
#define OB_MYSQL_FIELD_IN_PART_FUNC_FLAG (1 << 19)
|
||||||
|
#define IS_BOOL_FLAG (1 << 20)
|
||||||
|
|
||||||
enum EMySQLFieldType {
|
enum EMySQLFieldType {
|
||||||
MYSQL_TYPE_DECIMAL,
|
MYSQL_TYPE_DECIMAL,
|
||||||
|
|||||||
@ -1213,7 +1213,12 @@ static int int_json(const ObObjType expect_type, ObObjCastParams ¶ms,
|
|||||||
LOG_ERROR("NULL allocator in json cast function", K(ret), K(in), K(expect_type));
|
LOG_ERROR("NULL allocator in json cast function", K(ret), K(in), K(expect_type));
|
||||||
} else {
|
} else {
|
||||||
ObJsonInt j_int(in.get_int());
|
ObJsonInt j_int(in.get_int());
|
||||||
|
bool bool_val = (in.get_int() == 1) ? true : false;
|
||||||
|
ObJsonBoolean j_bool(bool_val);
|
||||||
ObIJsonBase *j_base = &j_int;
|
ObIJsonBase *j_base = &j_int;
|
||||||
|
if (CM_HAS_BOOLEAN_FLAG(cast_mode)) {
|
||||||
|
j_base = &j_bool;
|
||||||
|
}
|
||||||
ObString raw_bin;
|
ObString raw_bin;
|
||||||
if (OB_FAIL(j_base->get_raw_binary(raw_bin, params.allocator_v2_))) {
|
if (OB_FAIL(j_base->get_raw_binary(raw_bin, params.allocator_v2_))) {
|
||||||
LOG_WARN("fail to get int json binary", K(ret), K(in), K(expect_type), K(*j_base));
|
LOG_WARN("fail to get int json binary", K(ret), K(in), K(expect_type), K(*j_base));
|
||||||
|
|||||||
@ -43,6 +43,7 @@ namespace common {
|
|||||||
#define CM_STRICT_MODE (1ULL << 8)
|
#define CM_STRICT_MODE (1ULL << 8)
|
||||||
#define CM_SET_MIN_IF_OVERFLOW (1ULL << 9)
|
#define CM_SET_MIN_IF_OVERFLOW (1ULL << 9)
|
||||||
#define CM_ERROR_ON_SCALE_OVER (1ULL << 10)
|
#define CM_ERROR_ON_SCALE_OVER (1ULL << 10)
|
||||||
|
#define CM_TO_BOOLEAN (1ULL << 11)
|
||||||
// when casting string to integer, round if not set this flag, otherwise trunc.
|
// when casting string to integer, round if not set this flag, otherwise trunc.
|
||||||
// but ceil will always round to +inf, and floor will always round to -inf.
|
// but ceil will always round to +inf, and floor will always round to -inf.
|
||||||
#define CM_STRING_INTEGER_TRUNC (1ULL << 57)
|
#define CM_STRING_INTEGER_TRUNC (1ULL << 57)
|
||||||
@ -84,6 +85,7 @@ typedef uint64_t ObCastMode;
|
|||||||
#define CM_IS_SET_MIN_IF_OVERFLOW(mode) ((CM_SET_MIN_IF_OVERFLOW & (mode)) != 0)
|
#define CM_IS_SET_MIN_IF_OVERFLOW(mode) ((CM_SET_MIN_IF_OVERFLOW & (mode)) != 0)
|
||||||
#define CM_IS_ERROR_ON_SCALE_OVER(mode) ((CM_ERROR_ON_SCALE_OVER & (mode)) != 0)
|
#define CM_IS_ERROR_ON_SCALE_OVER(mode) ((CM_ERROR_ON_SCALE_OVER & (mode)) != 0)
|
||||||
#define CM_IS_JSON_VALUE(mode) CM_IS_ERROR_ON_SCALE_OVER(mode)
|
#define CM_IS_JSON_VALUE(mode) CM_IS_ERROR_ON_SCALE_OVER(mode)
|
||||||
|
#define CM_HAS_BOOLEAN_FLAG(mode) ((CM_TO_BOOLEAN & (mode)) != 0)
|
||||||
|
|
||||||
struct ObObjCastParams {
|
struct ObObjCastParams {
|
||||||
// add params when necessary
|
// add params when necessary
|
||||||
|
|||||||
@ -66,6 +66,12 @@ int ObExprToType::calc_result1(ObObj& result, const ObObj& obj1, ObExprCtx& expr
|
|||||||
EXPR_DEFINE_CAST_CTX(expr_ctx, cast_mode_);
|
EXPR_DEFINE_CAST_CTX(expr_ctx, cast_mode_);
|
||||||
if (ob_is_json(expect_type_)) {
|
if (ob_is_json(expect_type_)) {
|
||||||
cast_ctx.dest_collation_ = result_type_.get_collation_type();
|
cast_ctx.dest_collation_ = result_type_.get_collation_type();
|
||||||
|
bool is_bool = false;
|
||||||
|
if (OB_FAIL(get_param_is_boolean(expr_ctx, obj1, is_bool))) {
|
||||||
|
LOG_WARN("get is_boolean type failed, bool may be cast as json int", K(ret), K(obj1));
|
||||||
|
} else {
|
||||||
|
cast_ctx.cast_mode_ |= CM_TO_BOOLEAN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (OB_FAIL(ObObjCaster::to_type(expect_type_, cast_ctx, obj1, result))) {
|
if (OB_FAIL(ObObjCaster::to_type(expect_type_, cast_ctx, obj1, result))) {
|
||||||
LOG_WARN("failed to cast obj", K(ret));
|
LOG_WARN("failed to cast obj", K(ret));
|
||||||
@ -119,6 +125,9 @@ int ObExprToType::calc_result_type_for_literal(ObExprResType& type, ObExprResTyp
|
|||||||
}
|
}
|
||||||
} else if (lib::is_mysql_mode() && ob_is_json(expect_type_)) {
|
} else if (lib::is_mysql_mode() && ob_is_json(expect_type_)) {
|
||||||
cast_coll_type = CS_TYPE_UTF8MB4_BIN;
|
cast_coll_type = CS_TYPE_UTF8MB4_BIN;
|
||||||
|
if (type1.has_result_flag(IS_BOOL_FLAG)) {
|
||||||
|
cast_mode |= CM_TO_BOOLEAN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ObAccuracy res_accuracy;
|
ObAccuracy res_accuracy;
|
||||||
|
|||||||
@ -1768,7 +1768,11 @@ int ObRawExprDeduceType::visit(ObSysFunRawExpr& expr)
|
|||||||
LOG_WARN("fail to visit for column_conv", K(ret), K(i));
|
LOG_WARN("fail to visit for column_conv", K(ret), K(i));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (OB_FAIL(types.push_back(param_expr->get_result_type()))) {
|
ObExprResType res_type = param_expr->get_result_type();
|
||||||
|
if (param_expr->is_bool_expr()) {
|
||||||
|
res_type.set_result_flag(IS_BOOL_FLAG);
|
||||||
|
}
|
||||||
|
if (OB_FAIL(types.push_back(res_type))) {
|
||||||
LOG_WARN("push back param type failed", K(ret));
|
LOG_WARN("push back param type failed", K(ret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user