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


##########
be/src/vec/exprs/vruntimefilter_wrapper.h:
##########
@@ -0,0 +1,63 @@
+// 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.
+
+#pragma once
+
+#include "vec/exprs/vexpr.h"
+
+namespace doris::vectorized {
+class VRuntimeFilterWrapper final : public VExpr {
+public:
+    VRuntimeFilterWrapper(const TExprNode& node, VExpr* impl);
+    VRuntimeFilterWrapper(const VRuntimeFilterWrapper& vexpr);
+    ~VRuntimeFilterWrapper() = default;
+    doris::Status execute(VExprContext* context, doris::vectorized::Block* 
block,
+                          int* result_column_id) override;
+    doris::Status prepare(doris::RuntimeState* state, const 
doris::RowDescriptor& desc,
+                          VExprContext* context) override;
+    doris::Status open(doris::RuntimeState* state, VExprContext* context,
+                       FunctionContext::FunctionStateScope scope) override;
+    std::string debug_string() const override { return _impl->debug_string(); 
};
+    bool is_constant() const override;
+    void close(doris::RuntimeState* state, VExprContext* context,
+               FunctionContext::FunctionStateScope scope) override;
+    VExpr* clone(doris::ObjectPool* pool) const override {
+        return pool->add(new VRuntimeFilterWrapper(*this));
+    }
+    const std::string& expr_name() const override;
+
+    ColumnPtrWrapper* get_const_col(VExprContext* context) override {
+        return _impl->get_const_col(context);
+    }
+
+private:
+    VExpr* _impl;
+
+    bool _always_true;
+    /// TODO: statistic filter rate in the profile
+    std::atomic<int64_t> _filtered_rows;
+    std::atomic<int64_t> _scan_rows;
+
+    bool _has_calculate_filter = false;
+    // loop size must be power of 2
+    constexpr static int64_t _threshold_to_calculate_rate = 8192;

Review Comment:
   contexpr use `UPPER CASE` no need `_` in value



##########
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()) {

Review Comment:
   yes, no need change the `uint8`



##########
be/src/vec/exprs/vruntimefilter_wrapper.cpp:
##########
@@ -0,0 +1,107 @@
+// 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 "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/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_IF_ERROR(_impl->prepare(state, desc, context));
+    _expr_name = fmt::format("VRuntimeFilterWrapper({})", _impl->expr_name());
+    return Status::OK();
+}
+
+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());

Review Comment:
   `auto res_data_column = ColumnVector<UInt8>::create(block->rows(), 1);`



##########
be/src/util/simd/bits.h:
##########
@@ -57,5 +57,35 @@ inline uint32_t bytes32_mask_to_bits32_mask(const bool* 
data) {
     return bytes32_mask_to_bits32_mask(reinterpret_cast<const uint8_t*>(data));
 }
 
+inline size_t count_zero_num(const int8_t* data, size_t size) {
+    size_t num = 0;
+    const int8_t* end = data + size;
+
+#if defined(__SSE2__) && defined(__POPCNT__)

Review Comment:
   delete the code



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