Fix default value of ObDecimalIntType
This commit is contained in:
11
deps/oblib/src/common/object/ob_object.cpp
vendored
11
deps/oblib/src/common/object/ob_object.cpp
vendored
@ -1050,7 +1050,7 @@ bool ObObj::is_zero() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObObj::build_not_strict_default_value()
|
int ObObj::build_not_strict_default_value(int16_t precision)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
const ObObjType &data_type = meta_.get_type();
|
const ObObjType &data_type = meta_.get_type();
|
||||||
@ -1190,7 +1190,14 @@ int ObObj::build_not_strict_default_value()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ObDecimalIntType: {
|
case ObDecimalIntType: {
|
||||||
set_decimal_int(0, 0, nullptr);
|
const ObDecimalInt *decint = nullptr;
|
||||||
|
int32_t int_bytes = 0;
|
||||||
|
if (OB_FAIL(wide::ObDecimalIntConstValue::get_zero_value_byte_precision(precision, decint,
|
||||||
|
int_bytes))) {
|
||||||
|
_OB_LOG(WARN, "get zero value failed, ret=%u", ret);
|
||||||
|
} else {
|
||||||
|
set_decimal_int(int_bytes, 0, const_cast<ObDecimalInt *>(decint));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
2
deps/oblib/src/common/object/ob_object.h
vendored
2
deps/oblib/src/common/object/ob_object.h
vendored
@ -1219,7 +1219,7 @@ public:
|
|||||||
explicit ObObj(ObObjType type);
|
explicit ObObj(ObObjType type);
|
||||||
inline void reset();
|
inline void reset();
|
||||||
//when in not strict sql mode, build default value refer to data type
|
//when in not strict sql mode, build default value refer to data type
|
||||||
int build_not_strict_default_value();
|
int build_not_strict_default_value(int16_t precision);
|
||||||
static ObObj make_min_obj();
|
static ObObj make_min_obj();
|
||||||
static ObObj make_max_obj();
|
static ObObj make_max_obj();
|
||||||
static ObObj make_nop_obj();
|
static ObObj make_nop_obj();
|
||||||
|
|||||||
@ -1063,7 +1063,7 @@
|
|||||||
{ \
|
{ \
|
||||||
def_obj.set_type(data_type); \
|
def_obj.set_type(data_type); \
|
||||||
if (is_mysql_mode()) { \
|
if (is_mysql_mode()) { \
|
||||||
if (OB_FAIL(def_obj.build_not_strict_default_value())) { \
|
if (OB_FAIL(def_obj.build_not_strict_default_value(column.get_data_precision()))) { \
|
||||||
SQL_LOG(WARN, "failed to build not strict default json value", K(ret)); \
|
SQL_LOG(WARN, "failed to build not strict default json value", K(ret)); \
|
||||||
} else { \
|
} else { \
|
||||||
res_obj.set_json_value(data_type, def_obj.get_string().ptr(), \
|
res_obj.set_json_value(data_type, def_obj.get_string().ptr(), \
|
||||||
|
|||||||
@ -84,6 +84,8 @@ const ObDecimalInt *ObDecimalIntConstValue::MAX_DECINT[OB_MAX_DECIMAL_POSSIBLE_P
|
|||||||
const ObDecimalInt *ObDecimalIntConstValue::MAX_UPPER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1] = {nullptr};
|
const ObDecimalInt *ObDecimalIntConstValue::MAX_UPPER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1] = {nullptr};
|
||||||
const ObDecimalInt *ObDecimalIntConstValue::MIN_LOWER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1] = {nullptr};
|
const ObDecimalInt *ObDecimalIntConstValue::MIN_LOWER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1] = {nullptr};
|
||||||
|
|
||||||
|
const ObDecimalInt *ObDecimalIntConstValue::ZERO_VALUES[5] = {nullptr};
|
||||||
|
|
||||||
// init ObDecimalIntConstValue
|
// init ObDecimalIntConstValue
|
||||||
int ObDecimalIntConstValue::init_const_values(ObIAllocator &alloc, const lib::ObMemAttr &attr)
|
int ObDecimalIntConstValue::init_const_values(ObIAllocator &alloc, const lib::ObMemAttr &attr)
|
||||||
{
|
{
|
||||||
@ -143,6 +145,20 @@ int ObDecimalIntConstValue::init_const_values(ObIAllocator &alloc, const lib::Ob
|
|||||||
MAX_UPPER[precision] = max_decint;
|
MAX_UPPER[precision] = max_decint;
|
||||||
}
|
}
|
||||||
} // for end
|
} // for end
|
||||||
|
// init zero values
|
||||||
|
char *zero_buf = nullptr;
|
||||||
|
int buf_size = sizeof(int32_t) + sizeof(int64_t) + sizeof(int128_t) + sizeof(int256_t) + sizeof(int512_t);
|
||||||
|
if (OB_ISNULL(zero_buf = (char *)allocator.alloc(buf_size))) {
|
||||||
|
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||||
|
COMMON_LOG(WARN, "allocate memory failed", K(ret));
|
||||||
|
} else {
|
||||||
|
MEMSET(zero_buf, 0, buf_size);
|
||||||
|
ZERO_VALUES[0] = reinterpret_cast<const ObDecimalInt *>(zero_buf);
|
||||||
|
ZERO_VALUES[1] = reinterpret_cast<const ObDecimalInt *>(zero_buf + sizeof(int32_t));
|
||||||
|
ZERO_VALUES[2] = reinterpret_cast<const ObDecimalInt *>(zero_buf + sizeof(int32_t) + sizeof(int64_t));
|
||||||
|
ZERO_VALUES[3] = reinterpret_cast<const ObDecimalInt *>(zero_buf + sizeof(int32_t) + sizeof(int64_t) + sizeof(int128_t));
|
||||||
|
ZERO_VALUES[3] = reinterpret_cast<const ObDecimalInt *>(zero_buf + sizeof(int32_t) + sizeof(int64_t) + sizeof(int128_t) + sizeof(int256_t));
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -431,6 +431,20 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static int get_zero_value_byte_precision(int16_t precision, const ObDecimalInt *&decint, int32_t &int_bytes)
|
||||||
|
{
|
||||||
|
int ret = OB_SUCCESS;
|
||||||
|
ObDecimalIntWideType dec_type = get_decimalint_type(precision);
|
||||||
|
if (OB_UNLIKELY(dec_type == DECIMAL_INT_MAX)) {
|
||||||
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
COMMON_LOG(WARN, "invalid precision", K(precision));
|
||||||
|
} else {
|
||||||
|
decint = ZERO_VALUES[dec_type];
|
||||||
|
int_bytes = ((int32_t(1)) << dec_type) * sizeof(int32_t);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
inline static const ObDecimalInt* get_max_upper(ObPrecision prec)
|
inline static const ObDecimalInt* get_max_upper(ObPrecision prec)
|
||||||
{
|
{
|
||||||
OB_ASSERT(prec <= OB_MAX_DECIMAL_POSSIBLE_PRECISION);
|
OB_ASSERT(prec <= OB_MAX_DECIMAL_POSSIBLE_PRECISION);
|
||||||
@ -463,6 +477,8 @@ private:
|
|||||||
static const ObDecimalInt *MAX_UPPER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1];
|
static const ObDecimalInt *MAX_UPPER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1];
|
||||||
// MYSQL_MIN_LOWER
|
// MYSQL_MIN_LOWER
|
||||||
static const ObDecimalInt *MIN_LOWER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1];
|
static const ObDecimalInt *MIN_LOWER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1];
|
||||||
|
|
||||||
|
static const ObDecimalInt *ZERO_VALUES[5];
|
||||||
};
|
};
|
||||||
|
|
||||||
// helper functions
|
// helper functions
|
||||||
|
|||||||
@ -6611,7 +6611,7 @@ int ObDDLService::resolve_orig_default_value(ObColumnSchemaV2 &alter_column_sche
|
|||||||
} else {
|
} else {
|
||||||
ObObj default_value;
|
ObObj default_value;
|
||||||
default_value.set_type(alter_column_schema.get_data_type());
|
default_value.set_type(alter_column_schema.get_data_type());
|
||||||
if (OB_FAIL(default_value.build_not_strict_default_value())) {
|
if (OB_FAIL(default_value.build_not_strict_default_value(alter_column_schema.get_accuracy().get_precision()))) {
|
||||||
LOG_WARN("failed to build not strict default value", K(ret));
|
LOG_WARN("failed to build not strict default value", K(ret));
|
||||||
} else if (OB_FAIL(alter_column_schema.set_orig_default_value(default_value))) {
|
} else if (OB_FAIL(alter_column_schema.set_orig_default_value(default_value))) {
|
||||||
LOG_WARN("failed to set orig default value", K(ret));
|
LOG_WARN("failed to set orig default value", K(ret));
|
||||||
|
|||||||
@ -755,7 +755,7 @@ int ObDefaultValueUtils::build_default_expr_not_strict_static(
|
|||||||
default_value.set_null();
|
default_value.set_null();
|
||||||
} else {
|
} else {
|
||||||
default_value.set_type(column_schema->get_data_type());
|
default_value.set_type(column_schema->get_data_type());
|
||||||
if (OB_FAIL(default_value.build_not_strict_default_value())) {
|
if (OB_FAIL(default_value.build_not_strict_default_value(column_schema->get_accuracy().get_precision()))) {
|
||||||
LOG_WARN("failed to build not strict default value info", K(column_schema), K(ret));
|
LOG_WARN("failed to build not strict default value info", K(column_schema), K(ret));
|
||||||
} else if (default_value.is_string_type()) {
|
} else if (default_value.is_string_type()) {
|
||||||
default_value.set_collation_level(CS_LEVEL_IMPLICIT);
|
default_value.set_collation_level(CS_LEVEL_IMPLICIT);
|
||||||
@ -810,7 +810,7 @@ int ObDefaultValueUtils::build_default_expr_not_strict(const ColumnItem *column,
|
|||||||
default_value.set_null();
|
default_value.set_null();
|
||||||
} else {
|
} else {
|
||||||
default_value.set_type(column->get_column_type()->get_type());
|
default_value.set_type(column->get_column_type()->get_type());
|
||||||
if (OB_FAIL(default_value.build_not_strict_default_value())) {
|
if (OB_FAIL(default_value.build_not_strict_default_value(column->get_column_type()->get_accuracy().get_precision()))) {
|
||||||
LOG_WARN("failed to build not strict default value info", K(column), K(ret));
|
LOG_WARN("failed to build not strict default value info", K(column), K(ret));
|
||||||
} else if (default_value.is_string_type()) {
|
} else if (default_value.is_string_type()) {
|
||||||
default_value.set_collation_level(CS_LEVEL_IMPLICIT);
|
default_value.set_collation_level(CS_LEVEL_IMPLICIT);
|
||||||
|
|||||||
Reference in New Issue
Block a user