csun5285 commented on code in PR #62960:
URL: https://github.com/apache/doris/pull/62960#discussion_r3214338664
##########
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:
这个 encoding 不需要考虑 scale,因为是把里面的 int64 或者 int128 来进行encoding,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: [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]