forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvruntimefilter_wrapper.cpp
More file actions
129 lines (108 loc) · 4.25 KB
/
Copy pathvruntimefilter_wrapper.cpp
File metadata and controls
129 lines (108 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// 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 <fmt/format.h>
#include <cstddef>
#include "util/runtime_profile.h"
#include "vec/columns/column.h"
#include "vec/columns/column_const.h"
#include "vec/core/block.h"
#include "vec/core/column_numbers.h"
#include "vec/core/column_with_type_and_name.h"
#include "vec/core/types.h"
#include "vec/data_types/data_type.h"
#include "vec/utils/util.hpp"
namespace doris {
#include "common/compile_check_begin.h"
class RowDescriptor;
class RuntimeState;
class TExprNode;
double get_in_list_ignore_thredhold(size_t list_size) {
return std::log2(list_size + 1) / 64;
}
double get_comparison_ignore_thredhold() {
return 0.1;
}
double get_bloom_filter_ignore_thredhold() {
return 0.4;
}
} // namespace doris
namespace doris::vectorized {
class VExprContext;
VRuntimeFilterWrapper::VRuntimeFilterWrapper(const TExprNode& node, VExprSPtr impl,
double ignore_thredhold, bool null_aware,
int filter_id)
: VExpr(node),
_impl(std::move(impl)),
_ignore_thredhold(ignore_thredhold),
_null_aware(null_aware),
_filter_id(filter_id) {
reset_judge_selectivity();
}
Status VRuntimeFilterWrapper::prepare(RuntimeState* state, const RowDescriptor& desc,
VExprContext* context) {
RETURN_IF_ERROR_OR_PREPARED(_impl->prepare(state, desc, context));
_expr_name = fmt::format("VRuntimeFilterWrapper({})", _impl->expr_name());
_prepare_finished = true;
return Status::OK();
}
Status VRuntimeFilterWrapper::open(RuntimeState* state, VExprContext* context,
FunctionContext::FunctionStateScope scope) {
DCHECK(_prepare_finished);
RETURN_IF_ERROR(_impl->open(state, context, scope));
_open_finished = true;
return Status::OK();
}
void VRuntimeFilterWrapper::close(VExprContext* context,
FunctionContext::FunctionStateScope scope) {
_impl->close(context, scope);
}
Status VRuntimeFilterWrapper::execute(VExprContext* context, Block* block, int* result_column_id) {
DCHECK(_open_finished || _getting_const_col);
if (_judge_counter.fetch_sub(1) == 0) {
reset_judge_selectivity();
}
if (_always_true) {
size_t size = block->rows();
block->insert({create_always_true_column(size, _data_type->is_nullable()), _data_type,
expr_name()});
*result_column_id = block->columns() - 1;
COUNTER_UPDATE(_always_true_filter_rows, size);
return Status::OK();
} else {
if (_getting_const_col) {
_impl->set_getting_const_col(true);
}
ColumnNumbers args;
RETURN_IF_ERROR(_impl->execute_runtime_fitler(context, block, result_column_id, args));
if (_getting_const_col) {
_impl->set_getting_const_col(false);
}
ColumnWithTypeAndName& result_column = block->get_by_position(*result_column_id);
// bloom filter will handle null aware inside itself
if (_null_aware && TExprNodeType::BLOOM_PRED != node_type()) {
DCHECK_GE(args.size(), 1);
change_null_to_true(result_column.column, block->get_by_position(args[0]).column);
}
return Status::OK();
}
}
const std::string& VRuntimeFilterWrapper::expr_name() const {
return _expr_name;
}
#include "common/compile_check_end.h"
} // namespace doris::vectorized