yiguolei commented on code in PR #62960:
URL: https://github.com/apache/doris/pull/62960#discussion_r3214275730


##########
be/src/storage/index/inverted/inverted_index_reader.cpp:
##########
@@ -58,6 +61,85 @@
 #include "storage/types.h"
 #include "util/faststring.h"
 
+namespace {
+
+template <doris::FieldType FT>
+static void bkd_encode_min(const doris::KeyCoder* coder, std::string* out) {
+    using key_t = typename doris::CppTypeTraits<FT>::CppType;
+    key_t v = doris::type_limit<key_t>::min();
+    coder->full_encode_ascending(&v, out);
+}
+
+template <doris::FieldType FT>
+static void bkd_encode_max(const doris::KeyCoder* coder, std::string* out) {
+    using key_t = typename doris::CppTypeTraits<FT>::CppType;
+    key_t v = doris::type_limit<key_t>::max();
+    coder->full_encode_ascending(&v, out);
+}
+
+static doris::Status encode_bkd_field_ascending(doris::FieldType ft, const 
doris::Field& field,
+                                                const doris::KeyCoder* coder, 
std::string* out) {
+    // `actual` is the primitive type of the query Field from the caller; 
`PrimitiveType::PT` is the
+    // scalar type the BKD index stores (e.g. INT for an INT column or 
ARRAY<INT> index).
+    // Normally they match: `int_col = 1` -> both INT; 
`array_contains(int_arr, 2)` -> both INT.
+    // Mismatch happens when the query Field carries a non-scalar while BKD 
records the inner scalar:
+    // `arr = []` reaches here via `FunctionComparison<EqualsOp>` with the 
entire const ARRAY literal
+    // as the query Field, so `actual = TYPE_ARRAY` while PT is the inner 
scalar -- the predicate
+    // cannot be answered by BKD. Return INVERTED_INDEX_EVALUATE_SKIPPED so 
`_apply_index_expr`
+    // downgrades to scalar evaluation instead of crashing on 
`Field::get<PT>()` DCHECK below.
+#define CASE(FT, PT)                                                           
                    \
+    case doris::FieldType::FT: {                                               
                    \
+        const auto actual = field.get_type();                                  
                    \
+        if (actual != doris::PrimitiveType::PT && actual != 
doris::PrimitiveType::TYPE_NULL &&     \
+            !(doris::is_string_type(actual) && 
doris::is_string_type(doris::PrimitiveType::PT))) { \
+            return 
doris::Status::Error<doris::ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED, false>( 
\
+                    "BKD query value type {} does not match index type {}",    
                    \
+                    static_cast<int>(actual), static_cast<int>(ft));           
                    \
+        }                                                                      
                    \
+        doris::full_encode_field_as_key<doris::PrimitiveType::PT>(field, 
coder, out);              \
+        return doris::Status::OK();                                            
                    \
+    }
+    switch (ft) {
+        DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES(CASE)
+    default:
+        break;
+    }
+#undef CASE
+    return doris::Status::InternalError("unsupported BKD field type {}", 
static_cast<int>(ft));
+}
+
+static doris::Status encode_bkd_min_ascending(doris::FieldType ft, const 
doris::KeyCoder* coder,
+                                              std::string* out) {
+#define CASE(FT, PT)                                      \
+    case doris::FieldType::FT:                            \
+        bkd_encode_min<doris::FieldType::FT>(coder, out); \
+        return doris::Status::OK();
+    switch (ft) {
+        DORIS_APPLY_FOR_KEY_ENCODABLE_NON_STRING_TYPES(CASE)
+    default:
+        break;
+    }
+#undef CASE
+    return doris::Status::InternalError("unsupported BKD field type {}", 
static_cast<int>(ft));
+}
+
+static doris::Status encode_bkd_max_ascending(doris::FieldType ft, const 
doris::KeyCoder* coder,

Review Comment:
   对于decimal 和 datetime 这种类型,他是有scale的,此时我们min和max 怎么体现呢?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to