forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_subschema_ctx.cpp
More file actions
606 lines (574 loc) · 20.8 KB
/
Copy pathob_subschema_ctx.cpp
File metadata and controls
606 lines (574 loc) · 20.8 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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/*
* 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_ENG
#include "sql/engine/ob_subschema_ctx.h"
#include "deps/oblib/src/lib/udt/ob_udt_type.h"
#include "deps/oblib/src/lib/udt/ob_array_utils.h"
#include "lib/enumset/ob_enum_set_meta.h"
#include "share/rc/ob_tenant_base.h"
namespace oceanbase
{
using namespace common;
using namespace share;
using namespace transaction;
namespace sql
{
// implement of subschema mapping
// Add New de/serialize functions for schema value when new subschema types are added.
// Signature is identify of subschema value, using for reverse search of subschema id
// for sql udt, signature is original udt id
#define DEF_SUBSCHEMA_ENTRY(SUBSCHEMATYPE, CLZ) \
{ \
subschema_value_serialize<SUBSCHEMATYPE, CLZ>, \
subschema_value_deserialize<SUBSCHEMATYPE, CLZ>, \
subschema_value_serialize_size<SUBSCHEMATYPE, CLZ>, \
subschema_value_get_signature<SUBSCHEMATYPE, CLZ>, \
subschema_value_deep_copy<SUBSCHEMATYPE, CLZ>, \
subschema_value_init<SUBSCHEMATYPE, CLZ>, \
}
template<ObSubSchemaType TYPE, typename CLZ>
int subschema_value_serialize(void *value, char* buf, const int64_t buf_len, int64_t& pos)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(value)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null sql subschema value for serialize", K(ret), K(TYPE));
} else {
const CLZ *subschema_value = reinterpret_cast<CLZ *>(value);
if (OB_FAIL(subschema_value->serialize(buf, buf_len, pos))) {
LOG_WARN("failed to do sql subschema value serialize", K(ret), K(*subschema_value));
}
}
return ret;
}
template<ObSubSchemaType TYPE, typename CLZ>
int subschema_value_deserialize(void *value, const char* buf, const int64_t data_len, int64_t& pos)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(value)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null sql subschema value for deserialize", K(ret), K(TYPE));
} else {
CLZ *subschema_value = reinterpret_cast<CLZ *>(value);
if (OB_FAIL(subschema_value->deserialize(buf, data_len, pos))) {
LOG_WARN("failed to do sql subschema value deserialize", K(ret), KP(buf), K(data_len));
}
}
return ret;
}
template<ObSubSchemaType TYPE, typename CLZ>
int64_t subschema_value_serialize_size(void *value)
{
int ret = OB_SUCCESS;
int64_t len = 0;
if (OB_ISNULL(value)) {
} else {
const CLZ *subschema_value = reinterpret_cast<CLZ *>(value);
len += subschema_value->get_serialize_size();
}
return len;
}
template<ObSubSchemaType TYPE, typename CLZ>
int subschema_value_get_signature(void *value, uint64_t &signature)
{
int ret = OB_SUCCESS;
signature = 0;
if (OB_ISNULL(value)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null subschema value", K(ret), K(TYPE));
} else {
const CLZ *subschema_value = reinterpret_cast<CLZ *>(value);
signature = subschema_value->get_signature();
}
return ret;
}
template<ObSubSchemaType TYPE, typename CLZ>
int subschema_value_deep_copy(const void *src_value, void *&dst_value, ObIAllocator &allocator)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(src_value)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null subschema value for deep copy", K(ret), K(TYPE));
} else {
const CLZ *src_subschema_value = reinterpret_cast<const CLZ *>(src_value);
CLZ* copy_value = NULL;
if (OB_FAIL(src_subschema_value->deep_copy(allocator, copy_value))) {
LOG_WARN("failed to deep copy subschema value", K(ret), K(TYPE));
} else if (OB_ISNULL(copy_value)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("deep copy subschema value result is null", K(ret), K(TYPE));
} else {
dst_value = static_cast<void *>(copy_value);
}
}
return ret;
}
template<ObSubSchemaType TYPE, typename CLZ>
int subschema_value_init(void *&value, ObIAllocator &allocator)
{
int ret = OB_SUCCESS;
void *mem = value;
if (OB_NOT_NULL(mem)) {
ret = OB_INIT_TWICE;
LOG_WARN("value is not null", K(ret), KP(value));
} else if (OB_ISNULL(mem = allocator.alloc(sizeof(CLZ)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to alloc value", K(ret), K(TYPE));
} else {
CLZ *meta = new(mem)CLZ(&allocator);
value = meta;
}
return ret;
}
ObSubSchemaFuncs SUBSCHEMA_FUNCS[OB_SUBSCHEMA_MAX_TYPE] =
{
DEF_SUBSCHEMA_ENTRY(OB_SUBSCHEMA_UDT_TYPE, ObSqlUDTMeta),
DEF_SUBSCHEMA_ENTRY(OB_SUBSCHEMA_ENUM_SET_TYPE, ObEnumSetMeta),
DEF_SUBSCHEMA_ENTRY(OB_SUBSCHEMA_COLLECTION_TYPE, ObSqlCollectionInfo),
};
int ObSubSchemaValue::deep_copy_value(const void *src_value, ObIAllocator &allocator)
{
int ret = OB_SUCCESS;
if (!is_valid_type(type_)) {
// do nothing
} else if (OB_ISNULL(src_value)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("null value for deep copy subschema value", K(ret));
} else if (OB_FAIL(SUBSCHEMA_FUNCS[type_].deep_copy(src_value, value_, allocator))) {
LOG_WARN("failed deep copy subschema value", K(ret), K(*this), KP(src_value));
}
return ret;
}
// Implementation of de/serialize of ObSubschemaValue
OB_DEF_SERIALIZE(ObSubSchemaValue)
{
int ret = OB_SUCCESS;
LST_DO_CODE(OB_UNIS_ENCODE,
type_,
signature_);
if (OB_FAIL(ret)) {
LOG_WARN("fail to serialize subschema type info", K(ret), K(type_), K(signature_));
} else if (is_valid_type(type_) &&
OB_FAIL(SUBSCHEMA_FUNCS[type_].value_serialize(value_, buf, buf_len, pos))) {
LOG_WARN("fail to serialize subschema data", K(ret), K(type_), K(signature_));
}
return ret;
}
OB_DEF_DESERIALIZE(ObSubSchemaValue)
{
int ret = OB_SUCCESS;
LST_DO_CODE(OB_UNIS_DECODE,
type_,
signature_);
if (OB_FAIL(ret)) {
LOG_WARN("fail to deserialize subschema type info", K(ret), K(type_), K(signature_));
} else if (OB_ISNULL(allocator_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("allocator is null", K(ret), K(type_), K(signature_));
} else if (is_valid_type(type_)) {
ObIAllocator *alloc = allocator_;
void *value_meta = NULL;
if (OB_FAIL(SUBSCHEMA_FUNCS[type_].init(value_meta, *alloc))) {
LOG_WARN("fail to init value", K(ret));
} else if (OB_FAIL(SUBSCHEMA_FUNCS[type_].value_deserialize(value_meta, buf, data_len, pos))) {
LOG_WARN("fail to deserialize subschema data", K(ret), K(type_), K(signature_));
} else {
value_ = value_meta;
}
}
return ret;
}
// serialize size cannot return error code
OB_DEF_SERIALIZE_SIZE(ObSubSchemaValue)
{
int64_t len = 0;
LST_DO_CODE(OB_UNIS_ADD_LEN,
type_,
signature_);
if (is_valid_type(type_)) {
len += SUBSCHEMA_FUNCS[type_].get_value_serialize_size(value_);
}
return len;
}
// Implementation of de/serialize of ObSubschemaValue of ObSubSchemaCtx
OB_DEF_SERIALIZE(ObSubSchemaCtx)
{
int ret = OB_SUCCESS;
if (!is_inited_ || subschema_array_.empty()) { // do nothing
} else { // subschema count more then zero
const uint32_t subschema_count = subschema_array_.count();
OB_UNIS_ENCODE(subschema_count);
OB_UNIS_ENCODE(used_subschema_id_);
if (OB_FAIL(ret)) {
LOG_WARN("fail to serialize subschema ctx", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < subschema_array_.count(); ++i) {
if (OB_LIKELY(subschema_array_.at(i).is_valid())) {
OB_UNIS_ENCODE(i);
OB_UNIS_ENCODE(subschema_array_.at(i));
}
}
}
}
return ret;
}
OB_DEF_DESERIALIZE(ObSubSchemaCtx)
{
int ret = OB_SUCCESS;
uint32_t subschema_count = 0;
OB_UNIS_DECODE(subschema_count);
if (OB_FAIL(ret)) {
} else if (subschema_count > 0) {
if (!is_inited_ && OB_FAIL(init())) {
LOG_WARN("fail to init subschema ctx", K(ret));
} else {
OB_UNIS_DECODE(used_subschema_id_);
if (OB_FAIL(ret)) {
LOG_WARN("fail to deserialize subschema ctx", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < subschema_count; i++) {
uint64_t subschema_id = 0;
ObSubSchemaValue value;
value.allocator_ = &allocator_;
OB_UNIS_DECODE(subschema_id);
OB_UNIS_DECODE(value);
if (OB_FAIL(ret)) { // copy value from buffer to local memory
} else if (OB_FAIL(set_subschema(subschema_id, value))) {
LOG_WARN("fail to set subschema", K(ret), K(subschema_id), K(value));
}
}
}
}
}
return ret;
}
// serialize size cannot return error code
OB_DEF_SERIALIZE_SIZE(ObSubSchemaCtx)
{
int64_t len = 0;
if (!is_inited_ || subschema_array_.empty()) { // do nothing
} else { // subschema count more then zero
uint32_t subschema_count = subschema_array_.count();
OB_UNIS_ADD_LEN(subschema_count);
OB_UNIS_ADD_LEN(used_subschema_id_);
for (int64_t i = 0; i < subschema_array_.count(); ++i) {
if (OB_LIKELY(subschema_array_.at(i).is_valid())) {
OB_UNIS_ADD_LEN(i);
OB_UNIS_ADD_LEN(subschema_array_.at(i));
}
}
}
return len;
}
int ObSubSchemaCtx::assgin(const ObSubSchemaCtx &other)
{
int ret = OB_SUCCESS;
if (!other.is_inited() || other.get_subschema_count() == 0) {
// no subschema, do nothing
} else {
if (is_inited() && get_subschema_count() > 0) {
reset();
LOG_DEBUG("subschema context reset due to assign other", K(*this), K(lbt()));
}
if (!is_inited() && OB_FAIL(init())) {
LOG_WARN("fail to init subschema ctx", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < other.get_subschema_array().count(); ++i) {
uint64_t subschema_id = i;
const ObSubSchemaValue src = other.get_subschema_array().at(subschema_id);
ObSubSchemaValue dst = src;
if (OB_FAIL(dst.deep_copy_value(src.value_, allocator_))) {
LOG_WARN("deep copy value failed", K(ret), K(i), K(dst));
} else if (OB_FAIL(set_subschema(i, dst))) {
LOG_WARN("fail to set subschema", K(ret), K(i), K(dst));
}
}
used_subschema_id_ = other.used_subschema_id_;
}
}
return ret;
}
int ObSubSchemaCtx::init()
{
int ret = OB_SUCCESS;
if (is_inited_) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("sub schema ctx already inited", K(ret), K(*this));
} else {
uint64_t tenant_id = MTL_ID();
if (tenant_id == OB_INVALID_TENANT_ID) {
tenant_id = OB_SERVER_TENANT_ID;
}
if (OB_FAIL(subschema_reverse_map_.create(SUBSCHEMA_BUCKET_NUM,
"SubSchemaRev",
"SubSchemaRev",
tenant_id))) {
LOG_WARN("fail to create subschema reverse map", K(ret));
} else if (OB_FAIL(enum_set_meta_reverse_map_.create(SUBSCHEMA_BUCKET_NUM,
"SubSchemaRev",
"SubSchemaRev",
tenant_id))) {
LOG_WARN("fail to create enum_set meta reverse map", K(ret));
} else {
subschema_array_.set_attr(ObMemAttr(MTL_ID(), "SubSchemaHash"));
is_inited_ = true;
used_subschema_id_ = MAX_NON_RESERVED_SUBSCHEMA_ID;
}
}
return ret;
}
void ObSubSchemaCtx::reset() {
// content in subschema value is alloc from plan object allocator? need a new allocator?
subschema_array_.destroy();
subschema_reverse_map_.destroy();
enum_set_meta_reverse_map_.destroy();
if (is_inited_) {
is_inited_ = false;
used_subschema_id_ = MAX_NON_RESERVED_SUBSCHEMA_ID;
reserved_ = 0;
fields_ = NULL;
LOG_DEBUG("subschema ctx reset", KP(this), K(lbt()));
}
}
uint32_t ObSubSchemaCtx::get_subschema_count() const
{
uint32_t subschema_count = 0;
if (!is_inited_) {
} else {
subschema_count = subschema_array_.count();
}
return subschema_count;
}
int ObSubSchemaCtx::get_new_subschema_id(uint16_t &subschema_id)
{
int ret = OB_SUCCESS;
subschema_id = used_subschema_id_++;
if (used_subschema_id_ == UINT16_MAX) {
ret = OB_ERR_UNEXPECTED;
SQL_ENG_LOG(WARN, "more then 64K different subschema", K(ret), K(subschema_id), K(lbt()));
} else {
SQL_ENG_LOG(INFO, "new subschema id", KP(this), K(subschema_id), K(lbt()));
}
return ret;
}
int ObSubSchemaCtx::get_subschema_id_from_fields(uint64_t udt_id, uint16_t &subschema_id)
{
int ret = OB_SUCCESS;
subschema_id = ObInvalidSqlType;
bool is_found = false;
if (OB_NOT_NULL(fields_)) {
for (uint32_t i = 0; is_found == false && OB_SUCC(ret) && i < fields_->count(); i++) {
if ((fields_->at(i).type_.is_collection_sql_type())
&& fields_->at(i).accuracy_.get_accuracy() == udt_id) {
subschema_id = fields_->at(i).type_.get_udt_subschema_id();
is_found = true;
}
}
}
return ret;
}
int ObSubSchemaCtx::ensure_array_capacity(const uint16_t count)
{
int ret = common::OB_SUCCESS;
if (OB_UNLIKELY(count >= subschema_array_.get_capacity()) &&
OB_FAIL(subschema_array_.reserve(next_pow2(count)))) {
LOG_WARN("fail to reserve array capacity", K(ret), K(count), K_(subschema_array));
} else if (OB_FAIL(subschema_array_.prepare_allocate(count))) {
LOG_WARN("fail to prepare allocate array", K(ret), K(count), K_(subschema_array));
}
return ret;
}
int ObSubSchemaCtx::set_subschema(uint16_t subschema_id, ObSubSchemaValue &value)
{
int ret = OB_SUCCESS;
uint64_t key = subschema_id;
ObSubSchemaValue tmp_value;
ObSubSchemaReverseKey rev_key(value.type_, value.signature_);
if (OB_FAIL(get_subschema(key, tmp_value))) {
if (OB_HASH_NOT_EXIST != ret) {
LOG_WARN("failed to get subschema", K(ret), K(key), K(tmp_value), K(value));
} else if (value.type_ == ObSubSchemaType::OB_SUBSCHEMA_COLLECTION_TYPE) {
ObSqlCollectionInfo *meta_info = static_cast<ObSqlCollectionInfo *>(value.value_);
rev_key.str_signature_ = meta_info->get_def_string();
}
if (OB_HASH_NOT_EXIST == ret) {
// not exist
ret = OB_SUCCESS;
LOG_DEBUG("add new subschema", K(ret), K(subschema_id), K(value), K(subschema_array_.count()));
if (OB_FAIL(ensure_array_capacity(subschema_id + 1))) {
LOG_WARN("fail to ensure array capacity", K(ret));
} else if (FALSE_IT(subschema_array_.at(subschema_id) = value)) {
} else if (OB_FAIL(subschema_reverse_map_.set_refactored(rev_key, key))) {
if (OB_HASH_EXIST == ret) {
ret = OB_SUCCESS;
} else {
LOG_WARN("set subschema map failed", K(ret), K(rev_key));
subschema_array_.at(subschema_id).reset();
}
}
if (OB_SUCC(ret) && value.type_ == OB_SUBSCHEMA_ENUM_SET_TYPE) {
const ObEnumSetMeta* enumset_meta = reinterpret_cast<const ObEnumSetMeta*>(value.value_);
ObEnumSetMetaReverseKey meta_rev_key(value.type_, enumset_meta);
if (OB_FAIL(enum_set_meta_reverse_map_.set_refactored(meta_rev_key, key))) {
if (OB_HASH_EXIST == ret) {
ret = OB_SUCCESS;
} else {
LOG_WARN("set subschema map failed", K(ret), K(rev_key));
subschema_array_.at(subschema_id).reset();
subschema_reverse_map_.erase_refactored(rev_key);
}
}
}
}
} else {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("subschema id already exist", KP(this), K(ret), K(subschema_id), K(value));
}
return ret;
}
int ObSubSchemaCtx::get_subschema(uint16_t subschema_id, ObSubSchemaValue &value) const
{
int ret = OB_SUCCESS;
if (OB_LIKELY(subschema_id < subschema_array_.count() &&
subschema_array_.at(subschema_id).is_valid())) {
value = subschema_array_.at(subschema_id);
} else {
ret = OB_HASH_NOT_EXIST;
}
return ret;
}
int ObSubSchemaCtx::get_subschema_id(uint64_t value_signature,
ObSubSchemaType type,
uint16_t &subschema_id) const
{
ObSubSchemaReverseKey rev_key(type, value_signature);
uint64_t value = ObMaxSystemUDTSqlType; // init invalid subschema value
int ret = subschema_reverse_map_.get_refactored(rev_key, value);
subschema_id = value;
return ret;
}
int ObSubSchemaCtx::get_subschema_id_by_typedef(const ObString &type_def,
uint16_t &subschema_id)
{
int ret = OB_SUCCESS;
ObSubSchemaReverseKey rev_key(OB_SUBSCHEMA_COLLECTION_TYPE, type_def);
uint64_t tmp_subid = ObMaxSystemUDTSqlType;
if (OB_FAIL(subschema_reverse_map_.get_refactored(rev_key, tmp_subid))) {
if (OB_HASH_NOT_EXIST != ret) {
LOG_WARN("failed to get subschemaid from reverse map", K(ret));
} else {
ObSqlCollectionInfo *buf = NULL;
uint16_t new_tmp_id;
char *name_def = NULL;
// construnct collection meta
if (OB_ISNULL(buf = OB_NEWx(ObSqlCollectionInfo, &allocator_, allocator_))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to create ObSqlCollectionInfo buffer", K(ret));
} else if (OB_FAIL(get_new_subschema_id(new_tmp_id))) {
LOG_WARN("fail to get new subschema id", K(ret));
} else if (OB_ISNULL(name_def = static_cast<char *>(allocator_.alloc(type_def.length())))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to create ObSqlCollectionInfo buffer", K(ret));
} else {
tmp_subid = new_tmp_id;
ObString type_info;
type_info.assign_buffer(name_def, type_def.length());
type_info.write(type_def.ptr(), type_def.length());
buf->set_name(type_info);
if (OB_FAIL(buf->parse_type_info())) {
LOG_WARN("fail to parse ObSqlCollectionInfo", K(ret));
} else {
ObSubSchemaValue value;
value.type_ = OB_SUBSCHEMA_COLLECTION_TYPE;
value.value_ = static_cast<void *>(buf);
uint64_t key = tmp_subid;
rev_key.str_signature_.assign_ptr(type_info.ptr(), type_info.length());
if (OB_FAIL(ensure_array_capacity(key + 1))) {
LOG_WARN("fail to ensure array capacity", K(ret));
} else if (FALSE_IT(subschema_array_.at(key) = value)) {
} else if (OB_FAIL(subschema_reverse_map_.set_refactored(rev_key, key))) {
LOG_WARN("set subschema map failed", K(ret), K(rev_key), K(key));
subschema_array_.at(key).reset();
}
}
}
}
}
if (OB_SUCC(ret)) {
subschema_id = tmp_subid;
}
return ret;
}
int ObSubSchemaCtx::get_subschema_id_by_typedef(const ObString &type_def,
uint16_t &subschema_id) const
{
int ret = OB_SUCCESS;
ObSubSchemaReverseKey rev_key(OB_SUBSCHEMA_COLLECTION_TYPE, type_def);
uint64_t tmp_subid = ObMaxSystemUDTSqlType;
if (OB_FAIL(subschema_reverse_map_.get_refactored(rev_key, tmp_subid))) {
LOG_WARN("failed to get subschemaid from reverse map", K(ret));
} else {
subschema_id = tmp_subid;
}
return ret;
}
int ObSubSchemaCtx::get_subschema_id_by_typedef(ObNestedType coll_type,
const ObDataType &elem_type,
uint16_t &subschema_id)
{
int ret = OB_SUCCESS;
const int MAX_LEN = 256;
char tmp[MAX_LEN] = {0};
if (OB_FAIL(ObArrayUtil::get_type_name(coll_type, elem_type, tmp, MAX_LEN))) {
LOG_WARN("failed to convert len to string", K(ret));
} else {
ObString tmp_def(strlen(tmp), tmp);
if (OB_FAIL(get_subschema_id_by_typedef(tmp_def, subschema_id))) {
LOG_WARN("failed to get subschemaid by typedef", K(ret));
}
}
return ret;
}
int ObSubSchemaCtx::get_subschema_id_by_typedef(ObNestedType coll_type,
const ObDataType &elem_type,
uint16_t &subschema_id) const
{
int ret = OB_SUCCESS;
const int MAX_LEN = 256;
int64_t pos = 0;
char tmp[MAX_LEN] = {0};
if (OB_FAIL(ObArrayUtil::get_type_name(coll_type, elem_type, tmp, MAX_LEN))) {
LOG_WARN("failed to convert len to string", K(ret));
} else {
ObString tmp_def(strlen(tmp), tmp);
if (OB_FAIL(get_subschema_id_by_typedef(tmp_def, subschema_id))) {
LOG_WARN("failed to get subschemaid by typedef", K(ret));
}
}
return ret;
}
int ObSubSchemaCtx::get_subschema_id(const ObSubSchemaType type,
const ObEnumSetMeta &meta,
uint16_t &subschema_id) const
{
ObEnumSetMetaReverseKey rev_key(type, &meta);
uint64_t value = ObMaxSystemUDTSqlType; // init invalid subschema value
int ret = enum_set_meta_reverse_map_.get_refactored(rev_key, value);
subschema_id = value;
return ret;
}
} //sql
} //oceanbase