diff --git a/deps/oblib/src/lib/charset/ob_charset.h b/deps/oblib/src/lib/charset/ob_charset.h index b5fd2501e5..b81730d9d4 100644 --- a/deps/oblib/src/lib/charset/ob_charset.h +++ b/deps/oblib/src/lib/charset/ob_charset.h @@ -578,7 +578,8 @@ public: template static int foreach_char(const common::ObString &str, common::ObCollationType collation_type, - foreach_char_func &func) + foreach_char_func &func, + bool ignore_invalid_character = false) { int ret = common::OB_SUCCESS; int32_t wchar = 0; @@ -587,8 +588,19 @@ public: for (common::ObString temp_str = str; OB_SUCC(ret) && !temp_str.empty(); temp_str+=length) { if (OB_FAIL(ObCharset::mb_wc(collation_type, temp_str.ptr(), temp_str.length(), length, wchar))) { - COMMON_LOG(WARN, "fail to call mb_wc", K(ret), KPHEX(temp_str.ptr(), temp_str.length())); - } else { + COMMON_LOG(WARN, "fail to call mb_wc", K(ret), KPHEX(temp_str.ptr(), temp_str.length()), K(ignore_invalid_character)); + if (OB_ERR_INCORRECT_STRING_VALUE == ret && ignore_invalid_character) { + ret = common::OB_SUCCESS; + wchar = INT32_MAX; + length = ObCharset::is_mbchar(collation_type, temp_str.ptr(), temp_str.ptr() + temp_str.length()); + if (length <= 0) { + int64_t min_len = 0; + ObCharset::get_mbminlen_by_coll(collation_type, min_len); + length = static_cast(min_len); + } + } + } + if (OB_SUCC(ret)) { encoding.assign_ptr(temp_str.ptr(), length); if (OB_FAIL(func(encoding, wchar))) { COMMON_LOG(WARN, "fail to call func", K(ret), K(encoding), diff --git a/src/sql/engine/expr/ob_expr_to_outfile_row.cpp b/src/sql/engine/expr/ob_expr_to_outfile_row.cpp index a9e3d4a0d6..aa391b8930 100644 --- a/src/sql/engine/expr/ob_expr_to_outfile_row.cpp +++ b/src/sql/engine/expr/ob_expr_to_outfile_row.cpp @@ -277,7 +277,7 @@ int ObExprToOutfileRow::print_field(char *buf, const int64_t buf_len, int64_t &p return ret; }; ObString tmp_str(out_info.tmp_buf_len_, tmp_pos, out_info.tmp_buf_); - OZ(ObCharsetUtils::foreach_char(tmp_str, out_info.print_params_.cs_type_, escape_func)); + OZ(ObCharsetUtils::foreach_char(tmp_str, out_info.print_params_.cs_type_, escape_func, true)); } if (need_enclose) { OZ(out_info.enclose_.print_plain_str_literal(buf, buf_len, pos, out_info.print_params_));