From 902896a63e40663f331f3a98f46cbddf70693a2a Mon Sep 17 00:00:00 2001 From: SevenJ-swj Date: Fri, 18 Aug 2023 11:44:56 +0800 Subject: [PATCH] compat convert mistaken code with oracle --- deps/oblib/src/lib/charset/ob_charset.cpp | 132 ++++++++++-------- deps/oblib/src/lib/charset/ob_charset.h | 1 + src/sql/engine/expr/ob_datum_cast.cpp | 35 +---- src/sql/engine/expr/ob_expr_to_clob.cpp | 19 ++- src/sql/resolver/expr/ob_raw_expr_util.cpp | 1 + .../expr/r/mysql/func_regexp.result | 8 +- 6 files changed, 100 insertions(+), 96 deletions(-) diff --git a/deps/oblib/src/lib/charset/ob_charset.cpp b/deps/oblib/src/lib/charset/ob_charset.cpp index 42a88dcff8..23c027eb86 100644 --- a/deps/oblib/src/lib/charset/ob_charset.cpp +++ b/deps/oblib/src/lib/charset/ob_charset.cpp @@ -918,7 +918,7 @@ uint64_t ObCharset::hash(ObCollationType collation_type, ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->coll)) { - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->coll)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->coll), K(lbt())); } else { seed = 0xc6a4a7935bd1e995; cs->coll->hash_sort(cs, reinterpret_cast(str), str_len, @@ -955,7 +955,7 @@ int ObCharset::like_range(ObCollationType collation_type, OB_ISNULL(max_str_len) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type), KP(max_str), K(max_str_len), @@ -982,7 +982,7 @@ int ObCharset::like_range(ObCollationType collation_type, size_t res_size = *min_str_len < *max_str_len ? *min_str_len : *max_str_len; if (OB_ISNULL(cs->coll)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->coll)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->coll)); } else if (0 != cs->coll->like_range(cs, like_str.ptr(), like_str.length(), @@ -1011,11 +1011,11 @@ size_t ObCharset::strlen_char(const ObCollationType collation_type, if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset), K(lbt())); } else { ret = cs->cset->numchars(cs, str, str + str_len); } @@ -1031,11 +1031,11 @@ size_t ObCharset::strlen_byte_no_sp(const ObCollationType collation_type, if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset), K(lbt())); } else { ret = cs->cset->lengthsp(cs, str, str_len); } @@ -1051,7 +1051,7 @@ int ObCharset::well_formed_len(ObCollationType collation_type, const char *str, collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", K(collation_type), K(lbt())); } else if (OB_UNLIKELY(NULL == str && 0 != str_len)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument, str is null and str_len is nonzero", @@ -1060,7 +1060,7 @@ int ObCharset::well_formed_len(ObCollationType collation_type, const char *str, ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset), K(lbt())); } else { int32_t error = 0; well_formed_len = cs->cset->well_formed_len(cs, str, str + str_len, UINT64_MAX, &error); @@ -1085,7 +1085,7 @@ int ObCharset::well_formed_len(ObCollationType collation_type, const char *str, collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", K(collation_type)); } else if (OB_UNLIKELY(NULL == str && 0 != str_len)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument, str is null and str_len is nonzero", @@ -1094,7 +1094,7 @@ int ObCharset::well_formed_len(ObCollationType collation_type, const char *str, ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); } else { well_formed_len = cs->cset->well_formed_len(cs, str, str + str_len, UINT64_MAX, &well_formed_error); } @@ -1116,11 +1116,11 @@ size_t ObCharset::charpos(const ObCollationType collation_type, if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", K(collation_type)); + LOG_WARN_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { - LOG_ERROR_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", K(cs), K(cs->cset), K(lbt())); } else { res_pos = cs->cset->charpos(cs, str, str + str_len, length); if (res_pos > str_len) { @@ -1144,11 +1144,11 @@ size_t ObCharset::max_bytes_charpos(const ObCollationType collation_type, if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset), K(lbt())); } else { size_t char_len_tmp = 0; ret = cs->cset->max_bytes_charpos(cs, str, str + str_len, max_bytes, &char_len_tmp); @@ -1167,11 +1167,11 @@ bool ObCharset::wildcmp(ObCollationType collation_type, if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->coll)) { - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->coll)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->coll), K(lbt())); } else { int tmp = cs->coll->wildcmp(cs, str.ptr(), str.ptr() + str.length(), wildstr.ptr(), wildstr.ptr() + wildstr.length(), @@ -1195,14 +1195,14 @@ int ObCharset::mb_wc(ObCollationType collation_type, collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); ob_wc_t my_wc; if (OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); } else { int tmp = cs->cset->mb_wc(cs, &my_wc, reinterpret_cast(mb.ptr()), reinterpret_cast(mb.ptr()+mb.length())); @@ -1228,14 +1228,14 @@ int ObCharset::mb_wc(ObCollationType collation_type, collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); ob_wc_t my_wc; if (OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); } else { int tmp = cs->cset->mb_wc(cs, &my_wc, reinterpret_cast(mb), reinterpret_cast(mb + mb_size)); @@ -1260,13 +1260,13 @@ int ObCharset::display_len(ObCollationType collation_type, collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); } else { const uchar *buf = reinterpret_cast(mb.ptr()); int64_t buf_size = mb.length(); @@ -1311,13 +1311,13 @@ int ObCharset::max_display_width_charpos(ObCollationType collation_type, const c collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); } else { char_pos = 0; const uchar *buf = reinterpret_cast(mb); @@ -1365,12 +1365,12 @@ int ObCharset::wc_mb(ObCollationType collation_type, int32_t wc, char *buff, int if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(ret), K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs) || OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(ret)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(ret)); } else { int tmp = cs->cset->wc_mb(cs, wc, reinterpret_cast(buff), reinterpret_cast(buff + buff_len)); @@ -1559,8 +1559,8 @@ ObCharsetType ObCharset::charset_type(const char *cs_name) { ObCharsetType ct = CHARSET_INVALID; if (OB_ISNULL(cs_name)) { - LOG_ERROR_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", - K(ct), KP(cs_name), K(ct)); + LOG_WARN_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", + K(ret), K(ct), KP(cs_name), K(lbt())); } else { ObString cs_name_str = ObString::make_string(cs_name); ct = charset_type(cs_name_str); @@ -1917,7 +1917,7 @@ int ObCharset::charset_name_by_coll(ObCollationType collation_type, ObString &cs ObString tmp_cs_name = ObString(charset_name(charset_type)); if (OB_UNLIKELY(tmp_cs_name == "invalid_type")) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("charset str is invalid_type", K(ret), K(charset_type), K(collation_type)); + LOG_WARN("charset str is invalid_type", K(ret), K(charset_type), K(collation_type)); } else { cs_name = tmp_cs_name; } @@ -2131,7 +2131,7 @@ int ObCharset::aggregate_collation( res_level = (CS_TYPE_GB18030_2022_BIN == collation_type1) ? collation_level1 : collation_level2; } else { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("Unexpected charset", K(collation_type1), K(collation_type2), KCSTRING(lbt())); + LOG_WARN("Unexpected charset", K(ret), K(collation_type1), K(collation_type2), KCSTRING(lbt())); } } @@ -2165,8 +2165,8 @@ bool ObCharset::is_bin_sort(ObCollationType collation_type) if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", - K(ret), K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", + K(ret), K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); ret = (0 != (cs->state & OB_CS_BINSORT)); @@ -2379,11 +2379,11 @@ int ObCharset::first_valid_char( collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else if (OB_UNLIKELY(NULL == buf)) { ret = OB_NOT_INIT; - LOG_ERROR("Null buffer passed in", K(ret), KP(buf)); + LOG_WARN("Null buffer passed in", K(ret), KP(buf)); } else if (buf_size <= 0) { char_len = 0; } else { @@ -2392,7 +2392,7 @@ int ObCharset::first_valid_char( ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset)) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); + LOG_WARN("unexpected error. invalid argument(s)", K(cs), K(cs->cset)); } else { len = static_cast(cs->cset->well_formed_len(cs, buf, buf + buf_size, 1, &error)); if (OB_LIKELY(0 == error)) { @@ -2650,8 +2650,8 @@ bool ObCharset::case_mode_equal(const ObNameCaseMode case_mode, const ObString & bool is_equal = false; if (OB_UNLIKELY(OB_NAME_CASE_INVALID >= case_mode || case_mode >= OB_NAME_CASE_MAX)) { - LOG_ERROR_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid cast_mode", - K(case_mode)); + LOG_WARN_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid cast_mode", + K(case_mode), K(ret), K(lbt())); } else { ObCollationType collation_type = CS_TYPE_INVALID; if (OB_ORIGIN_AND_SENSITIVE == case_mode) { @@ -2674,8 +2674,8 @@ bool ObCharset::is_space(const ObCollationType collation_type, char c) if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", - K(ret), K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", + K(ret), K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); ret = ob_isspace(cs, c); @@ -2689,8 +2689,8 @@ bool ObCharset::is_graph(const ObCollationType collation_type, char c) if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", - K(ret), K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", + K(ret), K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); ret = ob_isgraph(cs, c); @@ -2704,8 +2704,8 @@ bool ObCharset::usemb(const ObCollationType collation_type) if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", - K(ret), K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", + K(ret), K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); ret = use_mb(cs); @@ -2719,8 +2719,8 @@ int ObCharset::is_mbchar(const ObCollationType collation_type, const char *str, if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR("unexpected error. invalid argument(s)", - K(ret), K(collation_type)); + LOG_WARN("unexpected error. invalid argument(s)", + K(ret), K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); ret = ob_ismbchar(cs, str, end); @@ -2733,8 +2733,7 @@ const ObCharsetInfo *ObCharset::get_charset(const ObCollationType collation_type ObCharsetInfo *ret = NULL; if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX)) { - LOG_ERROR_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", - K(collation_type)); + LOG_WARN_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", K(collation_type), K(lbt())); } else { ret = static_cast(ObCharset::charset_arr[collation_type]); } @@ -2748,7 +2747,7 @@ int ObCharset::get_mbmaxlen_by_coll(const ObCollationType collation_type, int64_ collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); @@ -2764,7 +2763,7 @@ int ObCharset::get_mbminlen_by_coll(const ObCollationType collation_type, int64_ collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(ret), K(collation_type)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); @@ -2805,7 +2804,7 @@ int ObCharset::fit_string(const ObCollationType collation_type, OB_ISNULL(str) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { ret = OB_ERR_UNEXPECTED; - LOG_ERROR("unexpected error. invalid argument(s)", + LOG_WARN("unexpected error. invalid argument(s)", K(collation_type), KP(str), K(str_len), K(len_limit_in_byte)); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); @@ -2847,7 +2846,7 @@ inline bool ObCharset::is_argument_valid(const ObCharsetInfo *cs, const char *st OB_ISNULL(cs->cset)) { is_arg_valid = false; const ObFatalErrExtraInfoGuard *extra_info = ObFatalErrExtraInfoGuard::get_thd_local_val_ptr(); - BACKTRACE_RET(ERROR, OB_INVALID_ARGUMENT, true, "invalid argument. charset info = %p, str = %p, str_len = %ld, extra_info=(%s)", cs, str, str_len, (NULL == extra_info) ? NULL : to_cstring(*extra_info)); + BACKTRACE_RET(WARN, OB_INVALID_ARGUMENT, true, "invalid argument. charset info = %p, str = %p, str_len = %ld, extra_info=(%s), lbt=(%s)", cs, str, str_len, (NULL == extra_info) ? NULL : to_cstring(*extra_info), lbt()); } } return is_arg_valid; @@ -2864,26 +2863,28 @@ inline bool ObCharset::is_argument_valid(const ObCollationType collation_type, c (OB_ISNULL(str2) && OB_UNLIKELY(0 != str_len2))) { is_arg_valid = false; const ObFatalErrExtraInfoGuard *extra_info = ObFatalErrExtraInfoGuard::get_thd_local_val_ptr(); - BACKTRACE_RET(ERROR, OB_INVALID_ARGUMENT, true, "invalid argument." + BACKTRACE_RET(WARN, OB_INVALID_ARGUMENT, true, "invalid argument." "collation_type = %d," "str1 = %p," "str1_len = %ld," "str2 = %p," "str2_len = %ld," - "extra_info=(%s)", collation_type, str1, str_len1, str2, str_len2, - (NULL == extra_info) ? NULL : to_cstring(*extra_info)); + "extra_info=(%s)," + "lbt=(%s)", collation_type, str1, str_len1, str2, str_len2, + (NULL == extra_info) ? NULL : to_cstring(*extra_info), lbt()); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); if (OB_ISNULL(cs->cset) || OB_ISNULL(cs->coll)) { is_arg_valid = false; - BACKTRACE_RET(ERROR, OB_INVALID_ARGUMENT, true, "invalid argument." + BACKTRACE_RET(WARN, OB_INVALID_ARGUMENT, true, "invalid argument." "collation_type = %d," "str1 = %p," "str1_len = %ld," "str2 = %p," "str2_len = %ld," "charset handler = %p," - "collation handler = %p", collation_type, str1, str_len1, str2, str_len2, cs->cset, cs->coll); + "collation handler = %p," + "lbt=(%s)", collation_type, str1, str_len1, str2, str_len2, cs->cset, cs->coll, lbt()); } } } @@ -3108,8 +3109,7 @@ bool ObCharset::is_cs_nonascii(ObCollationType collation_type) if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || collation_type >= CS_TYPE_MAX) || OB_ISNULL(ObCharset::charset_arr[collation_type])) { - LOG_ERROR_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", - K(collation_type)); + LOG_WARN_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", K(ret), K(collation_type), K(lbt())); } else { ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); is_cs_nonascii = !!(cs->state & OB_CS_NONASCII); @@ -3117,6 +3117,20 @@ bool ObCharset::is_cs_nonascii(ObCollationType collation_type) return is_cs_nonascii; } +bool ObCharset::is_cs_unicode(ObCollationType collation_type) +{ + bool is_cs_unicode = false; + if (OB_UNLIKELY(collation_type <= CS_TYPE_INVALID || + collation_type >= CS_TYPE_MAX) || + OB_ISNULL(ObCharset::charset_arr[collation_type])) { + LOG_WARN_RET(OB_INVALID_ARGUMENT, "unexpected error. invalid argument(s)", K(ret), K(collation_type), K(lbt())); + } else { + ObCharsetInfo *cs = static_cast(ObCharset::charset_arr[collation_type]); + is_cs_unicode = !!(cs->state & OB_CS_UNICODE); + } + return is_cs_unicode; +} + bool ObCharset::is_cjk_charset(ObCollationType collation_type) { ObCharsetType cs_type = ObCharset::charset_type_by_coll(collation_type); diff --git a/deps/oblib/src/lib/charset/ob_charset.h b/deps/oblib/src/lib/charset/ob_charset.h index 80d22a974b..d1ecdee2c0 100644 --- a/deps/oblib/src/lib/charset/ob_charset.h +++ b/deps/oblib/src/lib/charset/ob_charset.h @@ -536,6 +536,7 @@ public: ObString &result); static bool is_cs_nonascii(ObCollationType collation_type); + static bool is_cs_unicode(ObCollationType collation_type); static bool is_cjk_charset(ObCollationType collation_type); static bool is_valid_connection_collation(ObCollationType collation_type); static const char* get_oracle_charset_name_by_charset_type(ObCharsetType charset_type); diff --git a/src/sql/engine/expr/ob_datum_cast.cpp b/src/sql/engine/expr/ob_datum_cast.cpp index 8c19d58341..0138b52ac3 100644 --- a/src/sql/engine/expr/ob_datum_cast.cpp +++ b/src/sql/engine/expr/ob_datum_cast.cpp @@ -1380,37 +1380,10 @@ static int common_string_string(const ObExpr &expr, LOG_WARN("alloc memory failed", K(ret)); } else if (OB_FAIL(ObCharset::charset_convert(in_cs_type, in_str.ptr(), in_str.length(), out_cs_type, buf, - buf_len, result_len))) { - if (CM_IS_IGNORE_CHARSET_CONVERT_ERR(expr.extra_)) { - ObString question_mark = ObCharsetUtils::get_const_str(out_cs_type, '?'); - int32_t str_offset = 0; - int64_t buf_offset = 0; - while (str_offset < in_str.length() && buf_offset + question_mark.length() <= buf_len) { - int64_t offset = ObCharset::charpos(in_cs_type, - in_str.ptr() + str_offset, in_str.length() - str_offset, 1); - if (OB_UNLIKELY(0 == offset)) { - break; - } - ret = ObCharset::charset_convert(in_cs_type, in_str.ptr() + str_offset, - offset, out_cs_type, buf + buf_offset, buf_len - buf_offset, result_len); - str_offset += offset; - if (OB_SUCCESS == ret) { - buf_offset += result_len; - } else { - MEMCPY(buf + buf_offset, question_mark.ptr(), question_mark.length()); - buf_offset += question_mark.length(); - } - } - if (buf_offset > buf_len) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("buf_offset > buf_len, unexpected", K(ret)); - } else { - result_len = buf_offset; - ret = OB_SUCCESS; - LOG_WARN("charset convert failed", K(ret), K(in_cs_type), K(out_cs_type)); - res_datum.set_string(buf, result_len); - } - } + buf_len, result_len, lib::is_mysql_mode(), + !CM_IS_IGNORE_CHARSET_CONVERT_ERR(expr.extra_), + ObCharset::is_cs_unicode(out_cs_type) ? 0xFFFD : '?'))) { + LOG_WARN("charset convert failed", K(ret)); } else { res_datum.set_string(buf, result_len); } diff --git a/src/sql/engine/expr/ob_expr_to_clob.cpp b/src/sql/engine/expr/ob_expr_to_clob.cpp index 3bc526f16c..99dd0da125 100644 --- a/src/sql/engine/expr/ob_expr_to_clob.cpp +++ b/src/sql/engine/expr/ob_expr_to_clob.cpp @@ -103,7 +103,24 @@ int ObExprToClob::calc_to_clob_expr(const ObExpr &expr, ObEvalCtx &ctx, } else { ObString raw_string = arg->get_string(); ObTextStringDatumResult str_result(expr.datum_meta_.type_, &expr, &ctx, &res); - if (OB_FAIL(str_result.init(raw_string.length()))) { + uint32_t result_len = 0; + ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx); + common::ObArenaAllocator &temp_allocator = tmp_alloc_g.get_allocator(); + char *buf = NULL; + int64_t reserve_len = raw_string.length() * 4; + if (OB_ISNULL(buf = (char*)temp_allocator.alloc(reserve_len))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("alloc mem failed", K(ret)); + } else if (OB_FAIL(ObCharset::charset_convert(cs_type, raw_string.ptr(), raw_string.length(), + cs_type, buf, reserve_len, result_len, false, false, + ObCharset::is_cs_unicode(cs_type) ? 0xFFFD : '?'))) { + LOG_WARN("charset convert failed", K(ret)); + } else { + raw_string.assign_ptr(buf, result_len); + } + LOG_DEBUG("try convert param value", K(raw_string), K(ObHexStringWrap(raw_string)), K(cs_type)); + if (OB_FAIL(ret)) { + } else if (OB_FAIL(str_result.init(raw_string.length()))) { LOG_WARN("init lob result failed"); } else if (OB_FAIL(str_result.append(raw_string.ptr(), raw_string.length()))) { LOG_WARN("append lob result failed"); diff --git a/src/sql/resolver/expr/ob_raw_expr_util.cpp b/src/sql/resolver/expr/ob_raw_expr_util.cpp index 30ae3c9f29..3979a7fd6c 100644 --- a/src/sql/resolver/expr/ob_raw_expr_util.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_util.cpp @@ -3695,6 +3695,7 @@ int ObRawExprUtils::try_add_cast_expr_above(ObRawExprFactory *expr_factory, // setup zerofill cm // eg: select concat(cast(c_zf as char(10)), cast(col_no_zf as char(10))) from t1; ObCastMode cm_zf = cm; + cm_zf |= CM_CHARSET_CONVERT_IGNORE_ERR; if (expr.get_result_type().has_result_flag(ZEROFILL_FLAG)) { cm_zf |= CM_ZERO_FILL; } diff --git a/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result b/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result index 07313b368d..3b62d80f36 100644 --- a/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result +++ b/tools/deploy/mysql_test/test_suite/expr/r/mysql/func_regexp.result @@ -6417,9 +6417,7 @@ INSERT INTO `table10_bigint` VALUES (9,3,NULL,7,6.00000,NULL,NULL,NULL,NULL,8,1, set names GB18030; SELECT TRIM( SUBSTRING( SUBSTRING( '∷ ∶ ∫ ∮ ∝ ∞ ∧ ∨ ∑ ∏ ∪ ∩ ∈ ∵ ∴ ⊥ ∥ ∠ ⌒ ⊙ √∟⊿ ㏒ ㏑ % ‰' , 1, LEAST( 228, 20 ) ) , 1 , LEAST( 228, 20 ) ) ) NOT REGEXP CONCAT( 'tu', '%' ) FROM table10_bigint WHERE col_int NOT IN ( 5387431054241955840 , 13633803446934044672 , 65066 , 45808 , 6755399441055744000 ) ORDER BY col_char_20 DESC , pk ASC LIMIT 6 OFFSET 1; TRIM( SUBSTRING( SUBSTRING( ' √∟ % ' , 1, LEAST( 228, 20 ) ) , 1 , LEAST( 228, 20 ) ) ) NOT REGEXP CONCAT( 'tu', '%' ) -NULL -NULL -NULL -Warnings: -Warning 1300 Invalid utf16 character string: '' +1 +1 +1 drop database ly;