fix load data handle empty filed bug

This commit is contained in:
bf0 2021-07-27 20:24:13 +08:00 committed by wangzelin.wzl
parent 0b7773c43f
commit 2b51e4f001
2 changed files with 13 additions and 2 deletions

View File

@ -1231,7 +1231,7 @@ int ObLoadDataImpl::handle_one_line(ObExecContext& ctx, ObPhysicalPlanCtx& plan_
return ret;
}
const char* ObCSVParser::ZERO_STRING = "0";
const char* ObCSVParser::ZERO_STRING = "\xFF\xFF";
int ObCSVParser::init(
int64_t file_column_nums, const ObCSVFormats& formats, const common::ObBitSet<>& string_type_column)
@ -1355,7 +1355,7 @@ void ObCSVParser::deal_with_empty_field(ObString& field_str, int64_t index)
{
if (formats_.null_column_fill_zero_string_ && !string_type_column_.has_member(index)) {
// a non-string value will be set to "0", "0" will be cast to zero value of target types
field_str.assign_ptr(ZERO_STRING, 1);
field_str.assign_ptr(ZERO_STRING, 2);
} else {
// a string value will be set to ''
field_str.reset();
@ -2831,6 +2831,8 @@ int ObLoadDataSPImpl::exec_insert(ObInsertTask& task, ObInsertResult& result)
}
if (ObLoadDataUtils::is_null_field(single_row_values[c])) {
OZ(sql_str.append(ObString(ObLoadDataUtils::NULL_STRING)));
} else if (ObLoadDataUtils::is_zero_field(single_row_values[c])) {
OZ(sql_str.append("0"));
} else {
if (is_string_column) {
OZ(sql_str.append("'", 1));

View File

@ -147,6 +147,15 @@ public:
return ret_bool;
}
static inline bool is_zero_field(const common::ObString& field_str)
{
int ret_bool = false;
if (field_str.length() == 2 && field_str.ptr()[0] == '\xff' && field_str.ptr()[1] == '\xff') {
ret_bool = true;
}
return ret_bool;
}
static common::ObString escape_quotation(const common::ObString& value, common::ObDataBuffer& data_buf);
static int init_empty_string_array(common::ObIArray<common::ObString>& new_array, int64_t array_size);