xiaokang commented on code in PR #38908:
URL: https://github.com/apache/doris/pull/38908#discussion_r1738540582


##########
be/src/olap/rowset/segment_v2/segment_iterator.cpp:
##########
@@ -2103,15 +1716,16 @@ Status SegmentIterator::_read_columns_by_index(uint32_t 
nrows_read_limit, uint32
         }
 
         DBUG_EXECUTE_IF("segment_iterator._read_columns_by_index", {
+            auto col_name = _opts.tablet_schema->column(cid).name();
             auto debug_col_name = 
DebugPoints::instance()->get_debug_param_or_default<std::string>(
                     "segment_iterator._read_columns_by_index", "column_name", 
"");
-            if (debug_col_name.empty()) {
-                return Status::Error<ErrorCode::INTERNAL_ERROR>("does not need 
to read data");
+            if (debug_col_name.empty() && col_name != "__DORIS_DELETE_SIGN__") 
{

Review Comment:
   use a const



##########
be/src/vec/functions/functions_comparison.h:
##########
@@ -526,6 +528,72 @@ class FunctionComparison : public IFunction {
         return std::make_shared<DataTypeUInt8>();
     }
 
+    Status evaluate_inverted_index(
+            const ColumnsWithTypeAndName& arguments,
+            const std::vector<vectorized::IndexFieldNameAndTypePair>& 
data_type_with_names,
+            std::vector<segment_v2::InvertedIndexIterator*> iterators, 
uint32_t num_rows,
+            segment_v2::InvertedIndexResultBitmap& bitmap_result) const 
override {
+        DCHECK(arguments.size() == 1);
+        DCHECK(data_type_with_names.size() == 1);
+        DCHECK(iterators.size() == 1);
+        auto* iter = iterators[0];
+        auto data_type_with_name = data_type_with_names[0];
+        if (iter == nullptr) {
+            return Status::OK();
+        }
+        if (iter->get_inverted_index_reader_type() ==
+            segment_v2::InvertedIndexReaderType::FULLTEXT) {
+            //NOT support comparison predicate when parser is FULLTEXT for 
expr inverted index evaluate.
+            return Status::OK();
+        }
+        std::string column_name = data_type_with_name.first;
+        Field param_value;
+        arguments[0].column->get(0, param_value);
+        auto param_type = 
arguments[0].type->get_type_as_type_descriptor().type;
+
+        std::unique_ptr<segment_v2::InvertedIndexQueryParamFactory> 
query_param = nullptr;
+        
RETURN_IF_ERROR(segment_v2::InvertedIndexQueryParamFactory::create_query_value(
+                param_type, &param_value, query_param));
+        segment_v2::InvertedIndexQueryType query_type;
+        std::string_view name_view(name);
+        if (name_view == NameEquals::name || name_view == NameNotEquals::name) 
{
+            query_type = segment_v2::InvertedIndexQueryType::EQUAL_QUERY;
+        } else if (name_view == NameLess::name) {
+            query_type = segment_v2::InvertedIndexQueryType::LESS_THAN_QUERY;
+        } else if (name_view == NameLessOrEquals::name) {
+            query_type = segment_v2::InvertedIndexQueryType::LESS_EQUAL_QUERY;
+        } else if (name_view == NameGreater::name) {
+            query_type = 
segment_v2::InvertedIndexQueryType::GREATER_THAN_QUERY;
+        } else if (name_view == NameGreaterOrEquals::name) {
+            query_type = 
segment_v2::InvertedIndexQueryType::GREATER_EQUAL_QUERY;
+        } else {
+            return Status::InvalidArgument("invalid comparison op type {}", 
Name::name);
+        }
+
+        std::shared_ptr<roaring::Roaring> roaring = 
std::make_shared<roaring::Roaring>();
+        
RETURN_IF_ERROR(segment_v2::InvertedIndexQueryParamFactory::create_query_value(
+                param_type, &param_value, query_param));
+        RETURN_IF_ERROR(iter->read_from_inverted_index(column_name, 
query_param->get_value(),
+                                                       query_type, num_rows, 
roaring));
+        std::shared_ptr<roaring::Roaring> null_bitmap = 
std::make_shared<roaring::Roaring>();
+        if (iter->has_null()) {
+            segment_v2::InvertedIndexQueryCacheHandle null_bitmap_cache_handle;
+            RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle));
+            null_bitmap = null_bitmap_cache_handle.get_bitmap();
+        }
+        segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
+        bitmap_result = result;
+        bitmap_result.mask_out_null();
+
+        if (name == "ne") {

Review Comment:
   NameNotEquals::name



##########
be/src/vec/exprs/vcast_expr.cpp:
##########
@@ -32,6 +32,7 @@
 #include "vec/core/columns_with_type_and_name.h"
 #include "vec/exprs/vexpr.h"
 #include "vec/exprs/vexpr_context.h"
+#include "vec/exprs/vslot_ref.h"

Review Comment:
   useless



##########
be/src/vec/exprs/vectorized_fn_call.cpp:
##########
@@ -143,38 +138,38 @@ void VectorizedFnCall::close(VExprContext* context, 
FunctionContext::FunctionSta
     VExpr::close(context, scope);
 }
 
-Status VectorizedFnCall::eval_inverted_index(
-        VExprContext* context,
-        const std::unordered_map<ColumnId, 
std::pair<vectorized::IndexFieldNameAndTypePair,
-                                                     
segment_v2::InvertedIndexIterator*>>&
-                colid_to_inverted_index_iter,
-        uint32_t num_rows, roaring::Roaring* bitmap) const {
+Status VectorizedFnCall::evaluate_inverted_index(VExprContext* context, 
uint32_t segment_num_rows) {
     DCHECK_GE(get_num_children(), 1);
-    if (get_child(0)->is_slot_ref()) {
-        auto* column_slot_ref = assert_cast<VSlotRef*>(get_child(0).get());
-        if (auto iter = 
colid_to_inverted_index_iter.find(column_slot_ref->column_id());
-            iter != colid_to_inverted_index_iter.end()) {
-            const auto& pair = iter->second;
-            return 
_function->eval_inverted_index(context->fn_context(_fn_context_index),
-                                                  pair.first, pair.second, 
num_rows, bitmap);
-        } else {
-            return Status::NotSupported("column id {} not found in 
colid_to_inverted_index_iter",
-                                        column_slot_ref->column_id());
-        }
-    } else {
-        return Status::NotSupported("we can only eval inverted index for slot 
ref expr, but got ",
-                                    get_child(0)->expr_name());
-    }
-    return Status::OK();
+    return _evaluate_inverted_index(context, _function, segment_num_rows);
 }
 
 Status VectorizedFnCall::_do_execute(doris::vectorized::VExprContext* context,
                                      doris::vectorized::Block* block, int* 
result_column_id,
                                      std::vector<size_t>& args) {
-    if (is_const_and_have_executed()) { // const have execute in open function
+    if (is_const_and_have_executed()) { // const have executed in open function
         return get_result_from_const(block, _expr_name, result_column_id);
     }
+    if (_can_fast_execute && fast_execute(context, block, result_column_id)) {

Review Comment:
   check _can_fast_execute in fast_execute()



##########
be/src/vec/exprs/vexpr.cpp:
##########
@@ -611,80 +610,115 @@ Status VExpr::get_result_from_const(vectorized::Block* 
block, const std::string&
     return Status::OK();
 }
 
-bool VExpr::fast_execute(Block& block, const ColumnNumbers& arguments, size_t 
result,
-                         size_t input_rows_count, const std::string& 
function_name) {
-    if (!_enable_inverted_index_query) {
-        return false;
+Status VExpr::_evaluate_inverted_index(VExprContext* context, const 
FunctionBasePtr& function,
+                                       uint32_t segment_num_rows) {
+    std::vector<segment_v2::InvertedIndexIterator*> iterators;
+    std::vector<vectorized::IndexFieldNameAndTypePair> data_type_with_names;
+    std::vector<int> column_ids;
+    vectorized::ColumnsWithTypeAndName arguments;
+    VExprSPtrs children_exprs;
+    for (auto child : children()) {
+        if (child->node_type() == TExprNodeType::CAST_EXPR) {
+            auto* cast_expr = assert_cast<VCastExpr*>(child.get());
+            DCHECK_EQ(cast_expr->children().size(), 1);
+            if (cast_expr->get_child(0)->is_slot_ref()) {
+                auto* column_slot_ref = 
assert_cast<VSlotRef*>(cast_expr->get_child(0).get());
+                auto column_id = column_slot_ref->column_id();
+                const auto* storage_name_type =
+                        context->get_inverted_index_context()
+                                
->get_storage_name_and_type_by_column_id(column_id);
+                auto origin_primitive_type =
+                        
storage_name_type->second->get_type_as_type_descriptor().type;
+                auto target_primitive_type =
+                        
cast_expr->get_target_type()->get_type_as_type_descriptor().type;
+                if (origin_primitive_type != TYPE_VARIANT &&
+                    (origin_primitive_type == target_primitive_type ||
+                     (is_string_type(target_primitive_type) &&
+                      is_string_type(origin_primitive_type)))) {
+                    children_exprs.emplace_back(expr_without_cast(child));

Review Comment:
   add comment



-- 
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