[fix](array-type) fix the wrong result of array_join function (#13477)

this pr is used to fix the wrong result of array_join function.
before the change, the array_join function will return wrong result.
MySQL [example_db]> select array_join(["", "1", "2"], '');
+--------------------------------------+
| array_join(ARRAY('', '1', '2'), '') |
+--------------------------------------+
| 1_2 |
+--------------------------------------+
3.after the change, the array_join function will return correct result.
MySQL [example_db]> select array_join(["", "1", "2"], '');
+--------------------------------------+
| array_join(ARRAY('', '1', '2'), '') |
+--------------------------------------+
| _1_2 |
+--------------------------------------+
Issue Number: #7570
This commit is contained in:
carlvinhust2012
2022-10-21 17:36:44 +08:00
committed by GitHub
parent ddc08ee690
commit a555f45834
3 changed files with 60 additions and 7 deletions

View File

@ -106,9 +106,10 @@ private:
}
static void _fill_result_string(const std::string& input_str, const std::string& sep_str,
std::string& result_str) {
if (result_str.size() == 0) {
std::string& result_str, bool& is_first_elem) {
if (is_first_elem) {
result_str.append(input_str);
is_first_elem = false;
} else {
result_str.append(sep_str);
result_str.append(input_str);
@ -133,12 +134,13 @@ private:
size_t prev_src_offset = 0;
for (auto curr_src_offset : src_offsets) {
std::string result_str;
bool is_first_elem = true;
for (size_t j = prev_src_offset; j < curr_src_offset; ++j) {
if (src_null_map && src_null_map[j]) {
if (null_replace_str.size() == 0) {
continue;
} else {
_fill_result_string(null_replace_str, sep_str, result_str);
_fill_result_string(null_replace_str, sep_str, result_str, is_first_elem);
continue;
}
}
@ -147,10 +149,10 @@ private:
DecimalV2Value decimal_value =
(DecimalV2Value)(src_data_concrete->get_data()[j]);
std::string decimal_str = decimal_value.to_string();
_fill_result_string(decimal_str, sep_str, result_str);
_fill_result_string(decimal_str, sep_str, result_str, is_first_elem);
} else {
std::string elem_str = remove_nullable(nested_type)->to_string(src_column, j);
_fill_result_string(elem_str, sep_str, result_str);
_fill_result_string(elem_str, sep_str, result_str, is_first_elem);
}
}
@ -174,19 +176,20 @@ private:
size_t prev_src_offset = 0;
for (auto curr_src_offset : src_offsets) {
std::string result_str;
bool is_first_elem = true;
for (size_t j = prev_src_offset; j < curr_src_offset; ++j) {
if (src_null_map && src_null_map[j]) {
if (null_replace_str.size() == 0) {
continue;
} else {
_fill_result_string(null_replace_str, sep_str, result_str);
_fill_result_string(null_replace_str, sep_str, result_str, is_first_elem);
continue;
}
}
StringRef src_str_ref = src_data_concrete->get_data_at(j);
std::string elem_str(src_str_ref.data, src_str_ref.size);
_fill_result_string(elem_str, sep_str, result_str);
_fill_result_string(elem_str, sep_str, result_str, is_first_elem);
}
dest_column_ptr->insert_data(result_str.c_str(), result_str.size());