This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new c4341d3d43 [fix](like)prevent null pointer by unimplemented like_vec functions (#12910) c4341d3d43 is described below commit c4341d3d43c82387a7f065e2dfd69fcd3822c003 Author: starocean999 <40539150+starocean...@users.noreply.github.com> AuthorDate: Tue Sep 27 10:02:10 2022 +0800 [fix](like)prevent null pointer by unimplemented like_vec functions (#12910) * [fix](like)prevent null pointer by unimplemented like_vec functions * fix pushed like predicate on dict encoded column bug --- be/src/olap/like_column_predicate.cpp | 81 ++++++++++++++++++++++++---------- be/src/olap/like_column_predicate.h | 62 +++++++++++++++++--------- be/src/vec/columns/column_dictionary.h | 8 ++++ 3 files changed, 107 insertions(+), 44 deletions(-) diff --git a/be/src/olap/like_column_predicate.cpp b/be/src/olap/like_column_predicate.cpp index 56729c1c45..e0c9851f26 100644 --- a/be/src/olap/like_column_predicate.cpp +++ b/be/src/olap/like_column_predicate.cpp @@ -88,7 +88,7 @@ uint16_t LikeColumnPredicate<is_vectorized>::evaluate(const vectorized::IColumn& continue; } - StringValue cell_value = nested_col_ptr->get_value(data_array[idx]); + StringValue cell_value = nested_col_ptr->get_shrink_value(data_array[idx]); unsigned char flag = 0; (_state->function)(const_cast<vectorized::LikeSearchState*>(&_like_state), cell_value, pattern, &flag); @@ -115,45 +115,78 @@ uint16_t LikeColumnPredicate<is_vectorized>::evaluate(const vectorized::IColumn& } } else { if (column.is_column_dictionary()) { - if (LIKELY(_like_state.search_string_sv.len > 0)) { - auto* nested_col_ptr = vectorized::check_and_get_column< - vectorized::ColumnDictionary<vectorized::Int32>>(column); - auto& data_array = nested_col_ptr->get_data(); - StringValue values[size]; - unsigned char flags[size]; - for (uint16_t i = 0; i != size; i++) { - values[i] = nested_col_ptr->get_value(data_array[sel[i]]); - } - (_state->function_vec_dict)( - const_cast<vectorized::LikeSearchState*>(&_like_state), pattern, values, - size, flags); + if (_state->function_vec_dict) { + if (LIKELY(_like_state.search_string_sv.len > 0)) { + auto* nested_col_ptr = vectorized::check_and_get_column< + vectorized::ColumnDictionary<vectorized::Int32>>(column); + auto& data_array = nested_col_ptr->get_data(); + StringValue values[size]; + unsigned char flags[size]; + for (uint16_t i = 0; i != size; i++) { + values[i] = nested_col_ptr->get_shrink_value(data_array[sel[i]]); + } + (_state->function_vec_dict)( + const_cast<vectorized::LikeSearchState*>(&_like_state), pattern, + values, size, flags); - for (uint16_t i = 0; i != size; i++) { - uint16_t idx = sel[i]; - sel[new_size] = idx; - new_size += _opposite ^ flags[i]; + for (uint16_t i = 0; i != size; i++) { + uint16_t idx = sel[i]; + sel[new_size] = idx; + new_size += _opposite ^ flags[i]; + } + } else { + for (uint16_t i = 0; i != size; i++) { + uint16_t idx = sel[i]; + sel[new_size] = idx; + new_size += _opposite ^ true; + } } } else { + auto* nested_col_ptr = vectorized::check_and_get_column< + vectorized::ColumnDictionary<vectorized::Int32>>(column); + auto& data_array = nested_col_ptr->get_data(); for (uint16_t i = 0; i != size; i++) { uint16_t idx = sel[i]; sel[new_size] = idx; - new_size += _opposite ^ true; + StringValue cell_value = nested_col_ptr->get_value(data_array[idx]); + unsigned char flag = 0; + (_state->function)(const_cast<vectorized::LikeSearchState*>(&_like_state), + cell_value, pattern, &flag); + new_size += _opposite ^ flag; } } } else { - if (LIKELY(_like_state.search_string_sv.len > 0)) { + if (_state->function_vec) { + if (LIKELY(_like_state.search_string_sv.len > 0)) { + auto* data_array = + vectorized::check_and_get_column< + vectorized::PredicateColumnType<TYPE_STRING>>(column) + ->get_data() + .data(); + + (_state->function_vec)( + const_cast<vectorized::LikeSearchState*>(&_like_state), pattern, + data_array, sel, size, _opposite, &new_size); + } else { + for (uint16_t i = 0; i < size; i++) { + uint16_t idx = sel[i]; + sel[new_size] = idx; + new_size += _opposite ^ true; + } + } + } else { auto* data_array = vectorized::check_and_get_column< vectorized::PredicateColumnType<TYPE_STRING>>(column) ->get_data() .data(); - (_state->function_vec)(const_cast<vectorized::LikeSearchState*>(&_like_state), - pattern, data_array, sel, size, _opposite, &new_size); - } else { - for (uint16_t i = 0; i < size; i++) { + for (uint16_t i = 0; i != size; i++) { uint16_t idx = sel[i]; sel[new_size] = idx; - new_size += _opposite ^ true; + unsigned char flag = 0; + (_state->function)(const_cast<vectorized::LikeSearchState*>(&_like_state), + data_array[idx], pattern, &flag); + new_size += _opposite ^ flag; } } } diff --git a/be/src/olap/like_column_predicate.h b/be/src/olap/like_column_predicate.h index 303e176461..662f4ee59b 100644 --- a/be/src/olap/like_column_predicate.h +++ b/be/src/olap/like_column_predicate.h @@ -98,7 +98,7 @@ private: continue; } - StringValue cell_value = nested_col_ptr->get_value(data_array[i]); + StringValue cell_value = nested_col_ptr->get_shrink_value(data_array[i]); if constexpr (is_and) { unsigned char flag = 0; (_state->function)( @@ -118,31 +118,53 @@ private: } } else { if (column.is_column_dictionary()) { - if (LIKELY(_like_state.search_string_sv.len > 0)) { - auto* nested_col_ptr = vectorized::check_and_get_column< - vectorized::ColumnDictionary<vectorized::Int32>>(column); - auto& data_array = nested_col_ptr->get_data(); - StringValue values[size]; - unsigned char temp_flags[size]; - for (uint16_t i = 0; i != size; i++) { - values[i] = nested_col_ptr->get_value(data_array[i]); - } - (_state->function_vec_dict)( - const_cast<vectorized::LikeSearchState*>(&_like_state), pattern, - values, size, temp_flags); - for (uint16_t i = 0; i < size; i++) { - if constexpr (is_and) { - flags[i] &= _opposite ^ temp_flags[i]; - } else { - flags[i] = _opposite ^ temp_flags[i]; + if (_state->function_vec_dict) { + if (LIKELY(_like_state.search_string_sv.len > 0)) { + auto* nested_col_ptr = vectorized::check_and_get_column< + vectorized::ColumnDictionary<vectorized::Int32>>(column); + auto& data_array = nested_col_ptr->get_data(); + StringValue values[size]; + unsigned char temp_flags[size]; + for (uint16_t i = 0; i != size; i++) { + values[i] = nested_col_ptr->get_shrink_value(data_array[i]); + } + (_state->function_vec_dict)( + const_cast<vectorized::LikeSearchState*>(&_like_state), pattern, + values, size, temp_flags); + for (uint16_t i = 0; i < size; i++) { + if constexpr (is_and) { + flags[i] &= _opposite ^ temp_flags[i]; + } else { + flags[i] = _opposite ^ temp_flags[i]; + } + } + } else { + for (uint16_t i = 0; i < size; i++) { + if constexpr (is_and) { + flags[i] &= _opposite ^ true; + } else { + flags[i] = _opposite ^ true; + } } } } else { + auto* nested_col_ptr = vectorized::check_and_get_column< + vectorized::ColumnDictionary<vectorized::Int32>>(column); + auto& data_array = nested_col_ptr->get_data(); for (uint16_t i = 0; i < size; i++) { + StringValue cell_value = nested_col_ptr->get_value(data_array[i]); if constexpr (is_and) { - flags[i] &= _opposite ^ true; + unsigned char flag = 0; + (_state->function)( + const_cast<vectorized::LikeSearchState*>(&_like_state), + cell_value, pattern, &flag); + flags[i] &= _opposite ^ flag; } else { - flags[i] = _opposite ^ true; + unsigned char flag = 0; + (_state->function)( + const_cast<vectorized::LikeSearchState*>(&_like_state), + cell_value, pattern, &flag); + flags[i] = _opposite ^ flag; } } } diff --git a/be/src/vec/columns/column_dictionary.h b/be/src/vec/columns/column_dictionary.h index 2c09d4fb7c..7aa578d665 100644 --- a/be/src/vec/columns/column_dictionary.h +++ b/be/src/vec/columns/column_dictionary.h @@ -281,6 +281,14 @@ public: inline const StringValue& get_value(value_type code) const { return _dict.get_value(code); } + inline StringValue get_shrink_value(value_type code) const { + StringValue result = _dict.get_value(code); + if (_type == OLAP_FIELD_TYPE_CHAR) { + result.len = strnlen(result.ptr, result.len); + } + return result; + } + class Dictionary { public: Dictionary() : _dict_data(new DictContainer()), _total_str_len(0) {}; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org