Gabriel39 commented on code in PR #10103:
URL: https://github.com/apache/incubator-doris/pull/10103#discussion_r897468507


##########
be/src/vec/exprs/vexpr.cpp:
##########
@@ -88,8 +98,8 @@ void VExpr::close(doris::RuntimeState* state, VExprContext* 
context,
     }
 }
 
-Status VExpr::create_expr(doris::ObjectPool* pool, const doris::TExprNode& 
texpr_node,
-                          VExpr** expr) {
+Status VExpr::create_expr(doris::ObjectPool* pool, const doris::TExprNode& 
texpr_node, VExpr** expr,

Review Comment:
   Use a new method `create_rf_expr` instead



##########
be/src/exec/olap_scan_node.cpp:
##########
@@ -91,6 +92,8 @@ Status OlapScanNode::init(const TPlanNode& tnode, 
RuntimeState* state) {
                                                                         
&runtime_filter));
 
         _runtime_filter_ctxs[i].runtimefilter = runtime_filter;
+        _runtime_filter_ready_flag[i] = false;
+        _rf_locks.push_back(new std::mutex());

Review Comment:
   I change it to unique pointer and I think this way is better



##########
be/src/vec/exprs/vruntimefilter_wrapper.cpp:
##########
@@ -0,0 +1,108 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "vec/exprs/vruntimefilter_wrapper.h"
+
+#include <string_view>
+
+#include "exprs/create_predicate_function.h"
+#include "util/simd/bits.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/columns/column_set.h"
+#include "vec/core/field.h"
+#include "vec/data_types/data_type_factory.hpp"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+
+VRuntimeFilterWrapper::VRuntimeFilterWrapper(const TExprNode& node, VExpr* 
impl)
+        : VExpr(node), _impl(impl), _always_true(false), _filtered_rows(0), 
_scan_rows(0) {}
+
+VRuntimeFilterWrapper::VRuntimeFilterWrapper(const VRuntimeFilterWrapper& 
vexpr)
+        : VExpr(vexpr),
+          _impl(vexpr._impl),
+          _always_true(vexpr._always_true),
+          _filtered_rows(vexpr._filtered_rows.load()),
+          _scan_rows(vexpr._scan_rows.load()) {}
+
+Status VRuntimeFilterWrapper::prepare(RuntimeState* state, const 
RowDescriptor& desc,
+                                      VExprContext* context) {
+    return _impl->prepare(state, desc, context);
+}
+
+Status VRuntimeFilterWrapper::open(RuntimeState* state, VExprContext* context,
+                                   FunctionContext::FunctionStateScope scope) {
+    return _impl->open(state, context, scope);
+}
+
+void VRuntimeFilterWrapper::close(RuntimeState* state, VExprContext* context,
+                                  FunctionContext::FunctionStateScope scope) {
+    _impl->close(state, context, scope);
+}
+
+bool VRuntimeFilterWrapper::is_constant() const {
+    return _impl->is_constant();
+}
+
+Status VRuntimeFilterWrapper::execute(VExprContext* context, Block* block, 
int* result_column_id) {
+    if (_always_true) {
+        auto res_data_column = ColumnVector<UInt8>::create(block->rows());
+        size_t num_columns_without_result = block->columns();
+        size_t sz = block->rows();
+        res_data_column->resize(sz);
+        res_data_column->reserve(sz);
+        auto ptr = 
((ColumnVector<UInt8>*)res_data_column.get())->get_data().data();
+        for (size_t i = 0; i < sz; i++) {
+            ptr[i] = 1;
+        }
+        if (_data_type->is_nullable()) {
+            auto null_map = ColumnVector<UInt8>::create(block->rows(), 0);
+            block->insert({ColumnNullable::create(std::move(res_data_column), 
std::move(null_map)),
+                           _data_type, expr_name()});
+        } else {
+            block->insert({std::move(res_data_column), _data_type, 
expr_name()});
+        }
+        *result_column_id = num_columns_without_result;
+        return Status::OK();
+    } else {
+        _scan_rows += block->rows();
+        auto status = _impl->execute(context, block, result_column_id);
+        auto* data =
+                
((ColumnVector<UInt8>*)block->get_columns_with_type_and_name()[*result_column_id]
+                         .column.get())
+                        ->get_data()
+                        .data();
+        _filtered_rows +=
+                doris::simd::count_zero_num(reinterpret_cast<const 
int8_t*>(data), block->rows());
+
+        if ((!_has_calculate_filter) && (_scan_rows > 0) && (_scan_rows.load() 
>= _loop_size)) {
+            double rate = (double)_filtered_rows / _scan_rows;
+            if (rate < _expect_filter_rate) {
+                _always_true = true;
+            }
+            _has_calculate_filter = true;

Review Comment:
   > why we need `_has_calculate_filter`? seems `_scan_rows > 0` is e
   
   I just want to use the origin logics in `exprs/bloomfilter_predicate.cpp` 
here. I think using `_has_calculate_filter` will ensure we only calculate 
filter rate once when scan rows count is large than `_loop_size`



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

Reply via email to