fix bug of unsigned decimal

This commit is contained in:
obdev
2024-06-25 12:10:40 +00:00
committed by ob-robot
parent 236f3cf191
commit 83b4d3f1c2
8 changed files with 44 additions and 7 deletions

View File

@ -18,6 +18,7 @@
#include "sql/engine/expr/ob_expr_util.h" #include "sql/engine/expr/ob_expr_util.h"
#include "sql/resolver/expr/ob_raw_expr_util.h" #include "sql/resolver/expr/ob_raw_expr_util.h"
#include "sql/engine/expr/ob_datum_cast.h" #include "sql/engine/expr/ob_datum_cast.h"
#include "share/object/ob_obj_cast_util.h"
namespace oceanbase namespace oceanbase
{ {
@ -26,6 +27,8 @@ namespace observer
using namespace common; using namespace common;
using namespace sql; using namespace sql;
#define CAST_FAIL(stmt) \
(OB_UNLIKELY((OB_SUCCESS != (ret = ObTableLoadObjCaster::get_cast_ret(cast_mode, (stmt), cast_ctx.warning_)))))
const ObObj ObTableLoadObjCaster::zero_obj(0); const ObObj ObTableLoadObjCaster::zero_obj(0);
const ObObj ObTableLoadObjCaster::null_obj(ObObjType::ObNullType); const ObObj ObTableLoadObjCaster::null_obj(ObObjType::ObNullType);
@ -319,6 +322,7 @@ int ObTableLoadObjCaster::to_type(const ObObjType &expect_type, const share::sch
ObCastCtx cast_ctx = *cast_obj_ctx.cast_ctx_; ObCastCtx cast_ctx = *cast_obj_ctx.cast_ctx_;
cast_ctx.dest_collation_ = column_schema->get_collation_type(); cast_ctx.dest_collation_ = column_schema->get_collation_type();
const ObTableLoadTimeConverter time_cvrt = *cast_obj_ctx.time_cvrt_; const ObTableLoadTimeConverter time_cvrt = *cast_obj_ctx.time_cvrt_;
ObCastMode cast_mode = cast_ctx.cast_mode_;
if (src.is_null()) { if (src.is_null()) {
dst.set_null(); dst.set_null();
} else if (src.get_type_class() == ObStringTC && } else if (src.get_type_class() == ObStringTC &&
@ -339,10 +343,14 @@ int ObTableLoadObjCaster::to_type(const ObObjType &expect_type, const share::sch
LOG_WARN("fail to cast ObObj", KR(ret), K(src), K(expect_type)); LOG_WARN("fail to cast ObObj", KR(ret), K(src), K(expect_type));
} }
} else { } else {
dst.set_number(expect_type, d, digits); number::ObNumber value(d.desc_, digits);
if (ObUNumberType == expect_type && CAST_FAIL(numeric_negative_check(value))) {
LOG_WARN("numeric_negative_check failed", K(ret), K(value), K(cast_ctx));
} else {
dst.set_number(expect_type, value);
}
} }
} else if (src.get_type_class() == ObStringTC && expect_type == ObDateTimeType && lib::is_oracle_mode()) { } else if (src.get_type_class() == ObStringTC && expect_type == ObDateTimeType && lib::is_oracle_mode()) {
ObCastMode cast_mode = cast_obj_ctx.cast_ctx_->cast_mode_;
if (OB_FAIL(string_datetime_oracle(expect_type, cast_ctx, src, dst, cast_mode, time_cvrt))) { if (OB_FAIL(string_datetime_oracle(expect_type, cast_ctx, src, dst, cast_mode, time_cvrt))) {
LOG_WARN("fail to convert string to datetime in oracle mode", KR(ret), K(src), LOG_WARN("fail to convert string to datetime in oracle mode", KR(ret), K(src),
K(expect_type)); K(expect_type));

View File

@ -265,6 +265,20 @@ private:
} }
return ret; return ret;
} }
// copy from `ob_obj_cast.cpp`
static int get_cast_ret(const ObCastMode &cast_mode, int ret, int &warning)
{
// compatibility for old ob
if (OB_UNLIKELY(OB_ERR_UNEXPECTED_TZ_TRANSITION == ret)
|| OB_UNLIKELY(OB_ERR_UNKNOWN_TIME_ZONE == ret)) {
ret = OB_INVALID_DATE_VALUE;
} else if (OB_SUCCESS != ret && CM_IS_WARN_ON_FAIL(cast_mode)) {
LOG_INFO("static int get_cast_ret", K(CM_IS_WARN_ON_FAIL(cast_mode)), K(cast_mode));
warning = ret;
ret = OB_SUCCESS;
}
return ret;
}
}; };
} // namespace observer } // namespace observer

View File

@ -20,6 +20,7 @@
#include "observer/table_load/ob_table_load_stat.h" #include "observer/table_load/ob_table_load_stat.h"
#include "share/schema/ob_multi_version_schema_service.h" #include "share/schema/ob_multi_version_schema_service.h"
#include "sql/session/ob_sql_session_info.h" #include "sql/session/ob_sql_session_info.h"
#include "sql/ob_sql_utils.h"
namespace oceanbase namespace oceanbase
{ {
@ -32,6 +33,7 @@ using namespace table;
ObTableLoadPartitionCalc::ObTableLoadPartitionCalc() ObTableLoadPartitionCalc::ObTableLoadPartitionCalc()
: session_info_(nullptr), : session_info_(nullptr),
cast_mode_(CM_NONE),
is_partition_with_autoinc_(false), is_partition_with_autoinc_(false),
partition_with_autoinc_idx_(OB_INVALID_INDEX), partition_with_autoinc_idx_(OB_INVALID_INDEX),
param_(nullptr), param_(nullptr),
@ -58,6 +60,8 @@ int ObTableLoadPartitionCalc::init(const ObTableLoadParam &param, sql::ObSQLSess
ObDataTypeCastParams cast_params(session_info->get_timezone_info()); ObDataTypeCastParams cast_params(session_info->get_timezone_info());
if (OB_FAIL(time_cvrt_.init(cast_params.get_nls_format(ObDateTimeType)))) { if (OB_FAIL(time_cvrt_.init(cast_params.get_nls_format(ObDateTimeType)))) {
LOG_WARN("fail to init time converter", KR(ret)); LOG_WARN("fail to init time converter", KR(ret));
} else if (OB_FAIL(ObSQLUtils::get_default_cast_mode(session_info, cast_mode_))) {
LOG_WARN("fail to get_default_cast_mode", KR(ret));
} else if (OB_FAIL(ObTableLoadSchema::get_table_schema(tenant_id, table_id, schema_guard_, } else if (OB_FAIL(ObTableLoadSchema::get_table_schema(tenant_id, table_id, schema_guard_,
table_schema))) { table_schema))) {
LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id)); LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id));
@ -172,7 +176,7 @@ int ObTableLoadPartitionCalc::cast_part_key(common::ObNewRow &part_key, common::
LOG_WARN("invalid part key count", KR(ret), K(part_key.count_), K(part_key_obj_index_.count())); LOG_WARN("invalid part key count", KR(ret), K(part_key.count_), K(part_key_obj_index_.count()));
} else { } else {
ObDataTypeCastParams cast_params(session_info_->get_timezone_info()); ObDataTypeCastParams cast_params(session_info_->get_timezone_info());
ObCastCtx cast_ctx(&allocator, &cast_params, CM_NONE, ObCharset::get_system_collation()); ObCastCtx cast_ctx(&allocator, &cast_params, cast_mode_, ObCharset::get_system_collation());
ObTableLoadCastObjCtx cast_obj_ctx(*param_, &time_cvrt_, &cast_ctx, true); ObTableLoadCastObjCtx cast_obj_ctx(*param_, &time_cvrt_, &cast_ctx, true);
ObObj obj; ObObj obj;
for (int64_t i = 0; OB_SUCC(ret) && i < part_key_obj_index_.count(); ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < part_key_obj_index_.count(); ++i) {

View File

@ -55,6 +55,7 @@ public:
table::ObTableLoadArray<IndexAndType> part_key_obj_index_; table::ObTableLoadArray<IndexAndType> part_key_obj_index_;
sql::ObSQLSessionInfo *session_info_; sql::ObSQLSessionInfo *session_info_;
ObTableLoadTimeConverter time_cvrt_; ObTableLoadTimeConverter time_cvrt_;
common::ObCastMode cast_mode_;
bool is_partition_with_autoinc_; bool is_partition_with_autoinc_;
int64_t partition_with_autoinc_idx_; int64_t partition_with_autoinc_idx_;
private: private:

View File

@ -25,6 +25,7 @@
#include "observer/table_load/ob_table_load_trans_ctx.h" #include "observer/table_load/ob_table_load_trans_ctx.h"
#include "share/ob_autoincrement_service.h" #include "share/ob_autoincrement_service.h"
#include "share/sequence/ob_sequence_cache.h" #include "share/sequence/ob_sequence_cache.h"
#include "sql/ob_sql_utils.h"
namespace oceanbase namespace oceanbase
{ {
@ -66,6 +67,7 @@ ObTableLoadTransBucketWriter::ObTableLoadTransBucketWriter(ObTableLoadTransCtx *
param_(trans_ctx_->ctx_->param_), param_(trans_ctx_->ctx_->param_),
allocator_("TLD_TBWriter"), allocator_("TLD_TBWriter"),
is_partitioned_(false), is_partitioned_(false),
cast_mode_(CM_NONE),
session_ctx_array_(nullptr), session_ctx_array_(nullptr),
ref_count_(0), ref_count_(0),
is_flush_(false), is_flush_(false),
@ -97,7 +99,9 @@ int ObTableLoadTransBucketWriter::init()
LOG_WARN("unexpected null coordinator ctx", KR(ret)); LOG_WARN("unexpected null coordinator ctx", KR(ret));
} else { } else {
is_partitioned_ = coordinator_ctx_->ctx_->schema_.is_partitioned_table_; is_partitioned_ = coordinator_ctx_->ctx_->schema_.is_partitioned_table_;
if (OB_FAIL(init_session_ctx_array())) { if (OB_FAIL(ObSQLUtils::get_default_cast_mode(coordinator_ctx_->ctx_->session_info_, cast_mode_))) {
LOG_WARN("fail to get_default_cast_mode", KR(ret));
} else if (OB_FAIL(init_session_ctx_array())) {
LOG_WARN("fail to init session ctx array", KR(ret)); LOG_WARN("fail to init session ctx array", KR(ret));
} else { } else {
is_inited_ = true; is_inited_ = true;
@ -217,7 +221,7 @@ int ObTableLoadTransBucketWriter::handle_partition_with_autoinc_identity(
const int64_t row_count = obj_rows.count(); const int64_t row_count = obj_rows.count();
ObArenaAllocator autoinc_allocator("TLD_Autoinc", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID()); ObArenaAllocator autoinc_allocator("TLD_Autoinc", OB_MALLOC_NORMAL_BLOCK_SIZE, MTL_ID());
ObDataTypeCastParams cast_params(coordinator_ctx_->partition_calc_.session_info_->get_timezone_info()); ObDataTypeCastParams cast_params(coordinator_ctx_->partition_calc_.session_info_->get_timezone_info());
ObCastCtx cast_ctx(&autoinc_allocator, &cast_params, CM_NONE, ObCastCtx cast_ctx(&autoinc_allocator, &cast_params, cast_mode_,
ObCharset::get_system_collation()); ObCharset::get_system_collation());
ObTableLoadCastObjCtx cast_obj_ctx(param_, &(coordinator_ctx_->partition_calc_.time_cvrt_), &cast_ctx, ObTableLoadCastObjCtx cast_obj_ctx(param_, &(coordinator_ctx_->partition_calc_.time_cvrt_), &cast_ctx,
true); true);

View File

@ -70,6 +70,7 @@ private:
const ObTableLoadParam &param_; const ObTableLoadParam &param_;
common::ObArenaAllocator allocator_; common::ObArenaAllocator allocator_;
bool is_partitioned_; bool is_partitioned_;
common::ObCastMode cast_mode_;
struct SessionContext struct SessionContext
{ {
SessionContext(); SessionContext();

View File

@ -23,6 +23,7 @@
#include "observer/table_load/ob_table_load_utils.h" #include "observer/table_load/ob_table_load_utils.h"
#include "sql/engine/cmd/ob_load_data_utils.h" #include "sql/engine/cmd/ob_load_data_utils.h"
#include "sql/resolver/expr/ob_raw_expr_util.h" #include "sql/resolver/expr/ob_raw_expr_util.h"
#include "sql/ob_sql_utils.h"
#include "share/ob_autoincrement_service.h" #include "share/ob_autoincrement_service.h"
#include "share/sequence/ob_sequence_cache.h" #include "share/sequence/ob_sequence_cache.h"
@ -119,6 +120,7 @@ ObTableLoadTransStoreWriter::ObTableLoadTransStoreWriter(ObTableLoadTransStore *
param_(trans_ctx_->ctx_->param_), param_(trans_ctx_->ctx_->param_),
allocator_("TLD_TSWriter"), allocator_("TLD_TSWriter"),
table_data_desc_(nullptr), table_data_desc_(nullptr),
cast_mode_(CM_NONE),
lob_inrow_threshold_(0), lob_inrow_threshold_(0),
ref_count_(0), ref_count_(0),
is_inited_(false) is_inited_(false)
@ -157,7 +159,9 @@ int ObTableLoadTransStoreWriter::init()
} else { } else {
table_data_desc_ = &store_ctx_->table_data_desc_; table_data_desc_ = &store_ctx_->table_data_desc_;
collation_type_ = trans_ctx_->ctx_->schema_.collation_type_; collation_type_ = trans_ctx_->ctx_->schema_.collation_type_;
if (OB_FAIL(init_session_ctx_array())) { if (OB_FAIL(ObSQLUtils::get_default_cast_mode(store_ctx_->ctx_->session_info_, cast_mode_))) {
LOG_WARN("fail to get_default_cast_mode", KR(ret));
} else if (OB_FAIL(init_session_ctx_array())) {
LOG_WARN("fail to init session ctx array", KR(ret)); LOG_WARN("fail to init session ctx array", KR(ret));
} else if (OB_FAIL(init_column_schemas_and_lob_info())) { } else if (OB_FAIL(init_column_schemas_and_lob_info())) {
LOG_WARN("fail to init column schemas and lob info", KR(ret)); LOG_WARN("fail to init column schemas and lob info", KR(ret));
@ -428,7 +432,7 @@ int ObTableLoadTransStoreWriter::cast_column(
int32_t session_id) int32_t session_id)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
ObCastCtx cast_ctx(&cast_allocator, &cast_params, CM_NONE, column_schema->get_collation_type()); ObCastCtx cast_ctx(&cast_allocator, &cast_params, cast_mode_, column_schema->get_collation_type());
ObTableLoadCastObjCtx cast_obj_ctx(param_, &time_cvrt_, &cast_ctx, true); ObTableLoadCastObjCtx cast_obj_ctx(param_, &time_cvrt_, &cast_ctx, true);
const bool is_null_autoinc = const bool is_null_autoinc =
(column_schema->is_autoincrement() || column_schema->is_identity_column()) && (column_schema->is_autoincrement() || column_schema->is_identity_column()) &&

View File

@ -113,6 +113,7 @@ private:
common::ObArenaAllocator allocator_; common::ObArenaAllocator allocator_;
storage::ObDirectLoadTableDataDesc *table_data_desc_; storage::ObDirectLoadTableDataDesc *table_data_desc_;
common::ObCollationType collation_type_; common::ObCollationType collation_type_;
common::ObCastMode cast_mode_;
ObTableLoadTimeConverter time_cvrt_; ObTableLoadTimeConverter time_cvrt_;
// does not contain hidden primary key columns // does not contain hidden primary key columns
// and does not contain virtual generated columns // and does not contain virtual generated columns