This is an automated email from the ASF dual-hosted git repository. yangzhg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new 16020cb [fix](lateral-view) Fix bug that explode_json_array_string return unstable result (#8152) 16020cb is described below commit 16020cbdf9d1ec685514380b63eb59a8897477da Author: Mingyu Chen <morningman....@gmail.com> AuthorDate: Mon Feb 21 09:38:36 2022 +0800 [fix](lateral-view) Fix bug that explode_json_array_string return unstable result (#8152) Co-authored-by: morningman <chenmin...@baidu.com> --- be/src/exprs/table_function/explode_json_array.cpp | 17 +++++++++++------ be/src/exprs/table_function/explode_json_array.h | 1 - thirdparty/download-thirdparty.sh | 8 +++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/be/src/exprs/table_function/explode_json_array.cpp b/be/src/exprs/table_function/explode_json_array.cpp index e82c9ec..43fb1f3 100644 --- a/be/src/exprs/table_function/explode_json_array.cpp +++ b/be/src/exprs/table_function/explode_json_array.cpp @@ -68,8 +68,10 @@ int ParsedData::set_output(ExplodeJsonArrayType type, rapidjson::Document& docum switch (v.GetType()) { case rapidjson::Type::kStringType: _backup_string.emplace_back(v.GetString(), v.GetStringLength()); - _data_string.emplace_back(_backup_string.back()); _string_nulls.push_back(false); + // do not set _data_string here. + // Because the address of the string stored in `_backup_string` may + // change each time `emplace_back()` is called. break; case rapidjson::Type::kNumberType: if (v.IsUint()) { @@ -84,8 +86,10 @@ int ParsedData::set_output(ExplodeJsonArrayType type, rapidjson::Document& docum wbytes = sprintf(tmp_buf, "%f", v.GetDouble()); } _backup_string.emplace_back(tmp_buf, wbytes); - _data_string.emplace_back(_backup_string.back()); _string_nulls.push_back(false); + // do not set _data_string here. + // Because the address of the string stored in `_backup_string` may + // change each time `emplace_back()` is called. break; case rapidjson::Type::kFalseType: _data_string.emplace_back(true_value); @@ -106,6 +110,11 @@ int ParsedData::set_output(ExplodeJsonArrayType type, rapidjson::Document& docum } ++i; } + // Must set _data_string at the end, so that we can + // save the real addr of string in `_backup_string` to `_data_string`. + for (auto& str : _backup_string) { + _data_string.emplace_back(str); + } break; } default: @@ -139,21 +148,17 @@ Status ExplodeJsonArrayTableFunction::process(TupleRow* tuple_row) { StringVal text = _expr_context->root()->get_child(0)->get_string_val(_expr_context, tuple_row); if (text.is_null || text.len == 0) { - // _set_null_output(); _is_current_empty = true; } else { rapidjson::Document document; document.Parse((char*) text.ptr, text.len); if (UNLIKELY(document.HasParseError()) || !document.IsArray() || document.GetArray().Size() == 0) { - // _set_null_output(); _is_current_empty = true; } else { _cur_size = _parsed_data.set_output(_type, document); _cur_offset = 0; - // _eos = _cur_size == 0; } } - // _is_current_empty = _eos; return Status::OK(); } diff --git a/be/src/exprs/table_function/explode_json_array.h b/be/src/exprs/table_function/explode_json_array.h index ae5c657..8ecbd2d 100644 --- a/be/src/exprs/table_function/explode_json_array.h +++ b/be/src/exprs/table_function/explode_json_array.h @@ -91,7 +91,6 @@ struct ParsedData { *output = _data[offset]; break; case ExplodeJsonArrayType::STRING: - // LOG(INFO) << "cmy get_value offset: " << offset << ", is null: " << _string_nulls[offset] << ", data: " << (_string_nulls[offset] ? "null2" : _backup_string[offset]); *output = _string_nulls[offset] ? nullptr : &_data_string[offset]; break; default: diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh index c6650bd..768e92d 100755 --- a/thirdparty/download-thirdparty.sh +++ b/thirdparty/download-thirdparty.sh @@ -72,6 +72,8 @@ md5sum_func() { return 0 } +# return 0 if download succeed. +# return 1 if not. download_func() { local FILENAME=$1 local DOWNLOAD_URL=$2 @@ -134,18 +136,18 @@ do if test "x$REPOSITORY_URL" = x; then URL=$TP_ARCH"_DOWNLOAD" download_func ${!NAME} ${!URL} $TP_SOURCE_DIR ${!MD5SUM} - if [ "$?"x == "0"x ]; then + if [ "$?"x != "0"x ]; then echo "Failed to download ${!NAME}" exit 1 fi else URL="${REPOSITORY_URL}/${!NAME}" download_func ${!NAME} ${URL} $TP_SOURCE_DIR ${!MD5SUM} - if [ "$?x" == "0x" ]; then + if [ "$?x" != "0x" ]; then #try to download from home URL=$TP_ARCH"_DOWNLOAD" download_func ${!NAME} ${!URL} $TP_SOURCE_DIR ${!MD5SUM} - if [ "$?x" == "1x" ]; then + if [ "$?"x != "0"x ]; then echo "Failed to download ${!NAME}" exit 1 # download failed again exit. fi --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org