forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_job_parser.cpp
More file actions
420 lines (352 loc) · 14.4 KB
/
Copy pathtest_job_parser.cpp
File metadata and controls
420 lines (352 loc) · 14.4 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include <gtest/gtest.h>
#include "ob_mock_utils.h"
#include "lib/allocator/page_arena.h"
#include "sql/ob_sql_init.h"
//#include "sql/engine/basic/ob_project.h"
#include "sql/engine/sort/ob_sort.h"
//#include "sql/engine/join/ob_merge_join.h"
//#include "sql/engine/dml/ob_when_filter.h"
#include "sql/executor/ob_root_transmit.h"
#include "sql/executor/ob_direct_receive.h"
#include "sql/engine/table/ob_table_scan.h"
#include "sql/executor/ob_distributed_job_control.h"
#include "sql/executor/ob_job_parser.h"
#include "sql/executor/ob_task_spliter_factory.h"
using namespace oceanbase;
using namespace oceanbase::common;
using namespace oceanbase::sql;
class ObJobParserTest : public ::testing::Test
{
public:
ObJobParserTest();
virtual ~ObJobParserTest();
virtual void SetUp();
virtual void TearDown();
static void print_phy_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op);
static void print_sub_phy_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op);
static void print_job_tree(char *buf, const int64_t buf_len, int64_t& pos, ObJobControl *jc);
private:
// disallow copy
ObJobParserTest(const ObJobParserTest &other);
ObJobParserTest& operator=(const ObJobParserTest &ohter);
private:
static void print_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op, int32_t level);
static void print_sub_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op, int32_t level);
};
ObJobParserTest::ObJobParserTest()
{
}
ObJobParserTest::~ObJobParserTest()
{
}
void ObJobParserTest::SetUp()
{
}
void ObJobParserTest::TearDown()
{
}
void ObJobParserTest::print_phy_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op)
{
ObJobParserTest::print_op_tree(buf, buf_len, pos, op, 0);
buf[pos] = '\0';
}
void ObJobParserTest::print_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op, int32_t level)
{
const char* op_name = NULL;
if (NULL != op)
{
op_name = ob_phy_operator_type_str(op->get_type());
}
for (int32_t i = 0; i < level; i++)
{
::oceanbase::common::databuff_printf(buf, buf_len, pos, " ");
}
::oceanbase::common::databuff_printf(buf, buf_len, pos, "|- %s\n", op_name);
if (NULL != op)
{
for (int32_t i = 0; i < op->get_child_num(); i++)
{
ObJobParserTest::print_op_tree(buf, buf_len, pos, op->get_child(i), level + 1);
}
}
}
void ObJobParserTest::print_job_tree(char *buf, const int64_t buf_len, int64_t& pos, ObJobControl *jc)
{
::oceanbase::common::databuff_printf(buf, buf_len, pos, "total jobs: %ld\n", jc->get_job_count());
ObArray<ObJob *> jobs;
jc->get_all_jobs(jobs);
for (int64_t i = 0; i < jobs.count(); ++i)
{
ObJob *job = jobs.at(i);
::oceanbase::common::databuff_printf(buf, buf_len, pos, "job_id=%ld, priority=%ld:\n", i, job->get_priority());
ObJobParserTest::print_sub_phy_op_tree(buf, buf_len, pos, job->get_root_op());
}
buf[pos] = '\0';
}
void ObJobParserTest::print_sub_phy_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op)
{
ObJobParserTest::print_sub_op_tree(buf, buf_len, pos, op, 0);
buf[pos] = '\0';
}
void ObJobParserTest::print_sub_op_tree(char *buf, const int64_t buf_len, int64_t& pos, ObPhyOperator *op, int32_t level)
{
const char* op_name = NULL;
if (NULL != op)
{
op_name = ob_phy_operator_type_str(op->get_type());
}
for (int32_t i = 0; i < level; i++)
{
::oceanbase::common::databuff_printf(buf, buf_len, pos, " ");
}
::oceanbase::common::databuff_printf(buf, buf_len, pos, "|- %s\n", op_name);
if (NULL != op)
{
for (int32_t i = 0; i < op->get_child_num(); i++)
{
ObTransmit* trans_op = dynamic_cast<ObTransmit*>(op->get_child(i));
if (NULL == trans_op)
{
ObJobParserTest::print_sub_op_tree(buf, buf_len, pos, op->get_child(i), level + 1);
}
}
}
}
TEST_F(ObJobParserTest, basic_test)
{
ObPhysicalPlan *physical_plan = ObPhysicalPlan::alloc();
ObPhyOperator *cur_op = NULL;
ObPhyOperator *tmp_op = NULL;
int err_code = OB_SUCCESS;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObTableScan, PHY_TABLE_SCAN, physical_plan, err_code);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
physical_plan->set_main_query(cur_op);
char buf[3000];
int64_t pos = 0;
ObJobParserTest::print_phy_op_tree(buf, 3000 - 1, pos, cur_op);
_OB_LOG(INFO, "physical operator tree:\n%s", buf);
ObExecContext exec_ctx;
exec_ctx.init_phy_op(1);
exec_ctx.create_physical_plan_ctx();
ObDistributedJobControl jc;
ObAddrsProviderFactory spf;
ObTaskSpliterFactory tsf;
ObJobParser parser;
ASSERT_EQ(OB_INVALID_ARGUMENT, parser.parse_job(exec_ctx, NULL, OB_INVALID_ID, tsf, spf, jc));
ASSERT_EQ(OB_SUCCESS, parser.parse_job(exec_ctx, physical_plan, OB_INVALID_ID, tsf, spf, jc));
ASSERT_EQ(3, jc.get_job_count());
ObJob *tmp_job = NULL;
ObArray<ObJob *> jobs;
jc.get_all_jobs(jobs);
tmp_job = jobs.at(0);
ASSERT_EQ(3, tmp_job->get_priority());
tmp_job = jobs.at(1);
ASSERT_EQ(2, tmp_job->get_priority());
tmp_job = jobs.at(2);
ASSERT_EQ(1, tmp_job->get_priority());
char buf1[3000];
int64_t pos1 = 0;
ObJobParserTest::print_job_tree(buf1, 3000 - 1, pos1, &jc);
_OB_LOG(INFO, "job tree:\n%s", buf1);
jobs.reset();
jc.get_ready_jobs(jobs);
ASSERT_EQ(1, jobs.count());
ASSERT_EQ(3, jobs.at(0)->get_priority());
//ASSERT_EQ(3, jobs.at(1)->get_priority());
//ASSERT_EQ(3, jobs.at(2)->get_priority());
//ASSERT_EQ(3, jobs.at(3)->get_priority());
}
TEST_F(ObJobParserTest, error_test_1)
{
ObPhysicalPlan *physical_plan = ObPhysicalPlan::alloc();
ObPhyOperator *cur_op = NULL;
ObPhyOperator *tmp_op = NULL;
int err_code = OB_SUCCESS;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObTableScan, PHY_TABLE_SCAN, physical_plan, err_code);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
physical_plan->set_main_query(cur_op);
char buf[3000];
int64_t pos = 0;
ObJobParserTest::print_phy_op_tree(buf, 3000 - 1, pos, cur_op);
_OB_LOG(INFO, "physical operator tree:\n%s", buf);
ObExecContext exec_ctx;
exec_ctx.init_phy_op(1);
exec_ctx.create_physical_plan_ctx();
ObDistributedJobControl jc;
ObAddrsProviderFactory spf;
ObTaskSpliterFactory tsf;
ObJobParser parser;
ASSERT_EQ(OB_INVALID_ARGUMENT, parser.parse_job(exec_ctx, NULL, OB_INVALID_ID, tsf, spf, jc));
ASSERT_EQ(OB_SUCCESS, parser.parse_job(exec_ctx, physical_plan, OB_INVALID_ID, tsf, spf, jc));
}
TEST_F(ObJobParserTest, error_test_2)
{
ObPhysicalPlan *physical_plan = ObPhysicalPlan::alloc();
ObPhyOperator *cur_op = NULL;
ObPhyOperator *tmp_op = NULL;
int err_code = OB_SUCCESS;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObTableScan, PHY_TABLE_SCAN, physical_plan, err_code);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
physical_plan->set_main_query(cur_op);
char buf[3000];
int64_t pos = 0;
ObJobParserTest::print_phy_op_tree(buf, 3000 - 1, pos, cur_op);
_OB_LOG(INFO, "physical operator tree:\n%s", buf);
ObExecContext exec_ctx;
exec_ctx.init_phy_op(1);
exec_ctx.create_physical_plan_ctx();
ObDistributedJobControl jc;
ObAddrsProviderFactory spf;
ObTaskSpliterFactory tsf;
ObJobParser parser;
ASSERT_EQ(OB_INVALID_ARGUMENT, parser.parse_job(exec_ctx, NULL, OB_INVALID_ID, tsf, spf, jc));
ASSERT_EQ(OB_SUCCESS, parser.parse_job(exec_ctx, physical_plan, OB_INVALID_ID, tsf, spf, jc));
}
TEST_F(ObJobParserTest, error_test_3)
{
ObPhysicalPlan *physical_plan = ObPhysicalPlan::alloc();
ObPhyOperator *cur_op = NULL;
ObPhyOperator *tmp_op = NULL;
int err_code = OB_SUCCESS;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObTableScan, PHY_TABLE_SCAN, physical_plan, err_code);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObSort, PHY_SORT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObDirectReceive, PHY_DIRECT_RECEIVE, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
cur_op = tmp_op;
TEST_CREATE_PHY_OPERATOR(tmp_op, ObRootTransmit, PHY_ROOT_TRANSMIT, physical_plan, err_code);
tmp_op->set_child(0, *cur_op);
static_cast<ObTransmit*>(tmp_op)->get_job_conf().set_task_split_type(ObTaskSpliter::IDENTITY_SPLIT);
cur_op = tmp_op;
physical_plan->set_main_query(cur_op);
char buf[3000];
int64_t pos = 0;
ObJobParserTest::print_phy_op_tree(buf, 3000 - 1, pos, cur_op);
_OB_LOG(INFO, "physical operator tree:\n%s", buf);
ObExecContext exec_ctx;
exec_ctx.init_phy_op(1); // actually should be 9, the operator count
exec_ctx.create_physical_plan_ctx();
ObDistributedJobControl jc;
ObAddrsProviderFactory spf;
ObTaskSpliterFactory tsf;
ObJobParser parser;
ASSERT_EQ(OB_INVALID_ARGUMENT, parser.parse_job(exec_ctx, NULL, OB_INVALID_ID, tsf, spf, jc));
ASSERT_EQ(OB_SUCCESS, parser.parse_job(exec_ctx, physical_plan, OB_INVALID_ID, tsf, spf, jc));
}
int main(int argc, char **argv)
{
oceanbase::common::ObLogger::get_logger().set_log_level("DEBUG");
init_sql_factories();
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}