github-actions[bot] commented on code in PR #17629: URL: https://github.com/apache/doris/pull/17629#discussion_r1131920161
########## be/src/olap/rowset/segment_v2/inverted_index_reader.h: ########## @@ -61,6 +67,520 @@ MATCH_PHRASE_QUERY = 7, }; +inline std::string inverted_index_query_op_to_string(InvertedIndexQueryOp op) { + switch (op) { + case InvertedIndexQueryOp::EQUAL_QUERY: + return "="; + case InvertedIndexQueryOp::LESS_EQUAL_QUERY: + return "<="; + case InvertedIndexQueryOp::LESS_THAN_QUERY: + return "<<"; + case InvertedIndexQueryOp::GREATER_THAN_QUERY: + return ">>"; + case InvertedIndexQueryOp::GREATER_EQUAL_QUERY: + return ">="; + case InvertedIndexQueryOp::MATCH_ANY_QUERY: + return "match_any"; + case InvertedIndexQueryOp::MATCH_ALL_QUERY: + return "match_all"; + case InvertedIndexQueryOp::MATCH_PHRASE_QUERY: + return "match_phrase"; + default: + return ""; + } +} + +inline bool is_match_query(InvertedIndexQueryOp query_op) { + return (query_op == InvertedIndexQueryOp::MATCH_ANY_QUERY || + query_op == InvertedIndexQueryOp::MATCH_ALL_QUERY || + query_op == InvertedIndexQueryOp::MATCH_PHRASE_QUERY); +} + +inline bool is_equal_query(InvertedIndexQueryOp query_op) { + return (query_op == InvertedIndexQueryOp::EQUAL_QUERY); +} + +inline bool is_range_query(InvertedIndexQueryOp query_op) { + return (query_op == InvertedIndexQueryOp::LESS_EQUAL_QUERY || + query_op == InvertedIndexQueryOp::LESS_THAN_QUERY || + query_op == InvertedIndexQueryOp::GREATER_THAN_QUERY || + query_op == InvertedIndexQueryOp::GREATER_EQUAL_QUERY); +} + +template <PrimitiveType Type> +//template <FieldType field_type> +class InvertedIndexQuery { + using CppType = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; + +public: + /*class QueryEncodedValue { + public: + QueryEncodedValue() = default; + QueryEncodedValue(const uint8_t* encoded_value) : _encoded_value(encoded_value) {} + QueryEncodedValue Operator = (const std::string& encoded_value) { + _encoded_value = (const uint8_t*)encoded_value.c_str(); + } + ~QueryEncodedValue() = default; + + const uint8_t* encoded_value() const { return _encoded_value; } + + bool operator<(const QueryEncodedValue& value) const { return cmp(value) < 0; } + + bool operator<=(const QueryEncodedValue& value) const { return cmp(value) <= 0; } + + bool operator>(const QueryEncodedValue& value) const { return cmp(value) > 0; } + + bool operator>=(const QueryEncodedValue& value) const { return cmp(value) >= 0; } + + bool operator==(const QueryEncodedValue& value) const { return cmp(value) == 0; } + + bool operator!=(const QueryEncodedValue& value) const { return cmp(value) != 0; } + + int32_t cmp(const QueryEncodedValue& other) const { + return lucene::util::FutureArrays::CompareUnsigned( + (const uint8_t*)encoded_value().c_str(), 0, 0 + sizeof(CppType), + (const uint8_t*)other.encoded_value().c_str(), 0, 0 + sizeof(CppType)); + } + + private: + const uint8_t* _encoded_value; + };*/ + + InvertedIndexQuery(const TypeInfo* type_info) + : _low_value(TYPE_MIN), + _high_value(TYPE_MAX), + _low_op(InvertedIndexQueryOp::GREATER_THAN_QUERY), + _high_op(InvertedIndexQueryOp::LESS_THAN_QUERY), + _type_info(type_info) { + //FieldTypeTraits<field_type>::set_to_max(&_high_value); + //FieldTypeTraits<field_type>::set_to_min(&_low_value); + _value_key_coder = get_key_coder(_type_info->type()); + _value_key_coder->full_encode_ascending(&TYPE_MAX, &_high_value_encoded); + _value_key_coder->full_encode_ascending(&TYPE_MIN, &_low_value_encoded); + } + + // if op is match, we just need to add match_value to fixed_values_str, no need to add to fixed_values. + // because fulltext match only uses fixed_values_str. + Status add_match_value(InvertedIndexQueryOp op, const std::string& match_value) { + DCHECK(op == InvertedIndexQueryOp::MATCH_ANY_QUERY || + op == InvertedIndexQueryOp::MATCH_ALL_QUERY || + op == InvertedIndexQueryOp::MATCH_PHRASE_QUERY); + _fixed_values_str.insert(match_value); + _high_op = _low_op = op; + _high_value = TYPE_MIN; + _low_value = TYPE_MAX; + return Status::OK(); + } + + Status add_fixed_value(InvertedIndexQueryOp op, const CppType& value, + const std::string& value_str); + Status add_fixed_value(InvertedIndexQueryOp op, const CppType& value) { + _fixed_values.insert(value); + std::string tmp; + _value_key_coder->full_encode_ascending(&value, &tmp); + _fixed_values_encoded.insert(tmp); + + _high_value = value; + _low_value = value; + _high_op = op; + _low_op = op; + + return Status::OK(); + } + + Status from_string(const std::string& str_value, CppType& value, int precision, int scale); + Status add_value(InvertedIndexQueryOp op, const CppType& value) { + if (is_match_query(op) || is_equal_query(op)) { + return add_fixed_value(op, value); + } + if (_high_value > _low_value) { + switch (op) { + case InvertedIndexQueryOp::GREATER_THAN_QUERY: { + if (value >= _low_value) { + _low_value = value; + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::GREATER_EQUAL_QUERY: { + if (value > _low_value) { + _low_value = value; + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_THAN_QUERY: { + if (value <= _high_value) { + _high_value = value; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_EQUAL_QUERY: { + if (value < _high_value) { + _high_value = value; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + default: { + return Status::InternalError( + "Add value failed! Unsupported InvertedIndexQueryOp {}", op); + } + } + } + + return Status::OK(); + } + Status add_value_str(InvertedIndexQueryOp op, const std::string& value_str, int precision, int scale) { + CppType value; + from_string(value_str, value, precision, scale); + + if (is_match_query(op) || is_equal_query(op)) { + return add_fixed_value(op, value, value_str); + } + if (_high_value > _low_value) { + switch (op) { + case InvertedIndexQueryOp::GREATER_THAN_QUERY: { + if (value >= _low_value) { + _low_value = value; + _low_value_str = value_str; + // NOTE:full_encode_ascending will append encoded data to the end of buffer. + // so we need to clear buffer first. + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::GREATER_EQUAL_QUERY: { + if (value > _low_value) { + _low_value = value; + _low_value_str = value_str; + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_THAN_QUERY: { + if (value <= _high_value) { + _high_value = value; + _high_value_str = value_str; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_EQUAL_QUERY: { + if (value < _high_value) { + _high_value = value; + _high_value_str = value_str; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + default: { + return Status::InternalError( + "Add value string fail! Unsupported InvertedIndexQueryOp {}", op); + } + } + } + + return Status::OK(); + } + Status add_value_str(InvertedIndexQueryOp op, std::string_view value_str, int precision, int scale) { + CppType value; + from_string(value_str, value, precision, scale); + + if (is_match_query(op) || is_equal_query(op)) { + return add_fixed_value(op, value, value_str); Review Comment: warning: no matching member function for call to 'add_fixed_value' [clang-diagnostic-error] ```cpp return add_fixed_value(op, value, value_str); ^ ``` **be/src/olap/rowset/segment_v2/inverted_index_reader.h:174:** candidate function not viable: no known conversion from 'std::string_view' (aka 'basic_string_view<char>') to 'const std::string' (aka 'const basic_string<char>') for 3rd argument ```cpp Status add_fixed_value(InvertedIndexQueryOp op, const CppType& value, ^ ``` **be/src/olap/rowset/segment_v2/inverted_index_reader.h:176:** candidate function not viable: requires 2 arguments, but 3 were provided ```cpp Status add_fixed_value(InvertedIndexQueryOp op, const CppType& value) { ^ ``` ########## be/src/olap/rowset/segment_v2/inverted_index_reader.h: ########## @@ -61,6 +67,520 @@ enum class InvertedIndexQueryType { MATCH_PHRASE_QUERY = 7, }; +inline std::string inverted_index_query_op_to_string(InvertedIndexQueryOp op) { + switch (op) { + case InvertedIndexQueryOp::EQUAL_QUERY: + return "="; + case InvertedIndexQueryOp::LESS_EQUAL_QUERY: + return "<="; + case InvertedIndexQueryOp::LESS_THAN_QUERY: + return "<<"; + case InvertedIndexQueryOp::GREATER_THAN_QUERY: + return ">>"; + case InvertedIndexQueryOp::GREATER_EQUAL_QUERY: + return ">="; + case InvertedIndexQueryOp::MATCH_ANY_QUERY: + return "match_any"; + case InvertedIndexQueryOp::MATCH_ALL_QUERY: + return "match_all"; + case InvertedIndexQueryOp::MATCH_PHRASE_QUERY: + return "match_phrase"; + default: + return ""; + } +} + +inline bool is_match_query(InvertedIndexQueryOp query_op) { + return (query_op == InvertedIndexQueryOp::MATCH_ANY_QUERY || + query_op == InvertedIndexQueryOp::MATCH_ALL_QUERY || + query_op == InvertedIndexQueryOp::MATCH_PHRASE_QUERY); +} + +inline bool is_equal_query(InvertedIndexQueryOp query_op) { + return (query_op == InvertedIndexQueryOp::EQUAL_QUERY); +} + +inline bool is_range_query(InvertedIndexQueryOp query_op) { + return (query_op == InvertedIndexQueryOp::LESS_EQUAL_QUERY || + query_op == InvertedIndexQueryOp::LESS_THAN_QUERY || + query_op == InvertedIndexQueryOp::GREATER_THAN_QUERY || + query_op == InvertedIndexQueryOp::GREATER_EQUAL_QUERY); +} + +template <PrimitiveType Type> +//template <FieldType field_type> +class InvertedIndexQuery { + using CppType = typename PredicatePrimitiveTypeTraits<Type>::PredicateFieldType; + +public: + /*class QueryEncodedValue { + public: + QueryEncodedValue() = default; + QueryEncodedValue(const uint8_t* encoded_value) : _encoded_value(encoded_value) {} + QueryEncodedValue Operator = (const std::string& encoded_value) { + _encoded_value = (const uint8_t*)encoded_value.c_str(); + } + ~QueryEncodedValue() = default; + + const uint8_t* encoded_value() const { return _encoded_value; } + + bool operator<(const QueryEncodedValue& value) const { return cmp(value) < 0; } + + bool operator<=(const QueryEncodedValue& value) const { return cmp(value) <= 0; } + + bool operator>(const QueryEncodedValue& value) const { return cmp(value) > 0; } + + bool operator>=(const QueryEncodedValue& value) const { return cmp(value) >= 0; } + + bool operator==(const QueryEncodedValue& value) const { return cmp(value) == 0; } + + bool operator!=(const QueryEncodedValue& value) const { return cmp(value) != 0; } + + int32_t cmp(const QueryEncodedValue& other) const { + return lucene::util::FutureArrays::CompareUnsigned( + (const uint8_t*)encoded_value().c_str(), 0, 0 + sizeof(CppType), + (const uint8_t*)other.encoded_value().c_str(), 0, 0 + sizeof(CppType)); + } + + private: + const uint8_t* _encoded_value; + };*/ + + InvertedIndexQuery(const TypeInfo* type_info) + : _low_value(TYPE_MIN), + _high_value(TYPE_MAX), + _low_op(InvertedIndexQueryOp::GREATER_THAN_QUERY), + _high_op(InvertedIndexQueryOp::LESS_THAN_QUERY), + _type_info(type_info) { + //FieldTypeTraits<field_type>::set_to_max(&_high_value); + //FieldTypeTraits<field_type>::set_to_min(&_low_value); + _value_key_coder = get_key_coder(_type_info->type()); + _value_key_coder->full_encode_ascending(&TYPE_MAX, &_high_value_encoded); + _value_key_coder->full_encode_ascending(&TYPE_MIN, &_low_value_encoded); + } + + // if op is match, we just need to add match_value to fixed_values_str, no need to add to fixed_values. + // because fulltext match only uses fixed_values_str. + Status add_match_value(InvertedIndexQueryOp op, const std::string& match_value) { + DCHECK(op == InvertedIndexQueryOp::MATCH_ANY_QUERY || + op == InvertedIndexQueryOp::MATCH_ALL_QUERY || + op == InvertedIndexQueryOp::MATCH_PHRASE_QUERY); + _fixed_values_str.insert(match_value); + _high_op = _low_op = op; + _high_value = TYPE_MIN; + _low_value = TYPE_MAX; + return Status::OK(); + } + + Status add_fixed_value(InvertedIndexQueryOp op, const CppType& value, + const std::string& value_str); + Status add_fixed_value(InvertedIndexQueryOp op, const CppType& value) { + _fixed_values.insert(value); + std::string tmp; + _value_key_coder->full_encode_ascending(&value, &tmp); + _fixed_values_encoded.insert(tmp); + + _high_value = value; + _low_value = value; + _high_op = op; + _low_op = op; + + return Status::OK(); + } + + Status from_string(const std::string& str_value, CppType& value, int precision, int scale); + Status add_value(InvertedIndexQueryOp op, const CppType& value) { + if (is_match_query(op) || is_equal_query(op)) { + return add_fixed_value(op, value); + } + if (_high_value > _low_value) { + switch (op) { + case InvertedIndexQueryOp::GREATER_THAN_QUERY: { + if (value >= _low_value) { + _low_value = value; + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::GREATER_EQUAL_QUERY: { + if (value > _low_value) { + _low_value = value; + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_THAN_QUERY: { + if (value <= _high_value) { + _high_value = value; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_EQUAL_QUERY: { + if (value < _high_value) { + _high_value = value; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + default: { + return Status::InternalError( + "Add value failed! Unsupported InvertedIndexQueryOp {}", op); + } + } + } + + return Status::OK(); + } + Status add_value_str(InvertedIndexQueryOp op, const std::string& value_str, int precision, int scale) { + CppType value; + from_string(value_str, value, precision, scale); + + if (is_match_query(op) || is_equal_query(op)) { + return add_fixed_value(op, value, value_str); + } + if (_high_value > _low_value) { + switch (op) { + case InvertedIndexQueryOp::GREATER_THAN_QUERY: { + if (value >= _low_value) { + _low_value = value; + _low_value_str = value_str; + // NOTE:full_encode_ascending will append encoded data to the end of buffer. + // so we need to clear buffer first. + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::GREATER_EQUAL_QUERY: { + if (value > _low_value) { + _low_value = value; + _low_value_str = value_str; + _low_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_low_value_encoded); + _low_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_THAN_QUERY: { + if (value <= _high_value) { + _high_value = value; + _high_value_str = value_str; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + case InvertedIndexQueryOp::LESS_EQUAL_QUERY: { + if (value < _high_value) { + _high_value = value; + _high_value_str = value_str; + _high_value_encoded.clear(); + _value_key_coder->full_encode_ascending(&value, &_high_value_encoded); + _high_op = op; + } + break; + } + + default: { + return Status::InternalError( + "Add value string fail! Unsupported InvertedIndexQueryOp {}", op); + } + } + } + + return Status::OK(); + } + Status add_value_str(InvertedIndexQueryOp op, std::string_view value_str, int precision, int scale) { + CppType value; + from_string(value_str, value, precision, scale); Review Comment: warning: no viable conversion from 'std::string_view' (aka 'basic_string_view<char>') to 'const std::string' (aka 'const basic_string<char>') [clang-diagnostic-error] ```cpp from_string(value_str, value, precision, scale); ^ ``` **be/src/olap/in_list_predicate.h:217:** in instantiation of member function 'doris::segment_v2::InvertedIndexQuery<doris::TYPE_CHAR>::add_value_str' requested here ```cpp RETURN_IF_ERROR(query.add_value_str(InvertedIndexQueryOp::EQUAL_QUERY, value_str, ^ ``` **be/src/olap/in_list_predicate.h:82:** in instantiation of member function 'doris::InListPredicateBase<doris::TYPE_CHAR, doris::PredicateType::IN_LIST>::evaluate' requested here ```cpp InListPredicateBase(uint32_t column_id, const ConditionType& conditions, ^ ``` **be/src/olap/predicate_creator.h:107:** in instantiation of function template specialization 'doris::InListPredicateBase<doris::TYPE_CHAR, doris::PredicateType::IN_LIST>::InListPredicateBase<std::vector<std::basic_string<char>>, doris::StringRef (const doris::TabletColumn &, const std::basic_string<char> &, doris::MemPool *)>' requested here ```cpp return new InListPredicateBase<Type, PT>(index, conditions, convert, opposite, &column, ^ ``` **/usr/include/c++/11/bits/unique_ptr.h:961:** in instantiation of member function 'doris::StringPredicateCreator<doris::TYPE_CHAR, doris::PredicateType::IN_LIST, std::vector<std::basic_string<char>>>::create' requested here ```cpp { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } ^ ``` **be/src/olap/predicate_creator.h:195:** in instantiation of function template specialization 'std::make_unique<doris::StringPredicateCreator<doris::TYPE_CHAR, doris::PredicateType::IN_LIST, std::vector<std::basic_string<char>>>>' requested here ```cpp return std::make_unique<StringPredicateCreator<TYPE_CHAR, PT, ConditionType>>(); ^ ``` **be/src/olap/predicate_creator.h:242:** in instantiation of function template specialization 'doris::get_creator<doris::PredicateType::IN_LIST, std::vector<std::basic_string<char>>>' requested here ```cpp return get_creator<PT, ConditionType>(column.type()) ^ ``` **be/src/olap/predicate_creator.h:259:** in instantiation of function template specialization 'doris::create_predicate<doris::PredicateType::IN_LIST, std::vector<std::basic_string<char>>>' requested here ```cpp return create_predicate<PT, std::vector<std::string>>(column, index, conditions, opposite, ^ ``` **be/src/olap/predicate_creator.h:287:** in instantiation of function template specialization 'doris::create_list_predicate<doris::PredicateType::IN_LIST>' requested here ```cpp create = create_list_predicate<PredicateType::IN_LIST>; ^ ``` **/usr/include/c++/11/bits/basic_string.h:455:** candidate constructor not viable: no known conversion from 'std::string_view' (aka 'basic_string_view<char>') to 'const std::basic_string<char> &' for 1st argument ```cpp basic_string(const basic_string& __str) ^ ``` **/usr/include/c++/11/bits/basic_string.h:532:** candidate constructor template not viable: no known conversion from 'std::string_view' (aka 'basic_string_view<char>') to 'const char *' for 1st argument ```cpp basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) ^ ``` **/usr/include/c++/11/bits/basic_string.h:564:** candidate constructor not viable: no known conversion from 'std::string_view' (aka 'basic_string_view<char>') to 'std::basic_string<char> &&' for 1st argument ```cpp basic_string(basic_string&& __str) noexcept ^ ``` **/usr/include/c++/11/bits/basic_string.h:591:** candidate constructor not viable: no known conversion from 'std::string_view' (aka 'basic_string_view<char>') to 'initializer_list<char>' for 1st argument ```cpp basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) ^ ``` **/usr/include/c++/11/bits/basic_string.h:447:** explicit constructor is not a candidate ```cpp basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT ^ ``` **/usr/include/c++/11/bits/basic_string.h:663:** explicit constructor is not a candidate ```cpp basic_string(const _Tp& __t, const _Alloc& __a = _Alloc()) ^ ``` **be/src/olap/rowset/segment_v2/inverted_index_reader.h:190:** passing argument to parameter 'str_value' here ```cpp Status from_string(const std::string& str_value, CppType& value, int precision, int scale); ^ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org