forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_batch_eval_util.cpp
More file actions
195 lines (183 loc) · 7.46 KB
/
Copy pathob_batch_eval_util.cpp
File metadata and controls
195 lines (183 loc) · 7.46 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed 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.
*/
#define USING_LOG_PREFIX SQL
#include "ob_batch_eval_util.h"
namespace oceanbase
{
namespace sql
{
int binary_operand_batch_eval(const ObExpr &expr,
ObEvalCtx &ctx,
const ObBitVector &skip,
const int64_t size,
const bool null_short_circuit)
{
int ret = 0;
const ObExpr &left = *expr.args_[0];
const ObExpr &right = *expr.args_[1];
if (null_short_circuit) {
if (OB_FAIL(left.eval_batch(ctx, skip, size))) {
LOG_WARN("batch evaluate failed", K(ret), K(expr));
} else if (left.is_batch_result()) {
const ObBitVector *rskip = &skip;
if (!left.get_eval_info(ctx).notnull_) {
ObBitVector &my_skip = expr.get_pvt_skip(ctx);
rskip = &my_skip;
my_skip.deep_copy(skip, size);
const ObDatum *ldatums = left.locate_batch_datums(ctx);
for (int64_t i = 0; i < size; i++) {
if (!my_skip.at(i) && ldatums[i].is_null()) {
my_skip.set(i);
}
}
}
if (OB_FAIL(ret)) {
} else if (rskip->is_all_true(size)) {
// If rskip is all true, the right expr does not need to be evaluated.
} else if (OB_FAIL(right.eval_batch(ctx, *rskip, size))) {
LOG_WARN("batch evaluated failed", K(ret), K(right));
}
} else {
if (!left.locate_expr_datum(ctx).is_null()) {
if (OB_FAIL(right.eval_batch(ctx, skip, size))) {
LOG_WARN("batch evaluate failed", K(ret), K(right));
}
}
}
} else {
if (OB_FAIL(left.eval_batch(ctx, skip, size))
|| OB_FAIL(right.eval_batch(ctx, skip, size))) {
LOG_WARN("batch evaluate failed", K(ret), K(expr));
}
}
return ret;
}
int binary_operand_vector_eval(const ObExpr &expr,
ObEvalCtx &ctx,
const ObBitVector &skip,
EvalBound &bound,
const bool null_short_circuit,
bool &right_evaluated)
{
int ret = 0;
right_evaluated = true;
const ObExpr &left = *expr.args_[0];
const ObExpr &right = *expr.args_[1];
const ObBitVector *rskip = &skip;
if (null_short_circuit) {
if (OB_FAIL(left.eval_vector(ctx, skip, bound))) {
LOG_WARN("batch evaluate failed", K(ret), K(expr));
} else if (left.get_format(ctx) != VEC_UNIFORM_CONST) {
if (OB_LIKELY(!left.get_vector(ctx)->has_null())) {
if (OB_FAIL(right.eval_vector(ctx, *rskip, bound))) {
LOG_WARN("batch evaluated failed", K(ret), K(right));
}
} else {
ObBitVector &my_skip = expr.get_pvt_skip(ctx);
rskip = &my_skip;
if (OB_LIKELY(bound.get_all_rows_active())) {
if (OB_LIKELY(left.get_format(ctx) != VEC_UNIFORM)) {
my_skip.deep_copy(
*static_cast<ObBitmapNullVectorBase *>(left.get_vector(ctx))->get_nulls(),
bound.start(), bound.end());
} else {
my_skip.reset(bound.batch_size());
ObUniformBase *left_vec = static_cast<ObUniformBase *>(left.get_vector(ctx));
for (int i = bound.start(); i < bound.end(); i++) {
if (left_vec->is_null(i)) { my_skip.set(i); }
}
}
} else if (OB_LIKELY(left.get_format(ctx) != VEC_UNIFORM)) {
const ObBitVector *nulls_map = static_cast<ObBitmapNullVectorBase *>(left.get_vector(ctx))->get_nulls();
my_skip.deep_copy(skip, bound.start(), bound.end());
my_skip.bit_or(*nulls_map, bound.start(), bound.end());
} else {
my_skip.deep_copy(skip, bound.start(), bound.end());
ObUniformBase *left_vec = static_cast<ObUniformBase *>(left.get_vector(ctx));
for (int i = bound.start(); i < bound.end(); i++) {
if (left_vec->is_null(i)) { my_skip.set(i);}
}
}
bound.set_all_row_active(false);
}
if (OB_FAIL(ret)) {
} else if (rskip->is_all_true(bound.start(), bound.end())) {
right_evaluated = false;
// If rskip is all true, the right expr does not need to be evaluated.
} else if (OB_FAIL(right.eval_vector(ctx, *rskip, bound))) {
LOG_WARN("batch evaluated failed", K(ret), K(right));
}
} else {
if (!static_cast<ObVectorBase *>(left.get_vector(ctx))->is_null(0)) {
if (OB_FAIL(right.eval_vector(ctx, skip, bound))) {
LOG_WARN("batch evaluate failed", K(ret), K(right));
}
} else {
right_evaluated = false;
bound.set_all_row_active(false);
}
}
} else {
if (OB_FAIL(left.eval_vector(ctx, skip, bound))
|| OB_FAIL(right.eval_vector(ctx, skip, bound))) {
LOG_WARN("batch evaluate failed", K(ret), K(expr));
}
}
if (OB_SUCC(ret)) {
SQL_LOG(DEBUG, "expr.args_[0]", K(ToStrVectorHeader(*expr.args_[0], ctx, &skip, bound)));
SQL_LOG(DEBUG, "expr.args_[1]", K(ToStrVectorHeader(*expr.args_[1], ctx, rskip, bound)));
}
return ret;
}
int ObNestedArithOpBaseFunc::construct_param(ObIAllocator &alloc, ObEvalCtx &ctx, const uint16_t meta_id,
ObString &str_data, ObIArrayType *¶m_obj)
{
return ObNestedVectorFunc::construct_param(alloc, ctx, meta_id, str_data, param_obj);
}
int ObNestedArithOpBaseFunc::construct_res_obj(ObIAllocator &alloc, ObEvalCtx &ctx, const uint16_t meta_id, ObIArrayType *&res_obj)
{
return ObArrayExprUtils::construct_array_obj(alloc, ctx, meta_id, res_obj, false);
}
int ObNestedArithOpBaseFunc::construct_params(ObIAllocator &alloc, ObEvalCtx &ctx, const uint16_t left_meta_id,
const uint16_t right_meta_id, const uint16_t res_meta_id, ObString &left, ObString right,
ObIArrayType *&left_obj, ObIArrayType *&right_obj, ObIArrayType *&res_obj)
{
int ret = OB_SUCCESS;
if (OB_FAIL(ObArrayExprUtils::get_array_obj(alloc, ctx, left_meta_id, left, left_obj))) {
SQL_ENG_LOG(WARN, "get array failed", K(ret));
} else if (OB_FAIL(ObArrayExprUtils::get_array_obj(alloc, ctx, right_meta_id, right, right_obj))) {
SQL_ENG_LOG(WARN, "get array failed", K(ret));
} else if (OB_FAIL(ObArrayExprUtils::construct_array_obj(alloc, ctx, res_meta_id, res_obj, false))) {
SQL_ENG_LOG(WARN, "construct res array failed", K(ret));
}
return ret;
}
int ObNestedArithOpBaseFunc::get_res(ObEvalCtx &ctx, ObIArrayType *res_obj, const ObExpr &expr, ObString &res_str)
{
int ret = OB_SUCCESS;
if (OB_FAIL(res_obj->init())) {
LOG_WARN("array init failed", K(ret));
} else if (OB_FAIL(ObArrayExprUtils::set_array_res(res_obj, res_obj->get_raw_binary_len(), expr, ctx, res_str))) {
LOG_WARN("set array result failed", K(ret));
}
return ret;
}
void ObNestedArithOpBaseFunc::set_expr_attrs_null(const ObExpr &expr, ObEvalCtx &ctx, const int64_t idx)
{
ObArrayExprUtils::set_expr_attrs_null(expr, ctx, idx);
}
} // end namespace sql
} // end namespace oceanbase