oceanbase

Форк
0
/
test_create_executor.cpp 
590 строк · 23.1 Кб
1
/**
2
 * Copyright (c) 2023 OceanBase
3
 * OceanBase CE is licensed under Mulan PubL v2.
4
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
5
 * You may obtain a copy of Mulan PubL v2 at:
6
 *          http://license.coscl.org.cn/MulanPubL-2.0
7
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
 * See the Mulan PubL v2 for more details.
11
 */
12

13
#include <gtest/gtest.h>
14
#define private public  // 获取private成员
15
#define protected public  // 获取protect成员
16
#include "observer/table/ob_table_cg_service.h"
17
#include "observer/table/ob_table_cg_service.cpp"
18
#include "observer/table/ob_table_cache.h"
19
#include "observer/table/ob_table_context.h"
20
#include "../share/schema/mock_schema_service.h"
21
#include "sql/code_generator/ob_static_engine_cg.h"
22
#include "lib/net/ob_addr.h"
23
#include "sql/plan_cache/ob_lib_cache_register.h"
24
#include "observer/ob_req_time_service.h"
25
#include "share/rc/ob_tenant_base.h"
26
#include "sql/das/ob_data_access_service.h"
27

28
using namespace oceanbase::common;
29
using namespace oceanbase::table;
30
using namespace oceanbase::sql;
31
using namespace oceanbase::share;
32
using namespace oceanbase::share::schema;
33
using namespace oceanbase::observer;
34
using namespace oceanbase::pl;
35

36
// copy from test_table_schema.cpp
37
void fill_table_schema(ObTableSchema &table)
38
{
39
  table.set_tenant_id(1);
40
  table.set_database_id(1);
41
  table.set_tablegroup_id(1);
42
  table.set_table_id(3001);
43
  table.set_max_used_column_id(16);
44
  table.set_rowkey_column_num(0);
45
  table.set_index_column_num(0);
46
  table.set_rowkey_split_pos(11);
47
  table.set_progressive_merge_num(11);
48
  table.set_compress_func_name(ObString::make_string("snappy_1.0"));
49
  table.set_autoinc_column_id(0);
50
  table.set_auto_increment(1);
51
  table.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
52
  table.set_def_type(TABLE_DEF_TYPE_USER);
53
  table.set_part_level(PARTITION_LEVEL_TWO);
54
  table.set_charset_type(CHARSET_UTF8MB4);
55
  table.set_collation_type(CS_TYPE_UTF8MB4_BIN);
56
  table.set_table_type(USER_TABLE);
57
  table.set_index_type(INDEX_TYPE_IS_NOT);
58
  table.set_index_status(INDEX_STATUS_AVAILABLE);
59
  table.set_data_table_id(0);
60
  table.set_is_use_bloomfilter(false);
61
  table.set_block_size(2097152);
62
  table.set_tablegroup_name("table group name 1");
63
  table.set_comment("This is a table");
64
  table.set_table_name("table_xxx");
65
  table.set_expire_info("expire: modify_time > 3000s");
66
  table.set_schema_version(1);
67
  table.get_part_option().set_part_func_type(PARTITION_FUNC_TYPE_HASH);
68
  table.get_part_option().set_part_expr (ObString::make_string("rand() mod 111"));
69
  table.get_part_option().set_part_num(100);
70
  table.get_sub_part_option().set_part_func_type(PARTITION_FUNC_TYPE_HASH);
71
  table.get_sub_part_option().set_part_expr (ObString::make_string("rand() mod 111"));
72
  table.get_sub_part_option().set_part_num(666);
73
}
74
// 填充一个column_schema,类型:ObIntType
75
// rowkey_pos: >0时为rowkey列,表示rowkey的顺序
76
// index_key_pos:>0时为索引列,表示索引列顺序
77
// part_key_pos:>0时为分区键,表示分区间顺序
78
void fill_column_schema(ObColumnSchemaV2 &column, uint64_t id, const char *name,
79
                        uint64_t rowkey_pos = 1, uint64_t index_key_pos = 1,
80
                        uint64_t part_key_pos = 1, ObOrderType rowkey_order = ObOrderType::ASC)
81
{
82
  ObObj value;
83
  column.set_column_id(id);
84
  column.set_column_name(ObString::make_string(name));
85
  column.set_rowkey_position(rowkey_pos);
86
  column.set_order_in_rowkey(rowkey_order);
87
  column.set_tbl_part_key_pos(part_key_pos);
88
  column.set_index_position(index_key_pos);
89
  column.set_data_length(100);
90
  column.set_data_precision(1100);
91
  column.set_data_scale(88);
92
  column.set_nullable(false);
93
  column.set_charset_type(CHARSET_UTF8MB4);
94
  column.set_collation_type(CS_TYPE_UTF8MB4_BIN);
95
  column.set_data_type(ObIntType);
96
  value.set_int(100);
97
  column.set_orig_default_value(value);
98
  value.set_int(101);
99
  column.set_cur_default_value(value);
100
  column.set_comment("black gives me black eyes");
101
}
102

103
// create table test (C1, C2, C3)
104
void create_table_schema(ObTableSchema *table_schema, ObColumnSchemaV2 *columns)
105
{
106
  ASSERT_NE(nullptr, table_schema);
107
  fill_table_schema(*table_schema);
108
  fill_column_schema(columns[0], 1, "C1", 1, 1, 1);
109
  fill_column_schema(columns[1], 2, "C2", 0, 0, 0);
110
  fill_column_schema(columns[2], 3, "C3", 0, 0, 0);
111
  ASSERT_EQ(OB_SUCCESS, table_schema->add_column(columns[0]));
112
  ASSERT_EQ(OB_SUCCESS, table_schema->add_column(columns[1]));
113
  ASSERT_EQ(OB_SUCCESS, table_schema->add_column(columns[2]));
114
  ASSERT_EQ(1, table_schema->get_tenant_id());
115
  ASSERT_EQ(1, table_schema->get_database_id());
116
  ASSERT_EQ(1, table_schema->get_tablegroup_id());
117
  ASSERT_EQ(3001, table_schema->get_table_id());
118
  ASSERT_EQ(3, table_schema->get_column_count());
119
  ASSERT_EQ(1, table_schema->get_index_column_num());
120
  ASSERT_EQ(1, table_schema->get_rowkey_column_num());
121
  ASSERT_EQ(1, table_schema->get_partition_key_column_num());
122
}
123

124
class TestCreateExecutor: public ::testing::Test
125
{
126
public:
127
  TestCreateExecutor();
128
  virtual ~TestCreateExecutor() {}
129
  virtual void SetUp();
130
  virtual void TearDown();
131
  void fake_ctx_init_common(ObTableCtx &fake_ctx, ObTableSchema *table_schema);
132
public:
133
  ObArenaAllocator allocator_;
134
  MockSchemaService schema_service_;
135
  ObSchemaGetterGuard schema_guard_;
136
  ObTableSchema table_schema_;
137
  ObColumnSchemaV2 columns_[3];
138
private:
139
  // disallow copy
140
  DISALLOW_COPY_AND_ASSIGN(TestCreateExecutor);
141
};
142

143
TestCreateExecutor::TestCreateExecutor()
144
  : allocator_()
145
{
146
}
147

148
void TestCreateExecutor::SetUp()
149
{
150
  oceanbase::ObClusterVersion::get_instance().update_data_version(DATA_CURRENT_VERSION);
151
  schema_service_.init();
152
  create_table_schema(&table_schema_, columns_);
153
  schema_service_.add_table_schema(table_schema_, 1);
154
  schema_service_.get_schema_guard(schema_guard_, 1);
155
  // init MTL
156
  ObTenantBase tbase(1);
157
  static ObDataAccessService instance;
158
  tbase.inner_set(&instance);
159
  ASSERT_EQ(OB_SUCCESS, tbase.init());
160
  ObTenantEnv::set_tenant(&tbase);
161
}
162

163
void TestCreateExecutor::TearDown()
164
{
165
}
166

167
ObTableApiSessNodeVal g_sess_node_val(NULL, 500);
168
void TestCreateExecutor::fake_ctx_init_common(ObTableCtx &fake_ctx, ObTableSchema *table_schema)
169
{
170
  fake_ctx.table_schema_ = table_schema;
171
  fake_ctx.tenant_id_ = table_schema->get_tenant_id();
172
  fake_ctx.database_id_ = table_schema->get_database_id();
173
  fake_ctx.table_name_ = table_schema->get_table_name();
174
  fake_ctx.ref_table_id_ = table_schema->get_table_id();
175
  fake_ctx.index_table_id_ = fake_ctx.ref_table_id_;
176
  fake_ctx.index_tablet_id_ = table_schema->get_table_id();
177
  fake_ctx.sess_guard_.sess_node_val_ = &g_sess_node_val;
178
  g_sess_node_val.is_inited_ = true;
179
  g_sess_node_val.sess_info_.test_init(0, 0, 0, NULL);
180
  g_sess_node_val.sess_info_.load_all_sys_vars(schema_guard_);
181
  fake_ctx.init_physical_plan_ctx(0, 1);
182
  ASSERT_EQ(OB_SUCCESS, fake_ctx.construct_column_items());
183
}
184

185
TEST_F(TestCreateExecutor, scan)
186
{
187
  ObTableCtx fake_ctx(allocator_);
188
  ObExprFrameInfo fake_expr_info(allocator_);
189
  ObTableEntity entity;
190
  // init ctx
191
  fake_ctx_init_common(fake_ctx, &table_schema_);
192
  fake_ctx.set_entity(&entity);
193
  ASSERT_EQ(OB_SUCCESS, fake_ctx.init_get());
194
  for (int i = 0; i < 3; i++) {
195
    ASSERT_EQ(columns_[i].get_column_id(), fake_ctx.select_col_ids_.at(i));
196
  }
197
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
198
  fake_ctx.set_expr_info(&fake_expr_info);
199
  ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
200
  ASSERT_EQ(OB_SUCCESS, fake_ctx.classify_scan_exprs());
201
  ASSERT_EQ(3, fake_ctx.select_exprs_.count());
202
  ASSERT_EQ(1, fake_ctx.rowkey_exprs_.count());
203

204
  ObTableApiSpec *root_spec = nullptr;
205
  ObTableApiExecutor *executor = nullptr;
206
  ASSERT_EQ(OB_SUCCESS, ObTableSpecCgService::generate<TABLE_API_EXEC_SCAN>(allocator_, fake_ctx, root_spec));
207
  ASSERT_TRUE(nullptr != root_spec);
208
  ASSERT_EQ(TABLE_API_EXEC_SCAN, root_spec->get_type());
209
  ASSERT_EQ(nullptr, root_spec->get_parent());
210
  ASSERT_EQ(nullptr, root_spec->get_child());
211

212
  ASSERT_EQ(OB_SUCCESS, root_spec->create_executor(fake_ctx, executor));
213
  ASSERT_TRUE(nullptr != executor);
214
  ObTableApiScanExecutor *scan_executor = dynamic_cast<ObTableApiScanExecutor *>(executor);
215
  ASSERT_TRUE(nullptr != scan_executor);
216
  ASSERT_EQ(nullptr, executor->get_parent());
217
  ASSERT_EQ(nullptr, executor->get_child());
218
}
219

220
TEST_F(TestCreateExecutor, insert)
221
{
222
  ObTableCtx fake_ctx(allocator_);
223
  ObExprFrameInfo fake_expr_info(allocator_);
224
  // init ctx
225
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
226
  fake_ctx_init_common(fake_ctx, &table_schema_);
227
  ASSERT_EQ(OB_SUCCESS, fake_ctx.init_insert());
228
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
229
  fake_ctx.set_expr_info(&fake_expr_info);
230
  ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
231

232
  ObTableApiSpec *root_spec = nullptr;
233
  ObTableApiExecutor *executor = nullptr;
234

235
  // generate insert spec tree
236
  ASSERT_EQ(OB_SUCCESS, ObTableSpecCgService::generate<TABLE_API_EXEC_INSERT>(allocator_, fake_ctx, root_spec));
237
  ASSERT_TRUE(nullptr != root_spec);
238
  ASSERT_EQ(TABLE_API_EXEC_INSERT, root_spec->get_type());
239
  ASSERT_EQ(nullptr, root_spec->get_parent());
240
  ASSERT_EQ(nullptr, root_spec->get_child());
241

242
  // create insert excutor tree;
243
  ASSERT_EQ(OB_SUCCESS, root_spec->create_executor(fake_ctx, executor));
244
  ASSERT_TRUE(nullptr != executor);
245
  ObTableApiInsertExecutor *ins_executor = dynamic_cast<ObTableApiInsertExecutor *>(executor);
246
  ASSERT_TRUE(nullptr != ins_executor);
247
  ASSERT_EQ(nullptr, executor->get_parent());
248
  ASSERT_EQ(nullptr, executor->get_child());
249
}
250

251
TEST_F(TestCreateExecutor, delete)
252
{
253
  ObTableCtx fake_ctx(allocator_);
254
  ObExprFrameInfo fake_expr_info(allocator_);
255
  // init ctx
256
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
257
  fake_ctx_init_common(fake_ctx, &table_schema_);
258
  ASSERT_EQ(OB_SUCCESS, fake_ctx.init_delete());
259
  ASSERT_EQ(3, fake_ctx.select_col_ids_.count());
260
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
261
  fake_ctx.set_expr_info(&fake_expr_info);
262
  ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
263
  ObTableApiSpec *root_spec = nullptr;
264
  ObTableApiExecutor *executor = nullptr;
265

266
  // generate delete spec tree
267
  ASSERT_EQ(OB_SUCCESS, ObTableSpecCgService::generate<TABLE_API_EXEC_DELETE>(allocator_, fake_ctx, root_spec));
268
  ASSERT_TRUE(nullptr != root_spec);
269
  ASSERT_EQ(TABLE_API_EXEC_DELETE, root_spec->get_type());
270
  ASSERT_EQ(nullptr, root_spec->get_parent());
271
  ASSERT_TRUE(nullptr != root_spec->get_child());
272

273
  // check child spec (scan)
274
  const ObTableApiScanSpec *child_spec = dynamic_cast<const ObTableApiScanSpec *>(root_spec->get_child());
275
  ASSERT_TRUE(nullptr != child_spec);
276
  ASSERT_EQ(nullptr, child_spec->get_child());
277
  ASSERT_EQ(root_spec, child_spec->get_parent());
278

279
  // create executor tree
280
  ASSERT_EQ(OB_SUCCESS, root_spec->create_executor(fake_ctx, executor));
281
  ASSERT_TRUE(nullptr != executor);
282
  ObTableApiDeleteExecutor *del_executor = dynamic_cast<ObTableApiDeleteExecutor *>(executor);
283
  ASSERT_TRUE(nullptr != del_executor);
284
  ASSERT_EQ(nullptr, del_executor->get_parent());
285
  ASSERT_TRUE(nullptr != del_executor->get_child());
286

287
  // check child executor (scan)
288
  const ObTableApiScanExecutor *scan_executor = dynamic_cast<const ObTableApiScanExecutor *>(del_executor->get_child());
289
  ASSERT_TRUE(nullptr != scan_executor);
290
  ASSERT_EQ(del_executor, scan_executor->get_parent());
291
  ASSERT_EQ(nullptr, scan_executor->get_child());
292
}
293

294
TEST_F(TestCreateExecutor, update)
295
{
296
  ObTableCtx fake_ctx(allocator_);
297
  ObExprFrameInfo fake_expr_info(allocator_);
298
  // prepare
299
  ObTableEntity entity;
300
  ObObj obj;
301
  obj.set_int(1234);
302
  entity.add_rowkey_value(obj);
303
  entity.set_property(ObString::make_string("C2"), obj);
304
  // init ctx
305
  fake_ctx.set_entity(&entity);
306
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
307
  fake_ctx_init_common(fake_ctx, &table_schema_);
308
  ASSERT_EQ(OB_SUCCESS, fake_ctx.init_update());
309

310
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
311
  fake_ctx.set_expr_info(&fake_expr_info);
312
  ASSERT_EQ(4, fake_ctx.get_all_exprs().get_expr_array().count());
313
  ObTableApiSpec *root_spec = nullptr;
314
  ObTableApiExecutor *executor = nullptr;
315
  // generate update spec tree
316
  ASSERT_EQ(OB_SUCCESS, ObTableSpecCgService::generate<TABLE_API_EXEC_UPDATE>(allocator_, fake_ctx, root_spec));
317
  ASSERT_TRUE(nullptr != root_spec);
318
  ASSERT_EQ(TABLE_API_EXEC_UPDATE, root_spec->get_type());
319
  ASSERT_EQ(nullptr, root_spec->get_parent());
320
  ASSERT_TRUE(nullptr != root_spec->get_child());
321

322
  // check child spec (scan)
323
  const ObTableApiScanSpec *child_spec = dynamic_cast<const ObTableApiScanSpec *>(root_spec->get_child());
324
  ASSERT_TRUE(nullptr != child_spec);
325
  ASSERT_EQ(nullptr, child_spec->get_child());
326
  ASSERT_EQ(root_spec, child_spec->get_parent());
327

328
  // create executor tree
329
  ASSERT_EQ(OB_SUCCESS, root_spec->create_executor(fake_ctx, executor));
330
  ASSERT_TRUE(nullptr != executor);
331
  ObTableApiUpdateExecutor *upd_executor = dynamic_cast<ObTableApiUpdateExecutor *>(executor);
332
  ASSERT_TRUE(nullptr != upd_executor);
333
  ASSERT_EQ(nullptr, upd_executor->get_parent());
334
  ASSERT_TRUE(nullptr != upd_executor->get_child());
335

336
  // check child executor (scan)
337
  const ObTableApiScanExecutor *scan_executor = dynamic_cast<const ObTableApiScanExecutor *>(upd_executor->get_child());
338
  ASSERT_TRUE(nullptr != scan_executor);
339
  ASSERT_EQ(upd_executor, scan_executor->get_parent());
340
  ASSERT_EQ(nullptr, scan_executor->get_child());
341
}
342

343
TEST_F(TestCreateExecutor, insertup)
344
{
345
  ObTableCtx fake_ctx(allocator_);
346
  ObExprFrameInfo fake_expr_info(allocator_);
347
  ObTableEntity entity;
348
  ObObj obj;
349
  obj.set_int(1234);
350
  entity.add_rowkey_value(obj);
351
  entity.set_property(ObString::make_string("C2"), obj);
352
  // init ctx
353
  fake_ctx.set_entity(&entity);
354
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
355
  fake_ctx_init_common(fake_ctx, &table_schema_);
356
  ASSERT_EQ(OB_SUCCESS, fake_ctx.init_insert_up(false));
357
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
358
  fake_ctx.set_expr_info(&fake_expr_info);
359
  ASSERT_EQ(4, fake_ctx.get_all_exprs().get_expr_array().count());
360
  ObTableApiSpec *root_spec = nullptr;
361
  ObTableApiExecutor *executor = nullptr;
362

363
  // generate insertup spec tree
364
  ASSERT_EQ(OB_SUCCESS, ObTableSpecCgService::generate<TABLE_API_EXEC_INSERT_UP>(allocator_, fake_ctx, root_spec));
365
  ASSERT_TRUE(nullptr != root_spec);
366
  ASSERT_EQ(TABLE_API_EXEC_INSERT_UP, root_spec->get_type());
367
  ASSERT_EQ(nullptr, root_spec->get_parent());
368
  ASSERT_EQ(nullptr, root_spec->get_child());
369

370
  // create insertup excutor tree;
371
  ASSERT_EQ(OB_SUCCESS, root_spec->create_executor(fake_ctx, executor));
372
  ASSERT_TRUE(nullptr != executor);
373
  ObTableApiInsertUpExecutor *insup_executor = dynamic_cast<ObTableApiInsertUpExecutor *>(executor);
374
  ASSERT_TRUE(nullptr != insup_executor);
375
  ASSERT_EQ(nullptr, executor->get_parent());
376
  ASSERT_EQ(nullptr, executor->get_child());
377
}
378

379
TEST_F(TestCreateExecutor, replace)
380
{
381
  ObTableCtx fake_ctx(allocator_);
382
  ObExprFrameInfo fake_expr_info(allocator_);
383
  // init ctx
384
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
385
  fake_ctx_init_common(fake_ctx, &table_schema_);
386
  ASSERT_EQ(OB_SUCCESS, fake_ctx.init_replace());
387
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
388
  fake_ctx.set_expr_info(&fake_expr_info);
389
  ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
390
  ObTableApiSpec *root_spec = nullptr;
391
  ObTableApiExecutor *executor = nullptr;
392

393
  // generate replace spec tree
394
  ASSERT_EQ(OB_SUCCESS, ObTableSpecCgService::generate<TABLE_API_EXEC_REPLACE>(allocator_, fake_ctx, root_spec));
395
  ASSERT_TRUE(nullptr != root_spec);
396
  ASSERT_EQ(TABLE_API_EXEC_REPLACE, root_spec->get_type());
397
  ASSERT_EQ(nullptr, root_spec->get_parent());
398
  ASSERT_EQ(nullptr, root_spec->get_child());
399

400
  // create replace excutor tree;
401
  ASSERT_EQ(OB_SUCCESS, root_spec->create_executor(fake_ctx, executor));
402
  ASSERT_TRUE(nullptr != executor);
403
  ObTableApiReplaceExecutor *replace_executor = dynamic_cast<ObTableApiReplaceExecutor *>(executor);
404
  ASSERT_TRUE(nullptr != replace_executor);
405
  ASSERT_EQ(nullptr, executor->get_parent());
406
  ASSERT_EQ(nullptr, executor->get_child());
407
}
408

409
// refresh frame: init_datum_param_store + check_entity + refresh_rowkey_exprs_frame + refresh_properties_exprs_frame
410
TEST_F(TestCreateExecutor, refresh_exprs_frame)
411
{
412
  ObTableCtx fake_ctx(allocator_);
413
  ObExprFrameInfo fake_expr_info(allocator_);
414
  ObTableEntity entity;
415
  ObStaticEngineCG cg(GET_MIN_CLUSTER_VERSION());
416
  // prepare data
417
  ObObj obj;
418
  obj.set_int(1234);
419
  entity.add_rowkey_value(obj);
420
  obj.set_int(1235);
421
  entity.set_property(ObString::make_string("C2"), obj);
422
  // init ctx
423
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
424
  fake_ctx_init_common(fake_ctx, &table_schema_);
425
  ASSERT_EQ(OB_SUCCESS, fake_ctx.init_insert());
426
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::generate_exprs(fake_ctx, allocator_, fake_expr_info));
427
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::alloc_exprs_memory(fake_ctx, fake_expr_info));
428
  fake_ctx.set_expr_info(&fake_expr_info);
429
  ASSERT_EQ(3, fake_ctx.get_all_exprs().get_expr_array().count());
430
  ObArray<ObExpr *> rt_exprs;
431
  ASSERT_EQ(OB_SUCCESS, cg.generate_rt_exprs(fake_ctx.get_all_exprs().get_expr_array(), rt_exprs));
432

433
  ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::refresh_exprs_frame(fake_ctx, rt_exprs, entity));
434
  // verify the refresh value
435
  ObEvalCtx eval_ctx(fake_ctx.get_exec_ctx());
436
  ObDatum *datum = nullptr;
437
  ObExpr *rt_expr = nullptr;
438
  ObObj objs[3];
439
  const ObIArray<ObRawExpr *> &all_exprs = fake_ctx.get_all_exprs().get_expr_array();
440
  for (int i = 0; i < all_exprs.count(); i++) {
441
    ASSERT_EQ(OB_SUCCESS, cg.generate_rt_expr(*all_exprs.at(i), rt_expr));
442
    ASSERT_EQ(OB_SUCCESS, rt_expr->eval(eval_ctx, datum));
443
    ASSERT_EQ(OB_SUCCESS, datum->to_obj(objs[i], columns_[i].get_meta_type()));
444
  }
445
  ASSERT_EQ(1234, objs[0].get_int());
446
  ASSERT_EQ(1235, objs[1].get_int());
447
  // column default value
448
  ASSERT_EQ(101, objs[2].get_int());
449
}
450

451
// table context
452
TEST_F(TestCreateExecutor, cons_column_type)
453
{
454
  ObColumnSchemaV2 col_schema;
455
  // prepare data
456
  col_schema.set_data_type(ObVarcharType);
457
  col_schema.set_collation_type(CS_TYPE_UTF8MB4_GENERAL_CI);
458
  ObAccuracy acc(1);
459
  col_schema.set_accuracy(acc);
460
  uint32_t res_flag = ObRawExprUtils::calc_column_result_flag(col_schema);
461

462
  ObTableColumnInfo column_info;
463
  ObTableCtx fake_ctx(allocator_);
464
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
465
  fake_ctx_init_common(fake_ctx, &table_schema_);
466
  ASSERT_EQ(OB_SUCCESS, fake_ctx.cons_column_info(col_schema, column_info));
467
  ASSERT_EQ(ObVarcharType, column_info.type_.get_type());
468
  ASSERT_EQ(res_flag, column_info.type_.get_result_flag());
469
  ASSERT_EQ(CS_TYPE_UTF8MB4_GENERAL_CI, column_info.type_.get_collation_type());
470
  ASSERT_EQ(CS_LEVEL_IMPLICIT, column_info.type_.get_collation_level());
471
  ASSERT_EQ(1, column_info.type_.get_accuracy().get_length());
472
}
473

474
TEST_F(TestCreateExecutor, check_column_type)
475
{
476
  ObTableColumnInfo column_info;
477
  column_info.type_.set_result_flag(NOT_NULL_WRITE_FLAG);
478
  ObObj obj;
479
  uint32_t res_flag = 0;
480
  ObTableCtx fake_ctx(allocator_);
481
  schema_service_.get_schema_guard(fake_ctx.schema_guard_, 1);
482
  fake_ctx_init_common(fake_ctx, &table_schema_);
483

484
  // check nullable
485
  obj.set_null();
486
  res_flag |= NOT_NULL_FLAG;
487
  column_info.type_.set_result_flag(res_flag);
488
  column_info.is_nullable_ = false;
489
  ASSERT_EQ(OB_BAD_NULL_ERROR, fake_ctx.adjust_column_type(column_info, obj));
490
  // check data type mismatch
491
  res_flag = 0;
492
  obj.set_int(1);
493
  column_info.type_.set_result_flag(res_flag);
494
  column_info.type_.set_type(ObVarcharType);
495
  ASSERT_EQ(OB_KV_COLUMN_TYPE_NOT_MATCH, fake_ctx.adjust_column_type(column_info, obj));
496
  // check collation
497
  obj.set_binary("ttt");
498
  column_info.type_.set_collation_type(CS_TYPE_UTF8MB4_GENERAL_CI);
499
  ASSERT_EQ(OB_KV_COLLATION_MISMATCH, fake_ctx.adjust_column_type(column_info, obj));
500
  // collation convert
501
  obj.set_varchar("test");
502
  obj.set_collation_type(CS_TYPE_UTF8MB4_BIN);
503
  ASSERT_EQ(OB_SUCCESS, fake_ctx.adjust_column_type(column_info, obj));
504
  ASSERT_EQ(CS_TYPE_UTF8MB4_GENERAL_CI, obj.get_collation_type());
505
}
506

507
TEST_F(TestCreateExecutor, generate_key_range)
508
{
509
  ObTableCtx fake_ctx(allocator_);
510
  fake_ctx_init_common(fake_ctx, &table_schema_);
511
  // prepare data
512
  ObArray<ObNewRange> scan_ranges;
513
  ObObj pk_objs_start[1];
514
  pk_objs_start[0].set_int(0);
515
  ObObj pk_objs_end[1];
516
  pk_objs_end[0].set_max_value();
517
  ObNewRange range;
518
  range.start_key_.assign(pk_objs_start, 1);
519
  range.end_key_.assign(pk_objs_end, 1);
520
  range.border_flag_.set_inclusive_start();
521
  range.border_flag_.set_inclusive_end();
522
  scan_ranges.push_back(range);
523
  ASSERT_EQ(OB_SUCCESS, fake_ctx.generate_key_range(scan_ranges));
524
  // primary key range
525
  ASSERT_EQ(1, fake_ctx.get_key_ranges().count());
526
}
527

528
TEST_F(TestCreateExecutor, test_cache)
529
{
530
  uint64_t tenant_id = 1;
531
  ObTenantBase tenant_ctx(tenant_id);
532
  ObTenantEnv::set_tenant(&tenant_ctx);
533
  // init plan cache
534
  ObPlanCache plan_cache;
535
  int ret = plan_cache.init(OB_PLAN_CACHE_BUCKET_NUMBER, tenant_id);
536
  ASSERT_EQ(ret, OB_SUCCESS);
537
  plan_cache.set_mem_limit_pct(20);
538
  plan_cache.set_mem_high_pct(90);
539
  plan_cache.set_mem_low_pct(50);
540

541
  ObAddr addr;
542
  ObPCMemPctConf conf;
543
  ObLibCacheNameSpace ns = ObLibCacheNameSpace::NS_TABLEAPI;
544
  ObReqTimeGuard req_timeinfo_guard;
545
  // register cache obj
546
  ObLibCacheRegister::register_cache_objs();
547
  // get lib cache
548
  ObPlanCache *lib_cache = &plan_cache;
549
  // construct cache key
550
  ObTableApiCacheKey cache_key;
551
  cache_key.table_id_ = 1001;
552
  cache_key.index_table_id_ = 1001;
553
  cache_key.schema_version_ = 1;
554
  cache_key.operation_type_ = ObTableOperationType::Type::INSERT;
555
  cache_key.is_ttl_table_ = false;
556
  // construct ctx
557
  ObILibCacheCtx ctx;
558
  // construct cache obj
559
  {
560
    ObCacheObjGuard guard(CacheRefHandleID::TABLEAPI_NODE_HANDLE);
561
    ASSERT_EQ(OB_SUCCESS, lib_cache->alloc_cache_obj(guard, ns, tenant_id));
562
    ObILibCacheObject *cache_obj = guard.get_cache_obj();
563
    ASSERT_TRUE(nullptr != cache_obj);
564
    ObTableApiCacheObj *table_cache_obj = static_cast<ObTableApiCacheObj *>(cache_obj);
565
    ObIAllocator &cache_allocator = table_cache_obj->get_allocator();
566
    // construct spec
567
    ObTableApiInsertSpec spec(cache_allocator, TABLE_API_EXEC_INSERT);
568
    table_cache_obj->set_spec(&spec);
569
    // add an cache obj
570
    ASSERT_EQ(OB_SUCCESS, lib_cache->add_cache_obj(ctx, &cache_key , table_cache_obj));
571
  }
572
  // get cache obj
573
  {
574
    ObCacheObjGuard guard(CacheRefHandleID::TABLEAPI_NODE_HANDLE);
575
    ASSERT_EQ(OB_SUCCESS, lib_cache->get_cache_obj(ctx, &cache_key, guard));
576
    ObTableApiCacheObj *cache_obj = static_cast<ObTableApiCacheObj *>(guard.get_cache_obj());
577
    ASSERT_TRUE(nullptr != cache_obj);
578
    ObTableApiSpec *spec = cache_obj->get_spec();
579
    ASSERT_TRUE(nullptr != spec);
580
    ASSERT_EQ(TABLE_API_EXEC_INSERT, spec->type_);
581
  }
582
}
583

584
int main(int argc, char **argv)
585
{
586
  OB_LOGGER.set_log_level("INFO");
587
  OB_LOGGER.set_file_name("test_create_executor.log", true);
588
  ::testing::InitGoogleTest(&argc,argv);
589
  return RUN_ALL_TESTS();
590
}
591

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.