13
#include <gtest/gtest.h>
15
#define protected public
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"
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;
37
void fill_table_schema(ObTableSchema &table)
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);
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)
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);
97
column.set_orig_default_value(value);
99
column.set_cur_default_value(value);
100
column.set_comment("black gives me black eyes");
104
void create_table_schema(ObTableSchema *table_schema, ObColumnSchemaV2 *columns)
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());
124
class TestCreateExecutor: public ::testing::Test
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);
133
ObArenaAllocator allocator_;
134
MockSchemaService schema_service_;
135
ObSchemaGetterGuard schema_guard_;
136
ObTableSchema table_schema_;
137
ObColumnSchemaV2 columns_[3];
140
DISALLOW_COPY_AND_ASSIGN(TestCreateExecutor);
143
TestCreateExecutor::TestCreateExecutor()
148
void TestCreateExecutor::SetUp()
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);
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);
163
void TestCreateExecutor::TearDown()
167
ObTableApiSessNodeVal g_sess_node_val(NULL, 500);
168
void TestCreateExecutor::fake_ctx_init_common(ObTableCtx &fake_ctx, ObTableSchema *table_schema)
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());
185
TEST_F(TestCreateExecutor, scan)
187
ObTableCtx fake_ctx(allocator_);
188
ObExprFrameInfo fake_expr_info(allocator_);
189
ObTableEntity entity;
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));
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());
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());
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());
220
TEST_F(TestCreateExecutor, insert)
222
ObTableCtx fake_ctx(allocator_);
223
ObExprFrameInfo fake_expr_info(allocator_);
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());
232
ObTableApiSpec *root_spec = nullptr;
233
ObTableApiExecutor *executor = nullptr;
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());
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());
251
TEST_F(TestCreateExecutor, delete)
253
ObTableCtx fake_ctx(allocator_);
254
ObExprFrameInfo fake_expr_info(allocator_);
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;
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());
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());
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());
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());
294
TEST_F(TestCreateExecutor, update)
296
ObTableCtx fake_ctx(allocator_);
297
ObExprFrameInfo fake_expr_info(allocator_);
299
ObTableEntity entity;
302
entity.add_rowkey_value(obj);
303
entity.set_property(ObString::make_string("C2"), obj);
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());
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;
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());
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());
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());
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());
343
TEST_F(TestCreateExecutor, insertup)
345
ObTableCtx fake_ctx(allocator_);
346
ObExprFrameInfo fake_expr_info(allocator_);
347
ObTableEntity entity;
350
entity.add_rowkey_value(obj);
351
entity.set_property(ObString::make_string("C2"), obj);
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;
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());
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());
379
TEST_F(TestCreateExecutor, replace)
381
ObTableCtx fake_ctx(allocator_);
382
ObExprFrameInfo fake_expr_info(allocator_);
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;
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());
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());
410
TEST_F(TestCreateExecutor, refresh_exprs_frame)
412
ObTableCtx fake_ctx(allocator_);
413
ObExprFrameInfo fake_expr_info(allocator_);
414
ObTableEntity entity;
415
ObStaticEngineCG cg(GET_MIN_CLUSTER_VERSION());
419
entity.add_rowkey_value(obj);
421
entity.set_property(ObString::make_string("C2"), obj);
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));
433
ASSERT_EQ(OB_SUCCESS, ObTableExprCgService::refresh_exprs_frame(fake_ctx, rt_exprs, entity));
435
ObEvalCtx eval_ctx(fake_ctx.get_exec_ctx());
436
ObDatum *datum = nullptr;
437
ObExpr *rt_expr = nullptr;
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()));
445
ASSERT_EQ(1234, objs[0].get_int());
446
ASSERT_EQ(1235, objs[1].get_int());
448
ASSERT_EQ(101, objs[2].get_int());
452
TEST_F(TestCreateExecutor, cons_column_type)
454
ObColumnSchemaV2 col_schema;
456
col_schema.set_data_type(ObVarcharType);
457
col_schema.set_collation_type(CS_TYPE_UTF8MB4_GENERAL_CI);
459
col_schema.set_accuracy(acc);
460
uint32_t res_flag = ObRawExprUtils::calc_column_result_flag(col_schema);
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());
474
TEST_F(TestCreateExecutor, check_column_type)
476
ObTableColumnInfo column_info;
477
column_info.type_.set_result_flag(NOT_NULL_WRITE_FLAG);
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_);
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));
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));
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));
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());
507
TEST_F(TestCreateExecutor, generate_key_range)
509
ObTableCtx fake_ctx(allocator_);
510
fake_ctx_init_common(fake_ctx, &table_schema_);
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();
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));
525
ASSERT_EQ(1, fake_ctx.get_key_ranges().count());
528
TEST_F(TestCreateExecutor, test_cache)
530
uint64_t tenant_id = 1;
531
ObTenantBase tenant_ctx(tenant_id);
532
ObTenantEnv::set_tenant(&tenant_ctx);
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);
543
ObLibCacheNameSpace ns = ObLibCacheNameSpace::NS_TABLEAPI;
544
ObReqTimeGuard req_timeinfo_guard;
546
ObLibCacheRegister::register_cache_objs();
548
ObPlanCache *lib_cache = &plan_cache;
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;
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();
567
ObTableApiInsertSpec spec(cache_allocator, TABLE_API_EXEC_INSERT);
568
table_cache_obj->set_spec(&spec);
570
ASSERT_EQ(OB_SUCCESS, lib_cache->add_cache_obj(ctx, &cache_key , table_cache_obj));
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_);
584
int main(int argc, char **argv)
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();