ob_object.h 107.4 KB
Newer Older
O
oceanbase-admin 已提交
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
/**
 * 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.
 */

#ifndef OCEANBASE_COMMON_OB_OBJECT_H_
#define OCEANBASE_COMMON_OB_OBJECT_H_

#include "lib/ob_define.h"
#include "lib/string/ob_string.h"
#include "common/ob_action_flag.h"
#include "common/object/ob_obj_type.h"
#include "common/ob_accuracy.h"
#include "lib/checksum/ob_crc64.h"
#include "lib/number/ob_number_v2.h"
#include "lib/charset/ob_charset.h"
#include "lib/timezone/ob_timezone_info.h"
#include "lib/hash/ob_hashutils.h"
#include "lib/hash_func/ob_hash_func.h"
#include "lib/charset/ob_dtoa.h"
#include "lib/rowid/ob_urowid.h"

namespace oceanbase {
namespace tests {
namespace common {
class ObjTest;
class ObSqlString;
}  // namespace common
}  // namespace tests
namespace common {

struct ObCompareCtx;
enum ObCmpNullPos { NULL_LAST = 1, NULL_FIRST, MAX_NULL_POS };

inline ObCmpNullPos default_null_pos()
{
  return lib::is_oracle_mode() ? NULL_LAST : NULL_FIRST;
}

struct ObEnumSetInnerValue {
  OB_UNIS_VERSION_V(1);

G
gm 已提交
50
public:
O
oceanbase-admin 已提交
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
  ObEnumSetInnerValue() : numberic_value_(0), string_value_()
  {}
  ObEnumSetInnerValue(uint64_t numberic_value, common::ObString& string_value)
      : numberic_value_(numberic_value), string_value_(string_value)
  {}
  virtual ~ObEnumSetInnerValue()
  {}

  TO_STRING_KV(K_(numberic_value), K_(string_value));
  uint64_t numberic_value_;
  common::ObString string_value_;
};

struct ObLobScale {
  static const uint8_t LOB_SCALE_MASK = 0xF;
  enum StorageType { STORE_IN_ROW = 0, STORE_OUT_ROW };
  union {
    int8_t scale_;
    struct {
      uint8_t reserve_ : 4;
      uint8_t type_ : 4;
    };
  };
  ObLobScale() : scale_(0)
  {}
  ObLobScale(const ObScale scale) : scale_(static_cast<const int8_t>(scale))
  {
    reserve_ = 0;
  }
  OB_INLINE void reset()
  {
    scale_ = 0;
  }
  OB_INLINE bool is_valid()
  {
    return STORE_IN_ROW == type_ || STORE_OUT_ROW == type_;
  }
  OB_INLINE void set_in_row()
  {
    reserve_ = 0;
    type_ = STORE_IN_ROW;
  }
  OB_INLINE void set_out_row()
  {
    reserve_ = 0;
    type_ = STORE_OUT_ROW;
  }
  OB_INLINE bool is_in_row() const
  {
    return type_ == STORE_IN_ROW;
  }
  OB_INLINE bool is_out_row() const
  {
    return type_ == STORE_OUT_ROW;
  }
  OB_INLINE ObScale get_scale() const
  {
    return static_cast<ObScale>(scale_);
  }
  TO_STRING_KV(K_(scale));
};

class ObObjMeta {
G
gm 已提交
114
public:
O
oceanbase-admin 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  ObObjMeta() : type_(ObNullType), cs_level_(CS_LEVEL_INVALID), cs_type_(CS_TYPE_INVALID), scale_(-1)
  {}

  OB_INLINE bool operator==(const ObObjMeta& other) const
  {
    return (type_ == other.type_ && cs_level_ == other.cs_level_ && cs_type_ == other.cs_type_);
  }
  OB_INLINE bool operator!=(const ObObjMeta& other) const
  {
    return !this->operator==(other);
  }
  // this method is inefficient, you'd better use set_tinyint() etc. instead
  OB_INLINE void set_type(const ObObjType& type)
  {
    type_ = static_cast<uint8_t>(type);
    if (ObNullType == type_) {
      set_collation_level(CS_LEVEL_IGNORABLE);
      set_collation_type(CS_TYPE_BINARY);
    } else if (ObUnknownType == type_ || ObExtendType == type_) {
      set_collation_level(CS_LEVEL_INVALID);
      set_collation_type(CS_TYPE_INVALID);
    } else if (ObHexStringType == type_) {
      set_collation_type(CS_TYPE_BINARY);
X
xj0 已提交
138 139 140 141 142
    } else if (!ob_is_string_type(static_cast<ObObjType>(type_)) && 
               !ob_is_lob_locator(static_cast<ObObjType>(type_)) &&
               !ob_is_raw(static_cast<ObObjType>(type_)) && 
               !ob_is_enum_or_set_type(static_cast<ObObjType>(type_)) && 
               !ob_is_json(static_cast<ObObjType>(type_))) {
O
oceanbase-admin 已提交
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
      set_collation_level(CS_LEVEL_NUMERIC);
      set_collation_type(CS_TYPE_BINARY);
    }
  }
  OB_INLINE void set_type_simple(const ObObjType& type)
  {
    type_ = static_cast<uint8_t>(type);
  }
  // in greatest case need manually set numeric collation,
  // e.g greatest(2, 'x') => type=varchar,collation=binary,cmp_collation=utf8
  OB_INLINE void set_numeric_collation()
  {
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_meta(const ObObjMeta& meta)
  {
    type_ = meta.type_;
    cs_level_ = meta.cs_level_;
    cs_type_ = meta.cs_type_;
    scale_ = meta.scale_;
  }
  OB_INLINE void reset()
  {
    type_ = ObNullType;
    cs_level_ = CS_LEVEL_INVALID;
    cs_type_ = CS_TYPE_INVALID;
    scale_ = -1;
  }

  OB_INLINE ObObjType get_type() const
  {
    return static_cast<ObObjType>(type_);
  }
  OB_INLINE ObObjOType get_oracle_type() const
  {
    return ob_obj_type_to_oracle_type(static_cast<ObObjType>(type_));
  }
  OB_INLINE const ObObjMeta& get_obj_meta() const
  {
    return *this;
  }
  OB_INLINE ObObjTypeClass get_type_class() const
  {
    return ob_obj_type_class(get_type());
  }
  OB_INLINE ObObjTypeClass get_type_class_for_oracle() const
  {
    return ob_oracle_type_class(get_type());
  }

  OB_INLINE void set_null()
  {
    type_ = static_cast<uint8_t>(ObNullType);
    set_collation_level(CS_LEVEL_IGNORABLE);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_tinyint()
  {
    type_ = static_cast<uint8_t>(ObTinyIntType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_smallint()
  {
    type_ = static_cast<uint8_t>(ObSmallIntType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_mediumint()
  {
    type_ = static_cast<uint8_t>(ObMediumIntType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_int32()
  {
    type_ = static_cast<uint8_t>(ObInt32Type);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_int()
  {
    type_ = static_cast<uint8_t>(ObIntType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_utinyint()
  {
    type_ = static_cast<uint8_t>(ObUTinyIntType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_usmallint()
  {
    type_ = static_cast<uint8_t>(ObUSmallIntType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_umediumint()
  {
    type_ = static_cast<uint8_t>(ObUMediumIntType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_uint32()
  {
    type_ = static_cast<uint8_t>(ObUInt32Type);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_uint64()
  {
    type_ = static_cast<uint8_t>(ObUInt64Type);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_float()
  {
    type_ = static_cast<uint8_t>(ObFloatType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_double()
  {
    type_ = static_cast<uint8_t>(ObDoubleType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_ufloat()
  {
    type_ = static_cast<uint8_t>(ObUFloatType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_udouble()
  {
    type_ = static_cast<uint8_t>(ObUDoubleType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_number()
  {
    type_ = static_cast<uint8_t>(ObNumberType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_unumber()
  {
    type_ = static_cast<uint8_t>(ObUNumberType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_number_float()
  {
    type_ = static_cast<uint8_t>(ObNumberFloatType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_datetime()
  {
    type_ = static_cast<uint8_t>(ObDateTimeType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_timestamp()
  {
    type_ = static_cast<uint8_t>(ObTimestampType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_year()
  {
    type_ = static_cast<uint8_t>(ObYearType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_date()
  {
    type_ = static_cast<uint8_t>(ObDateType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_time()
  {
    type_ = static_cast<uint8_t>(ObTimeType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_varchar()
  {
    type_ = static_cast<uint8_t>(ObVarcharType);
  }
  OB_INLINE void set_char()
  {
    type_ = static_cast<uint8_t>(ObCharType);
  }
  OB_INLINE void set_varbinary()
  {
    type_ = static_cast<uint8_t>(ObVarcharType);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_binary()
  {
    type_ = static_cast<uint8_t>(ObCharType);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_hex_string()
  {
    type_ = static_cast<uint8_t>(ObHexStringType);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_raw()
  {
    type_ = static_cast<uint8_t>(ObRawType);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_ext()
  {
    type_ = static_cast<uint8_t>(ObExtendType);
    set_collation_level(CS_LEVEL_INVALID);
    set_collation_type(CS_TYPE_INVALID);
  }
  OB_INLINE void set_unknown()
  {
    type_ = static_cast<uint8_t>(ObUnknownType);
    set_collation_level(CS_LEVEL_INVALID);
    set_collation_type(CS_TYPE_INVALID);
    set_extend_type(0);
  }
  OB_INLINE void set_bit()
  {
    type_ = static_cast<uint8_t>(ObBitType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  // TODO():collation_level, collation_type
  OB_INLINE void set_enum()
  {
    type_ = static_cast<uint8_t>(ObEnumType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_set()
  {
    type_ = static_cast<uint8_t>(ObSetType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_enum_inner()
  {
    type_ = static_cast<uint8_t>(ObEnumInnerType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_set_inner()
  {
    type_ = static_cast<uint8_t>(ObSetInnerType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }

  OB_INLINE void set_clob()
  {
    type_ = static_cast<uint8_t>(ObLongTextType);
    lob_scale_.set_in_row();
    set_default_collation_type();
  }
  OB_INLINE void set_blob()
  {
    type_ = static_cast<uint8_t>(ObLongTextType);
    lob_scale_.set_in_row();
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_lob_inrow()
  {
    lob_scale_.set_in_row();
  }
  OB_INLINE void set_lob_outrow()
  {
    lob_scale_.set_out_row();
  }
X
xj0 已提交
425 426 427 428 429 430 431
  OB_INLINE void set_json()
  {
    type_ = static_cast<uint8_t>(ObJsonType);
    lob_scale_.set_in_row();
    set_collation_level(CS_LEVEL_IMPLICIT);
    set_collation_type(CS_TYPE_UTF8MB4_BIN);
  }
O
oceanbase-admin 已提交
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 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
  OB_INLINE void set_otimestamp_type(const ObObjType type)
  {
    type_ = static_cast<uint8_t>(type);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_timestamp_tz()
  {
    set_otimestamp_type(ObTimestampTZType);
  }
  OB_INLINE void set_timestamp_ltz()
  {
    set_otimestamp_type(ObTimestampLTZType);
  }
  OB_INLINE void set_timestamp_nano()
  {
    set_otimestamp_type(ObTimestampNanoType);
  }
  OB_INLINE void set_interval_ym()
  {
    type_ = static_cast<uint8_t>(ObIntervalYMType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_interval_ds()
  {
    type_ = static_cast<uint8_t>(ObIntervalDSType);
    set_collation_level(CS_LEVEL_NUMERIC);
    set_collation_type(CS_TYPE_BINARY);
  }
  OB_INLINE void set_nvarchar2()
  {
    type_ = static_cast<uint8_t>(ObNVarchar2Type);
  }
  OB_INLINE void set_nchar()
  {
    type_ = static_cast<uint8_t>(ObNCharType);
  }
  OB_INLINE void set_urowid()
  {
    type_ = static_cast<uint8_t>(ObURowIDType);
    set_collation_level(CS_LEVEL_INVALID);
    set_collation_type(CS_TYPE_BINARY);
  }

  OB_INLINE void set_clob_locator()
  {
    type_ = static_cast<uint8_t>(ObLobType);
    set_default_collation_type();
  }
  OB_INLINE void set_blob_locator()
  {
    type_ = static_cast<uint8_t>(ObLobType);
    set_collation_type(CS_TYPE_BINARY);
  }

  OB_INLINE bool is_valid() const
  {
    return ob_is_valid_obj_type(static_cast<ObObjType>(type_));
  }
  OB_INLINE bool is_invalid() const
  {
    return !ob_is_valid_obj_type(static_cast<ObObjType>(type_));
  }

  OB_INLINE bool is_null() const
  {
    return type_ == static_cast<uint8_t>(ObNullType);
  }
  OB_INLINE bool is_tinyint() const
  {
    return type_ == static_cast<uint8_t>(ObTinyIntType);
  }
  OB_INLINE bool is_smallint() const
  {
    return type_ == static_cast<uint8_t>(ObSmallIntType);
  }
  OB_INLINE bool is_mediumint() const
  {
    return type_ == static_cast<uint8_t>(ObMediumIntType);
  }
  OB_INLINE bool is_int32() const
  {
    return type_ == static_cast<uint8_t>(ObInt32Type);
  }
  OB_INLINE bool is_int() const
  {
    return type_ == static_cast<uint8_t>(ObIntType);
  }
  OB_INLINE bool is_utinyint() const
  {
    return type_ == static_cast<uint8_t>(ObUTinyIntType);
  }
  OB_INLINE bool is_usmallint() const
  {
    return type_ == static_cast<uint8_t>(ObUSmallIntType);
  }
  OB_INLINE bool is_umediumint() const
  {
    return type_ == static_cast<uint8_t>(ObUMediumIntType);
  }
  OB_INLINE bool is_uint32() const
  {
    return type_ == static_cast<uint8_t>(ObUInt32Type);
  }
  OB_INLINE bool is_uint64() const
  {
    return type_ == static_cast<uint8_t>(ObUInt64Type);
  }
  OB_INLINE bool is_float() const
  {
    return type_ == static_cast<uint8_t>(ObFloatType);
  }
  OB_INLINE bool is_double() const
  {
    return type_ == static_cast<uint8_t>(ObDoubleType);
  }
  OB_INLINE bool is_ufloat() const
  {
    return type_ == static_cast<uint8_t>(ObUFloatType);
  }
  OB_INLINE bool is_udouble() const
  {
    return type_ == static_cast<uint8_t>(ObUDoubleType);
  }
  OB_INLINE bool is_number() const
  {
    return type_ == static_cast<uint8_t>(ObNumberType);
  }
  OB_INLINE bool is_unumber() const
  {
    return type_ == static_cast<uint8_t>(ObUNumberType);
  }
  OB_INLINE bool is_number_float() const
  {
    return type_ == static_cast<uint8_t>(ObNumberFloatType);
  }
  OB_INLINE bool is_datetime() const
  {
    return type_ == static_cast<uint8_t>(ObDateTimeType);
  }
  OB_INLINE bool is_timestamp() const
  {
    return type_ == static_cast<uint8_t>(ObTimestampType);
  }
  OB_INLINE bool is_year() const
  {
    return type_ == static_cast<uint8_t>(ObYearType);
  }
  OB_INLINE bool is_date() const
  {
    return type_ == static_cast<uint8_t>(ObDateType);
  }
  OB_INLINE bool is_time() const
  {
    return type_ == static_cast<uint8_t>(ObTimeType);
  }
  OB_INLINE bool is_timestamp_tz() const
  {
    return type_ == static_cast<uint8_t>(ObTimestampTZType);
  }
  OB_INLINE bool is_timestamp_ltz() const
  {
    return type_ == static_cast<uint8_t>(ObTimestampLTZType);
  }
  OB_INLINE bool is_timestamp_nano() const
  {
    return type_ == static_cast<uint8_t>(ObTimestampNanoType);
  }
  OB_INLINE bool is_interval_ym() const
  {
    return type_ == static_cast<uint8_t>(ObIntervalYMType);
  }
  OB_INLINE bool is_interval_ds() const
  {
    return type_ == static_cast<uint8_t>(ObIntervalDSType);
  }
  OB_INLINE bool is_nvarchar2() const
  {
    return type_ == static_cast<uint8_t>(ObNVarchar2Type);
  }
  OB_INLINE bool is_nchar() const
  {
    return type_ == static_cast<uint8_t>(ObNCharType);
  }
  OB_INLINE bool is_varchar() const
  {
    return ((type_ == static_cast<uint8_t>(ObVarcharType)) && (CS_TYPE_BINARY != cs_type_));
  }
  OB_INLINE bool is_char() const
  {
    return ((type_ == static_cast<uint8_t>(ObCharType)) && (CS_TYPE_BINARY != cs_type_));
  }
  OB_INLINE bool is_varbinary() const
  {
    return (type_ == static_cast<uint8_t>(ObVarcharType) && CS_TYPE_BINARY == cs_type_);
  }
  static bool is_binary(const ObObjType type, const ObCollationType cs_type)
  {
    return (ObCharType == type && CS_TYPE_BINARY == cs_type);
  }
  OB_INLINE bool is_binary() const
  {
    return is_binary(static_cast<ObObjType>(type_), static_cast<ObCollationType>(cs_type_));
  }
  OB_INLINE bool is_cs_collation_free() const
  {
    return cs_type_ == CS_TYPE_UTF8MB4_GENERAL_CI || cs_type_ == CS_TYPE_UTF8MB4_BIN;
  }
  OB_INLINE bool is_hex_string() const
  {
    return type_ == static_cast<uint8_t>(ObHexStringType);
  }
  OB_INLINE bool is_raw() const
  {
    return type_ == static_cast<uint8_t>(ObRawType);
  }
  OB_INLINE bool is_ext() const
  {
    return type_ == static_cast<uint8_t>(ObExtendType);
  }
  OB_INLINE bool is_unknown() const
  {
    return type_ == static_cast<uint8_t>(ObUnknownType);
  }
  OB_INLINE bool is_bit() const
  {
    return type_ == static_cast<uint8_t>(ObBitType);
  }
  OB_INLINE bool is_enum() const
  {
    return type_ == static_cast<uint8_t>(ObEnumType);
  }
  OB_INLINE bool is_set() const
  {
    return type_ == static_cast<uint8_t>(ObSetType);
  }
  OB_INLINE bool is_enum_or_set() const
  {
    return type_ == static_cast<uint8_t>(ObEnumType) || type_ == static_cast<uint8_t>(ObSetType);
  }
  OB_INLINE bool is_text() const
  {
    return (ob_is_text_tc(get_type()) && CS_TYPE_BINARY != cs_type_);
  }
  /*OB_INLINE bool is_oracle_clob() const
  {
    return (lib::is_oracle_mode() && ObLongTextType == get_type() && CS_TYPE_BINARY != cs_type_);
  }*/
  OB_INLINE bool is_clob() const
  {
    return (lib::is_oracle_mode() && ObLongTextType == get_type() && CS_TYPE_BINARY != cs_type_);
  }
  /*OB_INLINE bool is_oracle_blob() const
  {
    return (lib::is_oracle_mode() && ObLongTextType == get_type() && CS_TYPE_BINARY == cs_type_);
  }*/
  OB_INLINE bool is_blob() const
  {
    return (ob_is_text_tc(get_type()) && CS_TYPE_BINARY == cs_type_);
  }
  OB_INLINE bool is_lob() const
  {
    return ob_is_text_tc(get_type());
  }
  OB_INLINE bool is_lob_inrow() const
  {
    return is_lob() && lob_scale_.is_in_row();
  }
  OB_INLINE bool is_lob_outrow() const
  {
    return is_lob() && lob_scale_.is_out_row();
  }
X
xj0 已提交
705 706 707 708 709 710 711 712 713 714 715 716
  OB_INLINE bool is_json() const 
  { 
    return type_ == static_cast<uint8_t>(ObJsonType); 
  }
  OB_INLINE bool is_json_inrow() const 
  { 
    return is_json() && lob_scale_.is_in_row(); 
  }
  OB_INLINE bool is_json_outrow() const 
  { 
    return is_json() && lob_scale_.is_out_row(); 
  }
O
oceanbase-admin 已提交
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
  // combination of above functions.
  OB_INLINE bool is_varbinary_or_binary() const
  {
    return is_varbinary() || is_binary();
  }
  OB_INLINE bool is_varchar_or_char() const
  {
    return is_varchar() || is_char();
  }
  OB_INLINE bool is_nstring() const
  {
    return is_nvarchar2() || is_nchar();
  }
  OB_INLINE bool is_fixed_len_char_type() const
  {
    return is_char() || is_nchar();
  }
  OB_INLINE bool is_varying_len_char_type() const
  {
    return is_varchar() || is_nvarchar2();
  }
  OB_INLINE bool is_character_type() const
  {
    return is_nstring() || is_varchar_or_char();
  }
  OB_INLINE bool is_collation_free_compatible() const
  {
    return is_character_type() && is_cs_collation_free();
  }
  OB_INLINE bool is_numeric_type() const
  {
    return ob_is_numeric_type(get_type());
  }
  OB_INLINE bool is_integer_type() const
  {
    return ob_is_integer_type(get_type());
  }
  OB_INLINE bool is_string_type() const
  {
    return ob_is_string_tc(get_type()) || ob_is_text_tc(get_type());
  }
  OB_INLINE bool is_string_or_lob_locator_type() const
  {
    return ob_is_string_tc(get_type()) || ob_is_text_tc(get_type()) || is_lob_locator();
  }
  OB_INLINE bool is_temporal_type() const
  {
    return ob_is_temporal_type(get_type());
  }
  OB_INLINE bool is_unsigned_integer() const
  {
    return (static_cast<uint8_t>(ObUTinyIntType) <= type_ && static_cast<uint8_t>(ObUInt64Type) >= type_);
  }
  OB_INLINE bool is_enumset_inner_type() const
  {
    return static_cast<uint8_t>(ObEnumInnerType) == type_ || static_cast<uint8_t>(ObSetInnerType) == type_;
  }
  OB_INLINE bool is_otimestamp_type() const
  {
    return ObTimestampTZType <= get_type() && get_type() <= ObTimestampNanoType;
  }
  OB_INLINE bool is_oracle_decimal() const
  {
    return ObNumberType == type_ || ObFloatType == type_ || ObDoubleType == type_;
  }
  OB_INLINE bool is_urowid() const
  {
    return ObURowIDType == type_;
  }
  OB_INLINE bool is_blob_locator() const
  {
    return (ObLobType == type_ && CS_TYPE_BINARY == cs_type_);
  }
  OB_INLINE bool is_clob_locator() const
  {
    return (ObLobType == type_ && CS_TYPE_BINARY != cs_type_);
  }
  OB_INLINE bool is_lob_locator() const
  {
    return ObLobType == type_;
  }

  OB_INLINE bool is_interval_type() const
  {
    return is_interval_ds() || is_interval_ym();
  }
  OB_INLINE bool is_oracle_temporal_type() const
  {
    return is_datetime() || is_otimestamp_type() || is_interval_type();
  }

  OB_INLINE void set_collation_level(ObCollationLevel cs_level)
  {
    cs_level_ = cs_level;
  }
  OB_INLINE void set_collation_type(ObCollationType cs_type)
  {
    cs_type_ = cs_type;
  }
  OB_INLINE void set_default_collation_type()
  {
    set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
  }
  OB_INLINE ObCollationLevel get_collation_level() const
  {
    return static_cast<ObCollationLevel>(cs_level_);
  }
  OB_INLINE ObCollationType get_collation_type() const
  {
    return static_cast<ObCollationType>(cs_type_);
  }
  OB_INLINE ObCharsetType get_charset_type() const
  {
    return ObCharset::charset_type_by_coll(get_collation_type());
  }
  OB_INLINE bool is_collation_invalid() const
  {
    return CS_LEVEL_INVALID == cs_level_ && CS_TYPE_INVALID == cs_type_;
  }
  OB_INLINE void set_collation(const ObObjMeta& other)
  {
    cs_level_ = other.cs_level_;
    cs_type_ = other.cs_type_;
  }
  OB_INLINE void set_scale(const ObScale scale)
  {
    scale_ = static_cast<int8_t>(scale);
  }
  OB_INLINE ObScale get_scale() const
  {
    return static_cast<ObScale>(scale_);
  }
  OB_INLINE void set_extend_type(uint8_t type)
  {
    extend_type_ = type;
  }
  OB_INLINE uint8_t get_extend_type() const
  {
    return extend_type_;
  }

  TO_STRING_KV(N_TYPE, ob_obj_type_str(static_cast<ObObjType>(type_)), N_COLLATION,
      ObCharset::collation_name(get_collation_type()), N_COERCIBILITY,
      ObCharset::collation_level(get_collation_level()));
  NEED_SERIALIZE_AND_DESERIALIZE;

  static uint32_t type_offset_bits()
  {
    return offsetof(ObObjMeta, type_) * 8;
  }
  static uint32_t cs_level_offset_bits()
  {
    return offsetof(ObObjMeta, cs_level_) * 8;
  }
  static uint32_t cs_type_offset_bits()
  {
    return offsetof(ObObjMeta, cs_type_) * 8;
  }
  static uint32_t scale_offset_bits()
  {
    return offsetof(ObObjMeta, scale_) * 8;
  }

G
gm 已提交
880
protected:
O
oceanbase-admin 已提交
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
  uint8_t type_;
  uint8_t cs_level_;  // collation level
  uint8_t cs_type_;   // collation type
  union {
    int8_t scale_;  // scale, bit length for bit type.
    ObLobScale lob_scale_;
    uint8_t extend_type_;
  };
};

struct ObLogicMacroBlockId {
  static const int64_t LOGIC_BLOCK_ID_VERSION = 1;
  ObLogicMacroBlockId() : data_seq_(0), data_version_(0)
  {}
  ObLogicMacroBlockId(const int64_t data_seq, const uint64_t data_version)
      : data_seq_(data_seq), data_version_(data_version)
  {}
  int64_t hash() const;
  bool operator==(const ObLogicMacroBlockId& other) const;
  bool operator!=(const ObLogicMacroBlockId& other) const;
  OB_INLINE bool is_valid() const
  {
    return data_seq_ >= 0;
  }
  TO_STRING_KV(K_(data_seq), K_(data_version));
  int64_t data_seq_;
  uint64_t data_version_;
  OB_UNIS_VERSION(LOGIC_BLOCK_ID_VERSION);
};

struct ObLobIndex {
  static const int64_t LOB_INDEX_VERSION = 1;
  ObLobIndex() : version_(LOB_INDEX_VERSION), reserved_(0), logic_macro_id_(), byte_size_(0), char_size_(0)
  {}
  bool operator==(const ObLobIndex& other) const;
  bool operator!=(const ObLobIndex& other) const;
  TO_STRING_KV(K_(version), K_(reserved), K_(logic_macro_id), K_(byte_size), K_(char_size));
  uint32_t version_;
  uint32_t reserved_;
  ObLogicMacroBlockId logic_macro_id_;
  uint64_t byte_size_;
  uint64_t char_size_;
  OB_UNIS_VERSION(LOB_INDEX_VERSION);
};

struct ObLobData {
  static const int64_t DIRECT_CNT = 48;
  static const int64_t NDIRECT_CNT = 1;
  static const int64_t TOTAL_INDEX_CNT = DIRECT_CNT + NDIRECT_CNT;
  static const int64_t LOB_DATA_VERSION = 1;
  ObLobData() : version_(LOB_DATA_VERSION), idx_cnt_(0), byte_size_(0), char_size_(0)
  {}
  bool operator==(const ObLobData& other) const;
  bool operator!=(const ObLobData& other) const;
  int64_t get_serialize_size() const;
  int serialize(char* buf, const int64_t buf_len, int64_t& pos) const;
  int deserialize(const char* buf, const int64_t buf_len, int64_t& pos);
  TO_STRING_KV(K_(version), K_(byte_size), K_(char_size), K_(idx_cnt), "lob_idx_array",
      common::ObArrayWrap<ObLobIndex>(lob_idx_, idx_cnt_));
  int64_t get_direct_cnt() const
  {
    return DIRECT_CNT;
  }
  OB_INLINE int32_t get_handle_size() const
  {
    return static_cast<int32_t>(offsetof(ObLobData, lob_idx_) + sizeof(ObLobIndex) * idx_cnt_);
  }
  void reset();
  uint32_t version_;
  uint32_t idx_cnt_;
  uint64_t byte_size_;
  uint64_t char_size_;
  ObLobIndex lob_idx_[TOTAL_INDEX_CNT];
};

// We always get/convert/build locator from existing buffer
#define LOB_DEFAULT_FLAGS UINT16_C(0)
#define LOB_COMPAT_MODE_FLAG (INT64_C(1) << 0)  // 1 means old heap table without rowid, fake locator
#define LOB_OPEN_MODE_FLAG (INT64_C(1) << 1)    // 0 means lob_readwrite, 1 means lob_readonly
#define LOB_IS_OPEN_FLAG (INT64_C(1) << 2)      // 0 means is close, 1 means is open

struct ObLobLocator {
  static const uint32_t MAGIC_CODE = 0x4C4F4221;  // LOB!
  static const uint32_t LOB_LOCATOR_VERSION = 1;
  ObLobLocator() = delete;
  ~ObLobLocator() = delete;
  OB_INLINE bool is_valid() const
  {
    return magic_code_ == MAGIC_CODE && version_ == LOB_LOCATOR_VERSION && snapshot_version_ >= 0 &&
           is_valid_id(table_id_) && is_valid_id(column_id_) && option_ == 0 && data_ != nullptr;
  }
  OB_INLINE bool is_fake_locator() const
  {
    return !is_inline_mode();
  }
  int init(const uint64_t table_id, const uint32_t column_id, const int64_t snapshot_version, const uint16_t flags,
      const ObString& rowid, const ObString& payload);
  int init(const ObString& payload);  // init a lob locator with fake rowid/table_id and etc.
  int get_rowid(ObString& rowid) const;
  int get_payload(ObString& payload) const;
  OB_INLINE int64_t get_data_length() const
  {
    return (payload_offset_ + payload_size_);
  }
  OB_INLINE int64_t get_total_size() const
  {
    return offsetof(ObLobLocator, data_) + get_data_length();
  }
  OB_INLINE uint32_t get_payload_length() const
  {
    return payload_size_;
  }
  // TODO to be deleted
  OB_INLINE const char* get_payload_ptr() const
  {
    return &data_[payload_offset_];
  }
  OB_INLINE void add_flag(int64_t flag)
  {
    flags_ |= flag;
  }
  OB_INLINE void del_flag(int64_t flag)
  {
    flags_ &= ~flag;
  }
  OB_INLINE void set_inline_mode()
  {
    del_flag(LOB_COMPAT_MODE_FLAG);
  }
  OB_INLINE void set_compat_mode()
  {
    add_flag(LOB_COMPAT_MODE_FLAG);
  }
  OB_INLINE bool is_inline_mode() const
  {
    return !(flags_ & LOB_COMPAT_MODE_FLAG);
  }
  OB_INLINE void set_readwrite()
  {
    del_flag(LOB_OPEN_MODE_FLAG);
  }
  OB_INLINE void set_readonly()
  {
    add_flag(LOB_OPEN_MODE_FLAG);
  }
  OB_INLINE bool is_readwrite() const
  {
    return !(flags_ & LOB_OPEN_MODE_FLAG);
  }
  OB_INLINE void set_is_close()
  {
    del_flag(LOB_IS_OPEN_FLAG);
  }
  OB_INLINE void set_is_open()
  {
    add_flag(LOB_IS_OPEN_FLAG);
  }
  OB_INLINE bool is_open() const
  {
    return (flags_ & LOB_IS_OPEN_FLAG);
  }

  DECLARE_TO_STRING;

  uint32_t magic_code_;
  uint32_t version_;
  int64_t snapshot_version_;
  uint64_t table_id_;
  uint32_t column_id_;
  uint16_t flags_;
  uint16_t option_;          // storage option: compress/ encrypt / dedup
  uint32_t payload_offset_;  //  == rowid_size; payload = data_ + payload_offset_
  uint32_t payload_size_;
  char data_[0];  // rowid + varchar
};

struct ObObjPrintParams {
  ObObjPrintParams(const ObTimeZoneInfo* tz_info, ObCollationType cs_type)
      : tz_info_(tz_info), cs_type_(cs_type), print_flags_(0)
  {}
  ObObjPrintParams(const ObTimeZoneInfo* tz_info)
      : tz_info_(tz_info), cs_type_(CS_TYPE_UTF8MB4_GENERAL_CI), print_flags_(0)
  {}
  ObObjPrintParams() : tz_info_(NULL), cs_type_(CS_TYPE_UTF8MB4_GENERAL_CI), print_flags_(0)
  {}
  TO_STRING_KV(K_(tz_info), K_(cs_type));
  const ObTimeZoneInfo* tz_info_;
  ObCollationType cs_type_;
  union {
    uint32_t print_flags_;
    struct {
      uint32_t need_cast_expr_ : 1;
      uint32_t is_show_create_view_ : 1;
1074 1075 1076
      uint32_t use_memcpy_ : 1;
      uint32_t skip_escape_ : 1;
      uint32_t reserved_ : 28;
O
oceanbase-admin 已提交
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
    };
  };
};

// sizeof(ObObjValue)=8
union ObObjValue {
  int64_t int64_;
  uint64_t uint64_;

  float float_;
  double double_;

  const char* string_;

  uint32_t* nmb_digits_;

  int64_t datetime_;
  int32_t date_;
  int64_t time_;
  uint8_t year_;

  int64_t ext_;
  int64_t unknown_;
  const ObLobData* lob_;
  const ObLobLocator* lob_locator_;
  int64_t nmonth_;   // for interval year to month
  int64_t nsecond_;  // for interval day to second
};

class ObBatchChecksum;
class ObObj {
G
gm 已提交
1108
public:
O
oceanbase-admin 已提交
1109 1110 1111 1112 1113 1114 1115 1116 1117
  // min, max extend value
  static const int64_t MIN_OBJECT_VALUE = UINT64_MAX - 2;
  static const int64_t MAX_OBJECT_VALUE = UINT64_MAX - 1;
  // WARNING: used only in RootTable, other user should not use this
  // to represent a (min, max) range in Roottable impl, we need this
  static const char* MIN_OBJECT_VALUE_STR;
  static const char* MAX_OBJECT_VALUE_STR;
  static const char* NOP_VALUE_STR;

G
gm 已提交
1118
public:
O
oceanbase-admin 已提交
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
  ObObj();
  ObObj(const ObObj& other);
  explicit ObObj(bool val);
  explicit ObObj(int32_t val);
  explicit ObObj(int64_t val);
  explicit ObObj(ObObjType type);
  inline void reset();
  // when in not strict sql mode, build default value refer to data type
  int build_not_strict_default_value();
  static ObObj make_min_obj();
  static ObObj make_max_obj();
  static ObObj make_nop_obj();

  OB_INLINE void copy_meta_type(const ObObjMeta& meta)
  {
    meta_.set_type_simple(meta.get_type());
    meta_.set_collation_type(meta.get_collation_type());
    if (ObCharType == get_type() || ObVarcharType == get_type() || ob_is_text_tc(get_type()) ||
X
xj0 已提交
1137
        ob_is_lob_locator(get_type()) || ob_is_json(get_type()) ) {
O
oceanbase-admin 已提交
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
      meta_.set_collation_level(ObCollationLevel::CS_LEVEL_IMPLICIT);
    } else {
      meta_.set_collation_level(meta.get_collation_level());
    }
  }

  OB_INLINE void copy_value_to(ObObj& obj, bool& has_null) const
  {
    switch (get_type()) {
      case ObNullType:
      case ObExtendType: {
        obj = *this;
        has_null = true;
        break;
      }
      case ObCharType:
      case ObVarcharType:
      case ObTinyTextType:
      case ObTextType:
      case ObMediumTextType:
      case ObLongTextType:
      case ObLobType:
X
xj0 已提交
1160
      case ObJsonType:
O
oceanbase-admin 已提交
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
      case ObRawType: {
        obj.meta_.set_collation_level(meta_.get_collation_level());
        obj.meta_.set_scale(meta_.get_scale());
        obj.val_len_ = val_len_;
        obj.v_ = v_;
        break;
      }
      default: {
        obj.meta_.set_scale(meta_.get_scale());
        obj.val_len_ = val_len_;
        obj.v_ = v_;
        break;
      }
    }
  }

  OB_INLINE void copy_value_or_obj(ObObj& obj, bool is_copy_all) const
  {
    if (is_copy_all) {
      obj = *this;
    } else {
      obj.meta_.set_scale(meta_.get_scale());
      obj.val_len_ = val_len_;
      obj.v_ = v_;
    }
  }
  //@{ setters
  OB_INLINE void set_type(const ObObjType& type)
  {
    if (OB_UNLIKELY(ObNullType > type || ObMaxType < type)) {
      COMMON_LOG(ERROR, "invalid type", K(type));
      meta_.set_type(ObUnknownType);
    } else {
      meta_.set_type(type);
    }
  }
  static int64_t get_otimestamp_store_size(const bool is_timestamp_tz)
  {
    return static_cast<int64_t>(sizeof(int64_t) + (is_timestamp_tz ? sizeof(uint32_t) : sizeof(uint16_t)));
  }
  template <typename T>
  void set_obj_value(const T& v);
  void set_collation_level(const ObCollationLevel& cs_level)
  {
    meta_.set_collation_level(cs_level);
  }
  void set_collation_type(const ObCollationType& cs_type)
  {
    meta_.set_collation_type(cs_type);
  }
  void set_default_collation_type()
  {
    meta_.set_default_collation_type();
  }
  void set_meta_type(const ObObjMeta& type)
  {
    meta_ = type;
  }
  void set_collation(const ObObjMeta& type)
  {
    meta_.set_collation(type);
  }
  void set_scale(ObScale scale)
  {
    meta_.set_scale(scale);
  }

  void set_int(const ObObjType type, const int64_t value);
  void set_tinyint(const int8_t value);
  void set_smallint(const int16_t value);
  void set_mediumint(const int32_t value);
  void set_int32(const int32_t value);
  void set_int(const int64_t value);  // aka bigint

  void set_tinyint_value(const int8_t value);
  void set_smallint_value(const int16_t value);
  void set_mediumint_value(const int32_t value);
  void set_int32_value(const int32_t value);
  void set_int_value(const int64_t value);  // aka bigint

  void set_uint(const ObObjType type, const uint64_t value);
  void set_utinyint(const uint8_t value);
  void set_utinyint_value(const uint8_t value);
  void set_usmallint(const uint16_t value);
  void set_usmallint_value(const uint16_t value);
  void set_umediumint(const uint32_t value);
  void set_umediumint_value(const uint32_t value);
  void set_uint32(const uint32_t value);
  void set_uint32_value(const uint32_t value);
  void set_uint64(const uint64_t value);
  void set_uint64_value(const uint64_t value);

  void set_float(const ObObjType type, const float value);
  void set_float(const float value);
  void set_float_value(const float value);
  void set_ufloat(const float value);
  void set_ufloat_value(const float value);

  void set_double(const ObObjType type, const double value);
  void set_double(const double value);
  void set_double_value(const double value);
  void set_udouble(const double value);
  void set_udouble_value(const double value);

  void set_number(const ObObjType type, const number::ObNumber& num);
  void set_number(const ObObjType type, const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits);
  void set_number(const number::ObNumber& num);
  void set_number_value(const number::ObNumber& num);
  void set_number_value(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits);
  void set_number(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits);

  void set_unumber(const number::ObNumber& num);
  void set_unumber(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits);
  void set_unumber_value(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits);

  void set_number_float(const number::ObNumber& num);
  void set_number_float(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits);
  void set_number_float_value(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits);

  void set_datetime(const ObObjType type, const int64_t value);
  void set_datetime(const int64_t value);
  void set_timestamp(const int64_t value);
  void set_date(const int32_t value);
  void set_time(const int64_t value);
  void set_year(const uint8_t value);

  void set_datetime_value(const int64_t value);
  void set_timestamp_value(const int64_t value);
  void set_date_value(const int32_t value);
  void set_time_value(const int64_t value);
  void set_year_value(const uint8_t value);

  // only set v_.string_ and length
  void set_common_value(const ObString& value);

  void set_string(const ObObjType type, const char* ptr, const ObString::obstr_size_t size);
  void set_string(const ObObjType type, const ObString& value);
  void set_varchar(const ObString& value);
  void set_varchar(const char* ptr, const ObString::obstr_size_t size);
  void set_varchar_value(const char* ptr, const ObString::obstr_size_t size);
  void set_varchar(const char* cstr);
  void set_char(const ObString& value);
  void set_char_value(const char* ptr, const ObString::obstr_size_t size);
  void set_varbinary(const ObString& value);
  void set_binary(const ObString& value);
  void set_raw(const ObString& value);
  void set_raw(const char* ptr, const ObString::obstr_size_t size);
  void set_raw_value(const char* ptr, const ObString::obstr_size_t size);
  void set_hex_string(const ObString& value);
  void set_hex_string_value(const ObString& value);
  void set_hex_string_value(const char* ptr, const ObString::obstr_size_t size);
  void set_enum(const uint64_t value);
  void set_enum_value(const uint64_t value);
  void set_set(const uint64_t value);
  void set_set_value(const uint64_t value);
  void set_enum_inner(const ObString& value);
  void set_enum_inner(const char* ptr, const ObString::obstr_size_t size);
  void set_set_inner(const ObString& value);
  void set_set_inner(const char* ptr, const ObString::obstr_size_t size);
  void set_lob_value(const ObObjType type, const ObLobData* value, const int32_t length);
  void set_lob_value(const ObObjType type, const char* ptr, const int32_t length);
X
xj0 已提交
1322 1323
  void set_json_value(const ObObjType type, const ObLobData *value, const int32_t length);
  void set_json_value(const ObObjType type, const char *ptr, const int32_t length);
O
oceanbase-admin 已提交
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
  void set_lob_locator(const ObLobLocator& value);
  void set_lob_locator(const ObObjType type, const ObLobLocator& value);
  inline void set_lob_inrow()
  {
    meta_.set_lob_inrow();
  }
  inline void set_lob_outrow()
  {
    meta_.set_lob_outrow();
  }
  void set_otimestamp_value(const ObObjType type, const ObOTimestampData& value);
  void set_otimestamp_value(const ObObjType type, const int64_t time_us, const uint32_t time_ctx_desc);
  void set_otimestamp_value(const ObObjType type, const int64_t time_us, const uint16_t time_desc);
  void set_otimestamp_null(const ObObjType type);

  void set_timestamp_tz(const int64_t time_us, const uint32_t time_ctx_desc)
  {
    set_otimestamp_value(ObTimestampTZType, time_us, time_ctx_desc);
  }
  void set_timestamp_ltz(const int64_t time_us, const uint16_t time_desc)
  {
    set_otimestamp_value(ObTimestampLTZType, time_us, time_desc);
  }
  void set_timestamp_nano(const int64_t time_us, const uint16_t time_desc)
  {
    set_otimestamp_value(ObTimestampNanoType, time_us, time_desc);
  }
  void set_timestamp_tz(const ObOTimestampData& value)
  {
    set_otimestamp_value(ObTimestampTZType, value);
  }
  void set_timestamp_ltz(const ObOTimestampData& value)
  {
    set_otimestamp_value(ObTimestampLTZType, value);
  }
  void set_timestamp_nano(const ObOTimestampData& value)
  {
    set_otimestamp_value(ObTimestampNanoType, value);
  }

  inline void set_bool(const bool value);
  inline void set_ext(const int64_t value);
  inline void set_extend(const int64_t value, uint8 extend_type, int32_t size = 0);
  inline void set_unknown(const int64_t value);

  inline void set_bit(const uint64_t value);
  inline void set_bit_value(const uint64_t value);

  inline void set_null();
  inline void set_min_value();
  inline void set_max_value();
  inline void set_nop_value();

  inline void set_lob(const char* ptr, const int32_t size, const ObLobScale& lob_scale);

  void set_val_len(const int32_t val_len);
  void set_null_meta(const ObObjMeta meta);

  void set_interval_ym(const ObIntervalYMValue& value);
  void set_interval_ds(const ObIntervalDSValue& value);
  void set_interval_ym(const int64_t value)
  {
    set_interval_ym(ObIntervalYMValue(value));
  }
  void set_nvarchar2(const ObString& value);
  void set_nvarchar2_value(const char* ptr, const ObString::obstr_size_t size);
  void set_nchar(const ObString& value);
  void set_nchar_value(const char* ptr, const ObString::obstr_size_t size);

  void set_urowid(const ObURowIDData& urowid)
  {
    meta_.set_urowid();
    v_.string_ = (const char*)urowid.rowid_content_;
    val_len_ = urowid.rowid_len_;
  }
  void set_urowid(const char* ptr, const int64_t size)
  {
    meta_.set_urowid();
    v_.string_ = ptr;
    val_len_ = size;
  }
  //@}

  //@{ getters
  OB_INLINE ObObjType get_type() const
  {
    return meta_.get_type();
  }
  OB_INLINE ObObjTypeClass get_type_class() const
  {
    return meta_.get_type_class();
  }
  OB_INLINE ObCollationLevel get_collation_level() const
  {
    return meta_.get_collation_level();
  }
  OB_INLINE ObCollationType get_collation_type() const
  {
    return meta_.get_collation_type();
  }
  OB_INLINE ObScale get_scale() const
  {
    return meta_.get_scale();
  }
  inline const ObObjMeta& get_meta() const
  {
    return meta_;
  }
  inline const ObObjMeta& get_null_meta() const
  {
    return null_meta_;
  }

  inline int get_tinyint(int8_t& value) const;
  inline int get_smallint(int16_t& value) const;
  inline int get_mediumint(int32_t& value) const;
  inline int get_int32(int32_t& value) const;
  inline int get_int(int64_t& value) const;

  inline int get_utinyint(uint8_t& value) const;
  inline int get_usmallint(uint16_t& value) const;
  inline int get_umediumint(uint32_t& value) const;
  inline int get_uint32(uint32_t& value) const;
  inline int get_uint64(uint64_t& value) const;

  inline int get_float(float& value) const;
  inline int get_double(double& value) const;
  inline int get_ufloat(float& value) const;
  inline int get_udouble(double& value) const;

  inline int get_number(number::ObNumber& num) const;
  inline int get_unumber(number::ObNumber& num) const;
  inline int get_number_float(number::ObNumber& num) const;

  inline int get_datetime(int64_t& value) const;
  inline int get_timestamp(int64_t& value) const;
  inline int get_date(int32_t& value) const;
  inline int get_time(int64_t& value) const;
  inline int get_year(uint8_t& value) const;

  inline int get_string(ObString& value) const;
  inline int get_varchar(ObString& value) const;
  inline int get_char(ObString& value) const;
  inline int get_nvarchar2(ObString& value) const;
  inline int get_nchar(ObString& value) const;
  inline int get_varbinary(ObString& value) const;
  inline int get_raw(ObString& value) const;
  inline int get_binary(ObString& value) const;
  inline int get_hex_string(ObString& value) const;
  inline int get_print_string(ObString& value) const;

  inline int get_bool(bool& value) const;
  inline int get_ext(int64_t& value) const;
  inline int get_unknown(int64_t& value) const;
  inline int get_bit(uint64_t& value) const;
  inline int get_enum(uint64_t& value) const;
  inline int get_set(uint64_t& value) const;
  int get_enum_str_val(ObSqlString& str_val, const ObIArray<ObString>& type_infos) const;
  int get_set_str_val(ObSqlString& str_val, const ObIArray<ObString>& type_infos) const;
  inline int32_t get_val_len() const
  {
    return val_len_;
  }
  inline int get_enumset_inner_value(ObEnumSetInnerValue& inner_value) const;

  int get_interval_ym(ObIntervalYMValue& value) const;
  int get_interval_ds(ObIntervalDSValue& value) const;

  int get_urowid(ObURowIDData& urowid_data) const;

  /// the follow getters do not check type, use them when you already known the type
  OB_INLINE int8_t get_tinyint() const
  {
    return static_cast<int8_t>(v_.int64_);
  }
  OB_INLINE int16_t get_smallint() const
  {
    return static_cast<int16_t>(v_.int64_);
  }
  OB_INLINE int32_t get_mediumint() const
  {
    return static_cast<int32_t>(v_.int64_);
  }
  OB_INLINE int32_t get_int32() const
  {
    return static_cast<int32_t>(v_.int64_);
  }
  OB_INLINE int64_t get_int() const
  {
    return static_cast<int64_t>(v_.int64_);
  }

  OB_INLINE uint8_t get_utinyint() const
  {
    return static_cast<uint8_t>(v_.uint64_);
  }
  OB_INLINE uint16_t get_usmallint() const
  {
    return static_cast<uint16_t>(v_.uint64_);
  }
  OB_INLINE uint32_t get_umediumint() const
  {
    return static_cast<uint32_t>(v_.uint64_);
  }
  OB_INLINE uint32_t get_uint32() const
  {
    return static_cast<uint32_t>(v_.uint64_);
  }
  OB_INLINE uint64_t get_uint64() const
  {
    return static_cast<uint64_t>(v_.uint64_);
  }

  OB_INLINE float get_float() const
  {
    return v_.float_;
  }
  OB_INLINE double get_double() const
  {
    return v_.double_;
  }
  OB_INLINE float get_ufloat() const
  {
    return v_.float_;
  }
  OB_INLINE double get_udouble() const
  {
    return v_.double_;
  }

  OB_INLINE bool is_negative_number() const
  {
    return number::ObNumber::is_negative_number(nmb_desc_);
  }
  OB_INLINE bool is_zero_number() const
  {
    return number::ObNumber::is_zero_number(nmb_desc_);
  }
  OB_INLINE int64_t get_number_digit_length() const
  {
    return nmb_desc_.len_;
  }
  OB_INLINE int64_t get_number_byte_length() const
  {
    return nmb_desc_.len_ * sizeof(uint32_t);
  }
  OB_INLINE number::ObNumber get_number() const
  {
    return number::ObNumber(nmb_desc_.desc_, v_.nmb_digits_);
  }
  OB_INLINE number::ObNumber get_unumber() const
  {
    return number::ObNumber(nmb_desc_.desc_, v_.nmb_digits_);
  }
  OB_INLINE number::ObNumber get_number_float() const
  {
    return number::ObNumber(nmb_desc_.desc_, v_.nmb_digits_);
  }

  OB_INLINE int64_t get_datetime() const
  {
    return v_.datetime_;
  }
  OB_INLINE int64_t get_timestamp() const
  {
    return v_.datetime_;
  }
  OB_INLINE int32_t get_date() const
  {
    return v_.date_;
  }
  OB_INLINE int64_t get_time() const
  {
    return v_.time_;
  }
  OB_INLINE uint8_t get_year() const
  {
    return v_.year_;
  }

  OB_INLINE ObString get_string() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_varchar() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_char() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_varbinary() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_raw() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_binary() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_hex_string() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_print_string(const int64_t max_len) const
  {
    return ObString(MIN(val_len_, max_len), v_.string_);
  }
  OB_INLINE ObString get_lob_print_string(const int64_t max_len) const
  {
    return ObString(MIN(v_.lob_locator_->payload_size_, max_len), v_.lob_locator_->get_payload_ptr());
  }

  OB_INLINE bool get_bool() const
  {
    return (0 != v_.int64_);
  }
  inline int64_t get_ext() const;
  OB_INLINE int64_t get_unknown() const
  {
    return v_.unknown_;
  }
  OB_INLINE uint64_t get_bit() const
  {
    return v_.uint64_;
  }
  OB_INLINE uint64_t get_enum() const
  {
    return v_.uint64_;
  }
  OB_INLINE uint64_t get_set() const
  {
    return v_.uint64_;
  }
  OB_INLINE ObString get_set_inner() const
  {
    return ObString(val_len_, v_.string_);
  }
  OB_INLINE ObString get_enum_inner() const
  {
    return ObString(val_len_, v_.string_);
  }

  inline const number::ObNumber::Desc& get_number_desc() const
  {
    return nmb_desc_;
  }
  inline const uint32_t* get_number_digits() const
  {
    return v_.nmb_digits_;
  }

  inline const char* get_string_ptr() const
  {
    return v_.string_;
  }
  inline int32_t get_string_len() const
  {
    return val_len_;
  }
  inline const ObLobData* get_lob_value() const
  {
    return v_.lob_;
  }
  inline int get_lob_value(const ObLobData*& lob) const;

  inline int get_lob_locator(ObLobLocator*& lob_locator) const;
  inline const ObLobLocator* get_lob_locator() const
  {
    return v_.lob_locator_;
  }
  // TODO dangerous interface
  inline uint32_t get_lob_payload_size() const
  {
    return v_.lob_locator_->payload_size_;
  }
  inline const char* get_lob_payload_ptr() const
  {
    return v_.lob_locator_ == nullptr ? nullptr : v_.lob_locator_->get_payload_ptr();
  }

  inline ObOTimestampData::UnionTZCtx get_tz_desc() const
  {
    return time_ctx_;
  }
  inline ObOTimestampData get_otimestamp_value() const
  {
    return ObOTimestampData(v_.datetime_, time_ctx_);
  }
  inline int64_t get_otimestamp_store_size() const
  {
    return get_otimestamp_store_size(is_timestamp_tz());
  }
  inline int write_otimestamp(char* buf, const int64_t len, int64_t& pos) const;
  inline int read_otimestamp(const char* buf, const int64_t len);

  inline int64_t get_interval_store_size() const;
  inline int write_interval(char* buf) const;
  inline int read_interval(const char* buf);

  inline ObIntervalYMValue get_interval_ym() const
  {
    return ObIntervalYMValue(v_.nmonth_);
  }
  inline ObIntervalDSValue get_interval_ds() const
  {
    return ObIntervalDSValue(v_.nsecond_, interval_fractional_);
  }

  inline ObString get_nvarchar2() const
  {
    return ObString(val_len_, v_.string_);
  }
  inline ObString get_nchar() const
  {
    return ObString(val_len_, v_.string_);
  }

  inline ObURowIDData get_urowid() const
  {
    return ObURowIDData(val_len_, (const uint8_t*)v_.string_);
  }

  //@}

  //@{ test functions
  OB_INLINE bool is_valid_type() const
  {
    return meta_.is_valid();
  }
  OB_INLINE bool is_invalid_type() const
  {
    return meta_.is_invalid();
  }

  OB_INLINE bool is_null() const
  {
    return meta_.is_null();
  }
  OB_INLINE bool is_null_oracle() const
  {
    return meta_.is_null() || (meta_.is_character_type() && (0 == get_string_len()));
  }
  OB_INLINE bool is_tinyint() const
  {
    return meta_.is_tinyint();
  }
  OB_INLINE bool is_smallint() const
  {
    return meta_.is_smallint();
  }
  OB_INLINE bool is_mediumint() const
  {
    return meta_.is_mediumint();
  }
  OB_INLINE bool is_int32() const
  {
    return meta_.is_int32();
  }
  OB_INLINE bool is_int() const
  {
    return meta_.is_int();
  }
  OB_INLINE bool is_utinyint() const
  {
    return meta_.is_utinyint();
  }
  OB_INLINE bool is_usmallint() const
  {
    return meta_.is_usmallint();
  }
  OB_INLINE bool is_umediumint() const
  {
    return meta_.is_umediumint();
  }
  OB_INLINE bool is_uint32() const
  {
    return meta_.is_uint32();
  }
  OB_INLINE bool is_uint64() const
  {
    return meta_.is_uint64();
  }
  OB_INLINE bool is_float() const
  {
    return meta_.is_float();
  }
  OB_INLINE bool is_double() const
  {
    return meta_.is_double();
  }
  OB_INLINE bool is_ufloat() const
  {
    return meta_.is_ufloat();
  }
  OB_INLINE bool is_udouble() const
  {
    return meta_.is_udouble();
  }
  OB_INLINE bool is_number() const
  {
    return meta_.is_number();
  }
  OB_INLINE bool is_unumber() const
  {
    return meta_.is_unumber();
  }
  OB_INLINE bool is_number_float() const
  {
    return meta_.is_number_float();
  }
  OB_INLINE bool is_oracle_decimal() const
  {
    return meta_.is_oracle_decimal();
  }
  OB_INLINE bool is_datetime() const
  {
    return meta_.is_datetime();
  }
  OB_INLINE bool is_timestamp() const
  {
    return meta_.is_timestamp();
  }
  OB_INLINE bool is_otimestamp_type() const
  {
    return meta_.is_otimestamp_type();
  }
  OB_INLINE bool is_year() const
  {
    return meta_.is_year();
  }
  OB_INLINE bool is_date() const
  {
    return meta_.is_date();
  }
  OB_INLINE bool is_time() const
  {
    return meta_.is_time();
  }
  OB_INLINE bool is_varchar() const
  {
    return meta_.is_varchar();
  }
  OB_INLINE bool is_char() const
  {
    return meta_.is_char();
  }
  OB_INLINE bool is_varbinary() const
  {
    return meta_.is_varbinary();
  }
  OB_INLINE bool is_raw() const
  {
    return meta_.is_raw();
  }
  OB_INLINE bool is_binary() const
  {
    return meta_.is_binary();
  }
  OB_INLINE bool is_hex_string() const
  {
    return meta_.is_hex_string();
  }
  OB_INLINE bool is_ext() const
  {
    return meta_.is_ext();
  }
  OB_INLINE bool is_unknown() const
  {
    return meta_.is_unknown();
  }
  OB_INLINE bool is_bit() const
  {
    return meta_.is_bit();
  }
  OB_INLINE bool is_enum() const
  {
    return meta_.is_enum();
  }
  OB_INLINE bool is_set() const
  {
    return meta_.is_set();
  }
  OB_INLINE bool is_text() const
  {
    return meta_.is_text();
  }
  OB_INLINE bool is_clob() const
  {
    return meta_.is_clob();
  }
  // OB_INLINE bool is_oracle_clob() const { return meta_.is_oracle_clob(); }
  OB_INLINE bool is_blob() const
  {
    return meta_.is_blob();
  }
  // OB_INLINE bool is_oracle_blob() const { return meta_.is_oracle_blob(); }
  OB_INLINE bool is_lob() const
  {
    return meta_.is_lob();
  }
  OB_INLINE bool is_lob_inrow() const
  {
    return meta_.is_lob_inrow();
  }
  OB_INLINE bool is_lob_outrow() const
  {
    return meta_.is_lob_outrow();
  }
X
xj0 已提交
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948
  OB_INLINE bool is_json() const 
  { 
    return meta_.is_json(); 
  }
  OB_INLINE bool is_json_inrow() const 
  { 
    return meta_.is_json_inrow(); 
  }
  OB_INLINE bool is_json_outrow() const 
  { 
    return meta_.is_json_outrow(); 
  }
O
oceanbase-admin 已提交
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124
  OB_INLINE bool is_timestamp_tz() const
  {
    return meta_.is_timestamp_tz();
  }
  OB_INLINE bool is_timestamp_ltz() const
  {
    return meta_.is_timestamp_ltz();
  }
  OB_INLINE bool is_timestamp_nano() const
  {
    return meta_.is_timestamp_nano();
  }
  OB_INLINE bool is_interval_ym() const
  {
    return meta_.is_interval_ym();
  }
  OB_INLINE bool is_interval_ds() const
  {
    return meta_.is_interval_ds();
  }

  OB_INLINE bool is_unsigned_integer() const
  {
    return meta_.is_unsigned_integer();
  }
  OB_INLINE bool is_integer_type() const
  {
    return meta_.is_integer_type();
  }
  OB_INLINE bool is_numeric_type() const
  {
    return meta_.is_numeric_type();
  }
  OB_INLINE bool is_string_type() const
  {
    return meta_.is_string_type();
  }
  OB_INLINE bool is_temporal_type() const
  {
    return meta_.is_temporal_type();
  }
  OB_INLINE bool is_varchar_or_char() const
  {
    return meta_.is_varchar_or_char();
  }
  OB_INLINE bool is_varbinary_or_binary() const
  {
    return meta_.is_varbinary_or_binary();
  }
  OB_INLINE bool is_nvarchar2() const
  {
    return meta_.is_nvarchar2();
  }
  OB_INLINE bool is_nchar() const
  {
    return meta_.is_nchar();
  }
  OB_INLINE bool is_nstring() const
  {
    return meta_.is_nstring();
  }
  OB_INLINE bool is_fixed_len_char_type() const
  {
    return meta_.is_fixed_len_char_type();
  }
  OB_INLINE bool is_varying_len_char_type() const
  {
    return meta_.is_varying_len_char_type();
  }
  OB_INLINE bool is_character_type() const
  {
    return meta_.is_character_type();
  }
  OB_INLINE bool is_collation_free_compatible() const
  {
    return meta_.is_collation_free_compatible();
  }

  OB_INLINE bool is_urowid() const
  {
    return meta_.is_urowid();
  }
  OB_INLINE bool is_blob_locator() const
  {
    return meta_.is_blob_locator();
  }
  OB_INLINE bool is_clob_locator() const
  {
    return meta_.is_clob_locator();
  }
  OB_INLINE bool is_lob_locator() const
  {
    return meta_.is_lob_locator();
  }
  OB_INLINE bool is_string_or_lob_locator_type() const
  {
    return meta_.is_string_or_lob_locator_type();
  }
  OB_INLINE bool is_pl_extend() const
  {
    return is_ext() && 0 != meta_.get_extend_type();
  }

  inline bool is_min_value() const;
  inline bool is_max_value() const;
  inline bool is_nop_value() const;
  inline bool is_true() const;
  inline bool is_false() const;

  bool is_zero() const;
  //@}

  /// apply mutation to this obj
  int apply(const ObObj& mutation);

  //@{ comparison
  //
  // ATTENTION:
  //
  // When < > <= >= == != compare is_equal is called,
  // that_obj MUST have same type with this obj (*this)
  // or can_compare.
  // For Sql, to get diff type comparing result(varchar '123' compare with int 123),
  // call static function ObExprEqual::calc or other ObExprXX::calc.
  bool operator<(const ObObj& that_obj) const;
  bool operator>(const ObObj& that_obj) const;
  bool operator<=(const ObObj& that_obj) const;
  bool operator>=(const ObObj& that_obj) const;
  bool operator==(const ObObj& that_obj) const;
  bool operator!=(const ObObj& that_obj) const;
  bool can_compare(const ObObj& other) const;
  inline bool strict_equal(const ObObj& other) const;
  int check_collation_free_and_compare(const ObObj& other, int& cmp) const;
  int compare(const ObObj& other, int& cmp) const;
  int compare(const ObObj& other) const;
  int compare(const ObObj& other, ObCollationType cs_type, int& cmp) const;
  int compare(const ObObj& other, ObCollationType cs_type) const;
  int compare(const ObObj& other, common::ObCompareCtx& cmp_ctx, int& cmp) const;
  int compare(const ObObj& other, common::ObCompareCtx& cmp_ctx) const;
  int compare(const ObObj& other, ObCollationType cs_type, const ObCmpNullPos null_pos) const;
  int equal(const ObObj& other, bool& is_equal) const;
  bool is_equal(const ObObj& other) const;
  int equal(const ObObj& other, ObCollationType cs_type, bool& is_equal) const;
  bool is_equal(const ObObj& other, ObCollationType cs_type) const;
  //@}

  //@{ print utilities
  /// print as JSON style
  int64_t to_string(char* buffer, const int64_t length, const ObObjPrintParams& params = ObObjPrintParams()) const;
  /// print as SQL literal style, e.g. used to show column default value
  int print_sql_literal(
      char* buffer, int64_t length, int64_t& pos, const ObObjPrintParams& params = ObObjPrintParams()) const;
  /// print as SQL VARCHAR literal
  int print_varchar_literal(
      char* buffer, int64_t length, int64_t& pos, const ObObjPrintParams& params = ObObjPrintParams()) const;
  // used for enum and set
  int print_varchar_literal(const ObIArray<ObString>& type_infos, char* buffer, int64_t length, int64_t& pos) const;
  /// print as plain string
  int print_plain_str_literal(
      char* buffer, int64_t length, int64_t& pos, const ObObjPrintParams& params = ObObjPrintParams()) const;
  // used for enum and set
  int print_plain_str_literal(const ObIArray<ObString>& type_infos, char* buffer, int64_t length, int64_t& pos) const;

  void print_range_value(char* buffer, int64_t length, int64_t& pos) const;
  void print_str_with_repeat(char* buffer, int64_t length, int64_t& pos) const;

  // print_smart and print_format are for log_tool use
  int print_smart(char* buffer, int64_t length, int64_t& pos) const;
  int print_format(char* buffer, int64_t length, int64_t& pos) const;
  /// dump into log
  void dump(const int32_t log_level = OB_LOG_LEVEL_DEBUG) const;
  //@}

  //@{  deep copy
  bool need_deep_copy() const;
  OB_INLINE int64_t get_deep_copy_size() const;
O
obdev 已提交
2125 2126 2127 2128 2129
  int deep_copy(const ObObj &src, char *buf, const int64_t size, int64_t &pos);
  void* get_deep_copy_obj_ptr();
  void set_data_ptr(void *data_ptr);
  const void *get_data_ptr() const;
  //return byte length
O
oceanbase-admin 已提交
2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177
  int64_t get_data_length() const;

  template <typename Allocator>
  int to_collation_free_obj(ObObj& dst, bool& is_valid_collation_free, Allocator& allocator);
  //@}

  //@{ checksum
  // CRC64
  int64_t checksum(const int64_t current) const;
  int64_t checksum_v2(const int64_t current) const;
  void checksum(ObBatchChecksum& bc) const;
  // mysql hash for string, murmurhash for others
  uint64_t hash(uint64_t seed = 0) const;
  uint64_t hash_v1(uint64_t seed = 0) const;  // for compatible purpose, use hash() instead
  uint64_t hash_murmur(uint64_t seed = 0) const;
  // wyhash for all types
  uint64_t hash_wy(uint64_t seed = 0) const;
  // xx hash
  uint64_t hash_xx(uint64_t seed = 0) const;
  // mysql hash
  uint64_t varchar_hash(ObCollationType cs_type, uint64_t seed = 0) const;
  uint64_t varchar_murmur_hash(ObCollationType cs_type, uint64_t seed = 0) const;
  uint64_t varchar_wy_hash(ObCollationType cs_type, uint64_t seed = 0) const;
  uint64_t varchar_xx_hash(ObCollationType cs_type, uint64_t seed = 0) const;
  bool check_collation_integrity() const;
  //@}

  NEED_SERIALIZE_AND_DESERIALIZE;

  static uint32_t meta_offset_bits()
  {
    return offsetof(ObObj, meta_) * 8;
  }
  static uint32_t val_len_offset_bits()
  {
    return offsetof(ObObj, val_len_) * 8;
  }
  static uint32_t nmb_desc_offset_bits()
  {
    return offsetof(ObObj, nmb_desc_) * 8;
  }
  static uint32_t v_offset_bits()
  {
    return offsetof(ObObj, v_) * 8;
  }
  int get_char_length(const ObAccuracy accuracy, int32_t& char_len, bool is_oracle_mode) const;
  int convert_string_value_charset(ObCharsetType charset_type, ObIAllocator& allocator);

G
gm 已提交
2178
private:
O
oceanbase-admin 已提交
2179 2180 2181 2182
  friend class tests::common::ObjTest;
  friend class ObCompactCellWriter;
  friend class ObCompactCellIterator;

G
gm 已提交
2183
public:
O
oceanbase-admin 已提交
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838
  ObObjMeta meta_;  // sizeof = 4
  union {
    int32_t val_len_;
    int32_t interval_fractional_;  // values for intervalds type
    number::ObNumber::Desc nmb_desc_;
    ObOTimestampData::UnionTZCtx time_ctx_;
    ObObjMeta null_meta_;
  };              // sizeof = 4
  ObObjValue v_;  // sizeof = 8
};

struct ObjHashBase {
  static const bool is_varchar_hash = true;
};

// default hash method: same with ObObj::hash())
//  murmurhash for non string types.
//  mysql string hash for string types.
struct ObDefaultHash : public ObjHashBase {
  static const bool is_varchar_hash = false;
  static uint64_t hash(const void* data, uint64_t len, uint64_t seed)
  {
    return murmurhash64A(data, static_cast<int32_t>(len), seed);
  }
};

struct ObMurmurHash : public ObjHashBase {
  static uint64_t hash(const void* data, uint64_t len, uint64_t seed)
  {
    return murmurhash64A(data, static_cast<int32_t>(len), seed);
  }
};

struct ObWyHash : public ObjHashBase {
  static uint64_t hash(const void* data, uint64_t len, uint64_t seed)
  {
    return wyhash(data, len, seed);
  }
};

struct ObXxHash : public ObjHashBase {
  static uint64_t hash(const void* data, uint64_t len, uint64_t seed)
  {
    return XXH64(data, static_cast<size_t>(len), seed);
  }
};

template <ObObjType type, typename T, typename P>
struct ObjHashCalculator {
  static uint64_t calc_hash_value(const P& param, const uint64_t hash)
  {
    UNUSED(param);
    UNUSED(hash);
    return 0;
  }
};

inline ObObj::ObObj()
{
  reset();
}

inline ObObj::ObObj(bool val)
{
  set_bool(val);
}

inline ObObj::ObObj(int32_t val)
{
  set_int32(val);
}

inline ObObj::ObObj(int64_t val)
{
  set_int(val);
}

inline ObObj::ObObj(ObObjType type)
{
  meta_.set_type(type);
}

inline ObObj::ObObj(const ObObj& other)
{
  *this = other;
}

inline void ObObj::reset()
{
  meta_.set_null();
  meta_.set_collation_type(CS_TYPE_INVALID);
  meta_.set_collation_level(CS_LEVEL_INVALID);
  val_len_ = 0;
  v_.int64_ = 0;
}

inline ObObj ObObj::make_min_obj()
{
  ObObj obj;
  obj.set_min_value();
  return obj;
}

inline ObObj ObObj::make_max_obj()
{
  ObObj obj;
  obj.set_max_value();
  return obj;
}

inline ObObj ObObj::make_nop_obj()
{
  ObObj obj;
  obj.set_nop_value();
  return obj;
}

inline void ObObj::set_int(const ObObjType type, const int64_t value)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_NUMERIC);
  v_.int64_ = value;
}

inline void ObObj::set_tinyint(const int8_t value)
{
  meta_.set_tinyint();
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_tinyint_value(const int8_t value)
{
  //  meta_.set_tinyint();
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_smallint(const int16_t value)
{
  meta_.set_smallint();
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_smallint_value(const int16_t value)
{
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_mediumint(const int32_t value)
{
  meta_.set_mediumint();
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_mediumint_value(const int32_t value)
{
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_int32(const int32_t value)
{
  meta_.set_int32();
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_int32_value(const int32_t value)
{
  //  meta_.set_int32();
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_int(const int64_t value)
{
  meta_.set_int();
  v_.int64_ = value;
}

inline void ObObj::set_int_value(const int64_t value)
{
  v_.int64_ = value;
}

inline void ObObj::set_uint(const ObObjType type, const uint64_t value)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_NUMERIC);
  v_.uint64_ = value;
}

inline void ObObj::set_utinyint(const uint8_t value)
{
  meta_.set_utinyint();
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_utinyint_value(const uint8_t value)
{
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_usmallint(const uint16_t value)
{
  meta_.set_usmallint();
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_usmallint_value(const uint16_t value)
{
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_umediumint(const uint32_t value)
{
  meta_.set_umediumint();
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_umediumint_value(const uint32_t value)
{
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_uint32(const uint32_t value)
{
  meta_.set_uint32();
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_uint32_value(const uint32_t value)
{
  v_.uint64_ = static_cast<uint64_t>(value);
}

inline void ObObj::set_uint64(const uint64_t value)
{
  meta_.set_uint64();
  v_.uint64_ = value;
}

inline void ObObj::set_uint64_value(const uint64_t value)
{
  v_.uint64_ = value;
}

inline void ObObj::set_float(const ObObjType type, const float value)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_NUMERIC);
  v_.uint64_ = 0;
  v_.float_ = value;
}

inline void ObObj::set_float(const float value)
{
  meta_.set_float();
  v_.uint64_ = 0;
  v_.float_ = value;
}

inline void ObObj::set_float_value(const float value)
{
  //  meta_.set_float();
  v_.uint64_ = 0;
  v_.float_ = value;
}

inline void ObObj::set_ufloat(const float value)
{
  meta_.set_ufloat();
  v_.uint64_ = 0;
  v_.float_ = value;
}

inline void ObObj::set_ufloat_value(const float value)
{
  v_.uint64_ = 0;
  v_.float_ = value;
}

inline void ObObj::set_double(const ObObjType type, const double value)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_NUMERIC);
  v_.double_ = value;
}

inline void ObObj::set_double(const double value)
{
  meta_.set_double();
  v_.double_ = value;
}

inline void ObObj::set_double_value(const double value)
{
  v_.double_ = value;
}

inline void ObObj::set_udouble(const double value)
{
  meta_.set_udouble();
  v_.double_ = value;
}

inline void ObObj::set_udouble_value(const double value)
{
  v_.double_ = value;
}

inline void ObObj::set_number(const ObObjType type, const number::ObNumber& num)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_NUMERIC);
  nmb_desc_.desc_ = num.get_desc_value();
  v_.nmb_digits_ = num.get_digits();
}

inline void ObObj::set_number(const ObObjType type, const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_NUMERIC);
  nmb_desc_ = nmb_desc;
  v_.nmb_digits_ = nmb_digits;
}

inline void ObObj::set_number(const number::ObNumber& num)
{
  meta_.set_number();
  nmb_desc_.desc_ = num.get_desc_value();
  v_.nmb_digits_ = num.get_digits();
}

inline void ObObj::set_number_value(const number::ObNumber& num)
{
  nmb_desc_.desc_ = num.get_desc_value();
  v_.nmb_digits_ = num.get_digits();
}

inline void ObObj::set_number_value(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits)
{
  nmb_desc_ = nmb_desc;
  v_.nmb_digits_ = nmb_digits;
}

inline void ObObj::set_number(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits)
{
  meta_.set_number();
  nmb_desc_ = nmb_desc;
  v_.nmb_digits_ = nmb_digits;
}

inline void ObObj::set_unumber(const number::ObNumber& num)
{
  meta_.set_unumber();
  nmb_desc_.desc_ = num.get_desc_value();
  v_.nmb_digits_ = num.get_digits();
}

inline void ObObj::set_unumber(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits)
{
  meta_.set_unumber();
  nmb_desc_ = nmb_desc;
  v_.nmb_digits_ = nmb_digits;
}

inline void ObObj::set_unumber_value(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits)
{
  nmb_desc_ = nmb_desc;
  v_.nmb_digits_ = nmb_digits;
}

inline void ObObj::set_number_float(const number::ObNumber& num)
{
  meta_.set_number_float();
  nmb_desc_.desc_ = num.get_desc_value();
  v_.nmb_digits_ = num.get_digits();
}

inline void ObObj::set_number_float(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits)
{
  meta_.set_number_float();
  nmb_desc_ = nmb_desc;
  v_.nmb_digits_ = nmb_digits;
}

inline void ObObj::set_number_float_value(const number::ObNumber::Desc nmb_desc, uint32_t* nmb_digits)
{
  nmb_desc_ = nmb_desc;
  v_.nmb_digits_ = nmb_digits;
}

inline void ObObj::set_datetime(const ObObjType type, const int64_t value)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_NUMERIC);
  v_.datetime_ = value;
}

inline void ObObj::set_datetime(const int64_t value)
{
  meta_.set_datetime();
  v_.datetime_ = value;
}
inline void ObObj::set_datetime_value(const int64_t value)
{

  v_.datetime_ = value;
}

inline void ObObj::set_timestamp(const int64_t value)
{
  meta_.set_timestamp();
  v_.datetime_ = value;
}

inline void ObObj::set_timestamp_value(const int64_t value)
{
  v_.datetime_ = value;
}

inline void ObObj::set_date(const int32_t value)
{
  meta_.set_date();
  v_.uint64_ = 0;
  v_.date_ = value;
}

inline void ObObj::set_time(const int64_t value)
{
  meta_.set_time();
  v_.time_ = value;
}
inline void ObObj::set_date_value(const int32_t value)
{
  v_.uint64_ = 0;
  v_.date_ = value;
}

inline void ObObj::set_time_value(const int64_t value)
{
  v_.time_ = value;
}

inline void ObObj::set_year(const uint8_t value)
{
  meta_.set_year();
  v_.uint64_ = 0;
  v_.year_ = value;
}

inline void ObObj::set_year_value(const uint8_t value)
{
  v_.uint64_ = 0;
  v_.year_ = value;
}

inline void ObObj::set_common_value(const ObString& value)
{
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_string(const ObObjType type, const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_string(const ObObjType type, const ObString& value)
{
  meta_.set_type(type);
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_varchar(const ObString& value)
{
  meta_.set_varchar();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_varchar(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_varchar();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_varchar_value(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_varchar(const char* cstr)
{
  meta_.set_varchar();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = cstr;
  val_len_ = static_cast<int32_t>(strlen(cstr));
}

inline void ObObj::set_char(const ObString& value)
{
  meta_.set_char();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_char_value(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_varbinary(const ObString& value)
{
  meta_.set_varchar();
  meta_.set_collation_type(CS_TYPE_BINARY);
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_binary(const ObString& value)
{
  meta_.set_char();
  meta_.set_collation_type(CS_TYPE_BINARY);
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_raw(const ObString& value)
{
  meta_.set_raw();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_raw(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_raw();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_raw_value(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_collation_type(CS_TYPE_BINARY);
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_hex_string(const ObString& value)
{
  meta_.set_hex_string();
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_hex_string_value(const ObString& value)
{
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_hex_string_value(const char* ptr, const ObString::obstr_size_t size)
{
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_enum(const uint64_t value)
{
  meta_.set_enum();
  v_.uint64_ = value;
}

inline void ObObj::set_set(const uint64_t value)
{
  meta_.set_set();
  v_.uint64_ = value;
}

inline void ObObj::set_enum_value(const uint64_t value)
{
  v_.uint64_ = value;
}

inline void ObObj::set_set_value(const uint64_t value)
{
  v_.uint64_ = value;
}

inline void ObObj::set_enum_inner(const ObString& value)
{
  meta_.set_enum_inner();
  // meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_enum_inner(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_enum_inner();
  // meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_set_inner(const ObString& value)
{
  meta_.set_set_inner();
  // meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_set_inner(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_set_inner();
  // meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_lob_value(const ObObjType type, const ObLobData* value, const int32_t length)
{
  meta_.set_type(type);
  meta_.set_lob_outrow();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.lob_ = value;
  val_len_ = length;
}

inline void ObObj::set_lob_value(const ObObjType type, const char* ptr, const int32_t length)
{
  meta_.set_type(type);
  meta_.set_lob_inrow();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = length;
}

X
xj0 已提交
2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
inline void ObObj::set_json_value(const ObObjType type, const ObLobData *value, const int32_t length)
{
  set_lob_value(type, value, length);
  meta_.set_collation_type(CS_TYPE_UTF8MB4_BIN); // for oracle it is decided by sys collation.
}

inline void ObObj::set_json_value(const ObObjType type, const char *ptr, const int32_t length)
{
  set_lob_value(type, ptr, length);
  meta_.set_collation_type(CS_TYPE_UTF8MB4_BIN); // for oracle it is decided by sys collation.
}

O
oceanbase-admin 已提交
2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031
inline void ObObj::set_lob_locator(const ObLobLocator& value)
{
  meta_.set_type(ObLobType);
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.lob_locator_ = &value;
  val_len_ = value.get_total_size();
}

inline void ObObj::set_lob_locator(const ObObjType type, const ObLobLocator& value)
{
  UNUSED(type);
  meta_.set_type(ObLobType);
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.lob_locator_ = &value;
  val_len_ = value.get_total_size();
}

inline void ObObj::set_otimestamp_value(const ObObjType type, const ObOTimestampData& value)
{
  meta_.set_otimestamp_type(type);
  time_ctx_ = value.time_ctx_;
  v_.datetime_ = value.time_us_;
}

inline void ObObj::set_otimestamp_value(const ObObjType type, const int64_t time_us, const uint32_t time_ctx_desc)
{
  meta_.set_otimestamp_type(type);
  time_ctx_.desc_ = time_ctx_desc;
  v_.datetime_ = time_us;
}

inline void ObObj::set_otimestamp_value(const ObObjType type, const int64_t time_us, const uint16_t time_desc)
{
  meta_.set_otimestamp_type(type);
  time_ctx_.tz_desc_ = 0;
  time_ctx_.time_desc_ = time_desc;
  v_.datetime_ = time_us;
}

inline void ObObj::set_otimestamp_null(const ObObjType type)
{
  meta_.set_otimestamp_type(type);
  time_ctx_.tz_desc_ = 0;
  time_ctx_.time_desc_ = 0;
  time_ctx_.is_null_ = 1;
}

inline void ObObj::set_interval_ym(const ObIntervalYMValue& value)
{
  meta_.set_interval_ym();
  v_.nmonth_ = value.nmonth_;
  interval_fractional_ = 0;
}

inline void ObObj::set_interval_ds(const ObIntervalDSValue& value)
{
  meta_.set_interval_ds();
  v_.nsecond_ = value.nsecond_;
  interval_fractional_ = value.fractional_second_;
}

inline void ObObj::set_nvarchar2(const ObString& value)
{
  meta_.set_nvarchar2();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_nvarchar2_value(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_nchar(const ObString& value)
{
  meta_.set_nchar();
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = value.ptr();
  val_len_ = value.length();
}

inline void ObObj::set_nchar_value(const char* ptr, const ObString::obstr_size_t size)
{
  meta_.set_collation_level(CS_LEVEL_IMPLICIT);
  v_.string_ = ptr;
  val_len_ = size;
}

inline void ObObj::set_null()
{
  meta_.set_null();
}

inline void ObObj::set_bool(const bool value)
{
  meta_.set_tinyint();
  v_.int64_ = static_cast<int64_t>(value);
}

inline void ObObj::set_ext(const int64_t value)
{
  meta_.set_ext();
  v_.ext_ = value;
}

inline void ObObj::set_extend(const int64_t value, uint8 extend_type, int32_t size)
{
  set_ext(value);
  meta_.set_extend_type(extend_type);
  set_val_len(size);
}

inline void ObObj::set_unknown(const int64_t value)
{
  meta_.set_unknown();
  v_.unknown_ = value;
}

inline void ObObj::set_bit(const uint64_t value)
{
  meta_.set_bit();
  v_.uint64_ = value;
}

inline void ObObj::set_bit_value(const uint64_t value)
{
  v_.uint64_ = value;
}

inline void ObObj::set_min_value()
{
  set_ext(MIN_OBJECT_VALUE);
}

inline void ObObj::set_max_value()
{
  set_ext(MAX_OBJECT_VALUE);
}

inline void ObObj::set_nop_value()
{
  set_ext(ObActionFlag::OP_NOP);
}

inline void ObObj::set_lob(const char* ptr, const int32_t size, const ObLobScale& lob_scale)
{
  meta_.set_scale(lob_scale.get_scale());
  v_.string_ = ptr;
  val_len_ = size;
}

inline bool ObObj::is_min_value() const
{
  return meta_.get_type() == ObExtendType && v_.ext_ == MIN_OBJECT_VALUE;
}

inline bool ObObj::is_max_value() const
{
  return meta_.get_type() == ObExtendType && v_.ext_ == MAX_OBJECT_VALUE;
}

inline bool ObObj::is_nop_value() const
{
  return meta_.get_type() == ObExtendType && v_.ext_ == ObActionFlag::OP_NOP;
}

inline bool ObObj::is_true() const
{
  return ob_is_int_tc(meta_.get_type()) && 0 != v_.int64_;
}

inline bool ObObj::is_false() const
{
  return ob_is_int_tc(meta_.get_type()) && 0 == v_.int64_;
}

inline bool ObObj::need_deep_copy() const
{
X
xj0 已提交
3032 3033 3034 3035 3036 3037 3038
  return (((ob_is_string_type(meta_.get_type()) || 
            ob_is_lob_locator(meta_.get_type()) || 
            ob_is_json(meta_.get_type()) ||
            ob_is_raw(meta_.get_type()) ||
            ob_is_rowid_tc(meta_.get_type())) &&
            0 != val_len_ && NULL != get_string_ptr()) ||
            (ob_is_number_tc(meta_.get_type()) && 0 != nmb_desc_.len_ && NULL != get_number_digits()));
O
oceanbase-admin 已提交
3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295
}

inline int64_t ObObj::get_ext() const
{
  int64_t res = 0;
  if (ObExtendType == meta_.get_type()) {
    res = v_.ext_;
  }
  return res;
}

inline void ObObj::set_val_len(const int32_t val_len)
{
  val_len_ = val_len;
}

inline void ObObj::set_null_meta(const ObObjMeta meta)
{
  null_meta_ = meta;
}

////////////////////////////////////////////////////////////////
inline int ObObj::get_tinyint(int8_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_tinyint()) {
    v = static_cast<int8_t>(v_.int64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_smallint(int16_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_smallint()) {
    v = static_cast<int16_t>(v_.int64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_mediumint(int32_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_mediumint()) {
    v = static_cast<int32_t>(v_.int64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_int32(int32_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_int32()) {
    v = static_cast<int32_t>(v_.int64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_int(int64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_int()) {
    v = v_.int64_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_utinyint(uint8_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_utinyint()) {
    v = static_cast<uint8_t>(v_.uint64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_usmallint(uint16_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_usmallint()) {
    v = static_cast<uint16_t>(v_.uint64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_umediumint(uint32_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_umediumint()) {
    v = static_cast<uint32_t>(v_.uint64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_uint32(uint32_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_uint32()) {
    v = static_cast<uint32_t>(v_.uint64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_uint64(uint64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_uint64()) {
    v = v_.uint64_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_float(float& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_float()) {
    v = v_.float_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_double(double& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_double()) {
    v = v_.double_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_ufloat(float& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_ufloat()) {
    v = v_.float_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_udouble(double& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_udouble()) {
    v = v_.double_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_number(number::ObNumber& num) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_number()) {
    num.assign(nmb_desc_.desc_, v_.nmb_digits_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_unumber(number::ObNumber& num) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_unumber()) {
    num.assign(nmb_desc_.desc_, v_.nmb_digits_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_number_float(number::ObNumber& num) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_number_float()) {
    num.assign(nmb_desc_.desc_, v_.nmb_digits_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_datetime(int64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_datetime()) {
    v = v_.datetime_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_timestamp(int64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_timestamp()) {
    v = v_.datetime_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_date(int32_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_date()) {
    v = v_.date_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_time(int64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_time()) {
    v = v_.time_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_year(uint8_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_year()) {
    v = v_.year_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_string(ObString& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_string_or_lob_locator_type()) {
    if (ObLobType == meta_.get_type()) {
      if (OB_ISNULL(v_.lob_locator_)) {
        ret = OB_ERR_UNEXPECTED;
        OB_LOG(WARN, "Unexpected null lob locator", K(*this));
      } else if (OB_FAIL(v_.lob_locator_->get_payload(v))) {
        OB_LOG(WARN, "Failed to get payload from lob locator", K(ret), KPC(v_.lob_locator_));
      }
    } else {
      v.assign_ptr(v_.string_, val_len_);
    }
    ret = OB_SUCCESS;
X
xj0 已提交
3296 3297 3298
  } else if (meta_.is_json()) {
    v.assign_ptr(v_.string_, val_len_);
    ret = OB_SUCCESS;
O
oceanbase-admin 已提交
3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398
  } else if (meta_.is_null()) {
    v.assign_ptr(NULL, 0);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_print_string(ObString& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_string_type()) {
    v.assign_ptr(v_.string_, MIN(val_len_, OB_MAX_VARCHAR_LENGTH));
    ret = OB_SUCCESS;
  } else if (meta_.is_null()) {
    v.assign_ptr(NULL, 0);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_varchar(ObString& v) const
{
  return get_string(v);
}

inline int ObObj::get_char(ObString& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_char()) {
    v.assign_ptr(v_.string_, val_len_);
    ret = OB_SUCCESS;
  } else if (meta_.is_null()) {
    v.assign_ptr(NULL, 0);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_nvarchar2(ObString& v) const
{
  return get_string(v);
}

inline int ObObj::get_nchar(ObString& v) const
{
  return get_string(v);
}

inline int ObObj::get_varbinary(ObString& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_varbinary()) {
    v.assign_ptr(v_.string_, val_len_);
    ret = OB_SUCCESS;
  } else if (meta_.is_null()) {
    v.assign_ptr(NULL, 0);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_raw(ObString& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_raw()) {
    v.assign_ptr(v_.string_, val_len_);
    ret = OB_SUCCESS;
  } else if (meta_.is_null()) {
    v.assign_ptr(NULL, 0);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_binary(ObString& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_binary()) {
    v.assign_ptr(v_.string_, val_len_);
    ret = OB_SUCCESS;
  } else if (meta_.is_null()) {
    v.assign_ptr(NULL, 0);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_hex_string(ObString& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_hex_string()) {
    v.assign_ptr(v_.string_, val_len_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_lob_value(const ObLobData*& value) const
{
  int ret = OB_OBJ_TYPE_ERROR;
X
xj0 已提交
3399
  if (is_lob_outrow() || is_json_outrow()) {
O
oceanbase-admin 已提交
3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554
    value = v_.lob_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_lob_locator(ObLobLocator*& lob_locator) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (is_lob_locator()) {
    lob_locator = const_cast<ObLobLocator*>(v_.lob_locator_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_bool(bool& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_tinyint()) {
    v = (0 != v_.int64_);
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_ext(int64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_ext()) {
    v = v_.ext_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_unknown(int64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_unknown()) {
    v = v_.unknown_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_bit(uint64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_bit()) {
    v = v_.uint64_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_enum(uint64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_enum()) {
    v = v_.uint64_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_set(uint64_t& v) const
{
  int ret = OB_OBJ_TYPE_ERROR;
  if (meta_.is_set()) {
    v = v_.uint64_;
    ret = OB_SUCCESS;
  }
  return ret;
}

inline int ObObj::get_enumset_inner_value(ObEnumSetInnerValue& inner_value) const
{
  int ret = OB_SUCCESS;
  if (!ob_is_enumset_inner_tc(get_type())) {
    ret = OB_OBJ_TYPE_ERROR;
  } else {
    int64_t pos = 0;
    if (OB_FAIL(inner_value.deserialize(v_.string_, val_len_, pos))) {}
  }
  return ret;
}

inline int ObObj::get_interval_ds(ObIntervalDSValue& value) const
{
  int ret = OB_SUCCESS;
  if (OB_UNLIKELY(!meta_.is_interval_ds())) {
    ret = OB_OBJ_TYPE_ERROR;
  } else {
    value = get_interval_ds();
  }
  return ret;
}

inline int ObObj::get_interval_ym(ObIntervalYMValue& value) const
{
  int ret = OB_SUCCESS;
  if (OB_UNLIKELY(!meta_.is_interval_ym())) {
    ret = OB_OBJ_TYPE_ERROR;
  } else {
    value = get_interval_ym();
  }
  return ret;
}

inline int ObObj::get_urowid(ObURowIDData& urowid_data) const
{
  int ret = common::OB_SUCCESS;
  urowid_data.rowid_content_ = (const uint8_t*)v_.string_;
  urowid_data.rowid_len_ = val_len_;
  return ret;
}
OB_INLINE static uint64_t varchar_hash_with_collation(
    const ObObj& obj, const ObCollationType cs_type, const uint64_t hash, hash_algo hash_al)
{
  return ObCharset::hash(cs_type,
      obj.get_string_ptr(),
      obj.get_string_len(),
      hash,
      obj.is_varying_len_char_type() && lib::is_oracle_mode(),
      hash_al);
}

inline uint64_t ObObj::varchar_hash(ObCollationType cs_type, uint64_t seed) const
{
  check_collation_integrity();
  return varchar_hash_with_collation(*this, cs_type, seed, NULL);
}

inline uint64_t ObObj::varchar_murmur_hash(ObCollationType cs_type, uint64_t seed) const
{
  check_collation_integrity();
  return varchar_hash_with_collation(*this, cs_type, seed, ObMurmurHash::hash);
}

inline uint64_t ObObj::varchar_wy_hash(ObCollationType cs_type, uint64_t seed) const
{
  check_collation_integrity();
  return varchar_hash_with_collation(*this, cs_type, seed, ObWyHash::hash);
}

inline uint64_t ObObj::varchar_xx_hash(ObCollationType cs_type, uint64_t seed) const
{
  check_collation_integrity();
  return varchar_hash_with_collation(*this, cs_type, seed, ObXxHash::hash);
}

inline const void* ObObj::get_data_ptr() const
{
  const void* ret = NULL;
X
xj0 已提交
3555 3556
  if (ob_is_string_type(get_type()) || ob_is_raw(get_type()) || 
      ob_is_rowid_tc(get_type()) || ob_is_json(get_type())) {
O
oceanbase-admin 已提交
3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569
    ret = const_cast<char*>(v_.string_);
  } else if (ob_is_number_tc(get_type())) {
    ret = const_cast<uint32_t*>(v_.nmb_digits_);
  } else if (ob_is_lob_locator(get_type())) {
    ret = const_cast<ObLobLocator*>(v_.lob_locator_);
  } else {
    ret = &v_;
  }
  return ret;
};

inline void ObObj::set_data_ptr(void* data_ptr)
{
X
xj0 已提交
3570 3571
  if (ob_is_string_type(get_type()) || ob_is_raw(get_type()) || 
      ob_is_rowid_tc(get_type()) || ob_is_json(get_type())) {
O
oceanbase-admin 已提交
3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630
    v_.string_ = static_cast<char*>(data_ptr);
  } else if (ob_is_number_tc(get_type())) {
    v_.nmb_digits_ = static_cast<uint32_t*>(data_ptr);
  } else if (ob_is_lob_locator(get_type())) {
    v_.lob_locator_ = static_cast<ObLobLocator*>(data_ptr);
  } else {
    //@TODO other value pointer
  }
};

template <typename Allocator>
int ObObj::to_collation_free_obj(ObObj& dst, bool& is_valid_collation_free, Allocator& allocator)
{
  int ret = OB_SUCCESS;
  const int32_t len = get_string_len();
  const bool is_copy_all = true;
  const int32_t buf_len = len * 2;
  char* buf = NULL;
  is_valid_collation_free = true;
  if (!is_character_type()) {
    ret = OB_INVALID_ARGUMENT;
    COMMON_LOG(WARN,
        "invalid argument, only varchar or char can be transformed to collation free obj",
        K(ret),
        "obj type",
        get_type());
  } else {
    if (0 == len || NULL == get_string_ptr()) {
      copy_value_or_obj(dst, is_copy_all);
      dst.set_collation_type(CS_TYPE_COLLATION_FREE);
    } else {
      if (OB_ISNULL(buf = static_cast<char*>(allocator.alloc(buf_len)))) {
        ret = OB_ALLOCATE_MEMORY_FAILED;
        COMMON_LOG(WARN, "fail to allocate memory", K(ret), K(buf_len));
      } else {
        size_t size = ObCharset::sortkey(get_collation_type(),
            get_string_ptr(),
            static_cast<int64_t>(len),
            buf,
            static_cast<int64_t>(buf_len),
            is_valid_collation_free);
        copy_value_or_obj(dst, is_copy_all);
        if (is_varchar()) {
          dst.set_varchar_value(buf, static_cast<int32_t>(size));
        } else {
          dst.set_char_value(buf, static_cast<int32_t>(size));
        }
        dst.set_collation_type(CS_TYPE_COLLATION_FREE);
      }
    }
  }
  return ret;
}

// return byte length
inline int64_t ObObj::get_data_length() const
{
  int64_t ret = sizeof(v_);
  if (ob_is_string_type(get_type()) || ob_is_raw(get_type()) || ob_is_rowid_tc(get_type()) ||
X
xj0 已提交
3631
      ob_is_lob_locator(get_type()) || ob_is_json(get_type()) ) {
O
oceanbase-admin 已提交
3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806
    ret = val_len_;
  } else if (ob_is_number_tc(get_type())) {
    ret = nmb_desc_.len_ * sizeof(uint32_t);
  }
  return ret;
};

template <typename AllocatorT>
int ob_write_obj(AllocatorT& allocator, const ObObj& src, ObObj& dst)
{
  int ret = OB_SUCCESS;
  if (OB_UNLIKELY(src.need_deep_copy())) {
    int64_t deep_copy_size = src.get_deep_copy_size();
    char* buf = static_cast<char*>(allocator.alloc(deep_copy_size));
    int64_t pos = 0;
    if (OB_ISNULL(buf)) {
      ret = OB_ALLOCATE_MEMORY_FAILED;
      LIB_LOG(WARN, "allocate memory failed", K(ret), K(deep_copy_size));
    } else if (OB_FAIL(dst.deep_copy(src, buf, deep_copy_size, pos))) {
      LIB_LOG(WARN, "deep copy src obj failed", K(ret), K(deep_copy_size), K(pos));
    }
  } else {
    dst = src;
  }
  return ret;
}

inline int ObObj::write_otimestamp(char* buf, const int64_t len, int64_t& pos) const
{
  int ret = common::OB_SUCCESS;
  if (OB_ISNULL(buf) || OB_UNLIKELY(len < get_otimestamp_store_size())) {
    ret = common::OB_INVALID_ARGUMENT;
    OB_LOG(WARN, "invalid argument", KP(buf), K(len));
  } else {
    const ObOTimestampData& ot_data = get_otimestamp_value();
    *reinterpret_cast<int64_t*>(buf) = ot_data.time_us_;
    if (is_timestamp_tz()) {
      *reinterpret_cast<uint32_t*>(buf + sizeof(int64_t)) = ot_data.time_ctx_.desc_;
      pos += static_cast<int64_t>(sizeof(int64_t) + sizeof(uint32_t));
    } else {
      *reinterpret_cast<uint16_t*>(buf + sizeof(int64_t)) = ot_data.time_ctx_.time_desc_;
      pos += static_cast<int64_t>(sizeof(int64_t) + sizeof(uint16_t));
    }
  }
  return ret;
}

inline int ObObj::read_otimestamp(const char* buf, const int64_t len)
{
  int ret = common::OB_SUCCESS;
  if (OB_ISNULL(buf) || OB_UNLIKELY(len < get_otimestamp_store_size())) {
    ret = common::OB_INVALID_ARGUMENT;
    OB_LOG(WARN, "invalid argument", KP(buf), K(len));
  } else {
    const int64_t time_us = *reinterpret_cast<int64_t*>(const_cast<char*>(buf));
    if (is_timestamp_tz()) {
      const uint32_t time_ctx_desc = *reinterpret_cast<const uint32_t*>(buf + sizeof(int64_t));
      set_otimestamp_value(get_type(), time_us, time_ctx_desc);
    } else {
      const uint16_t time_desc = *reinterpret_cast<const uint16_t*>(buf + sizeof(int64_t));
      set_otimestamp_value(get_type(), time_us, time_desc);
    }
  }
  return ret;
}

int ObObj::read_interval(const char* buf)
{
  int ret = OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = OB_INVALID_ARGUMENT;
    OB_LOG(WARN, "invalid argument", KP(buf));
  } else if (is_interval_ym()) {
    ObIntervalYMValue value;
    if (OB_FAIL(value.decode(buf))) {
    } else {
      set_interval_ym(value);
    }
  } else {
    ObIntervalDSValue value;
    if (OB_FAIL(value.decode(buf))) {
    } else {
      set_interval_ds(value);
    }
  }
  return ret;
}

int64_t ObObj::get_interval_store_size() const
{
  return is_interval_ym() ? ObIntervalYMValue::get_store_size() : ObIntervalDSValue::get_store_size();
}

int ObObj::write_interval(char* buf) const
{
  int ret = common::OB_SUCCESS;
  if (OB_ISNULL(buf)) {
    ret = common::OB_INVALID_ARGUMENT;
    OB_LOG(WARN, "invalid argument", KP(buf));
  } else {
    ret = is_interval_ym() ? get_interval_ym().encode(buf) : get_interval_ds().encode(buf);
  }
  return ret;
}

inline bool ObObj::strict_equal(const ObObj& other) const
{
  bool bret = true;
  if (OB_UNLIKELY(get_type() != other.get_type())) {
    bret = false;
  } else {
    // here must use CS_TYPE_BINARY to compare, avoid spaces at the end of the string be ignored
    bret = (0 == compare(other, CS_TYPE_BINARY));
    if (bret && is_timestamp_tz()) {
      // for the data type of timestamp with time zone,
      // obj meaningful info includes v_.datetime_ and time_ctx_.desc_
      // so we must compare time_ctx_.desc_ here
      bret = (time_ctx_.desc_ == other.time_ctx_.desc_);
    }
  }
  return bret;
}

#define DEFINE_SET_COMMON_OBJ_VALUE(VTYPE, OBJTYPE)           \
  template <>                                                 \
  inline void ObObj::set_obj_value<OBJTYPE>(const OBJTYPE& v) \
  {                                                           \
    v_.VTYPE##_ = static_cast<typeof(v_.VTYPE##_)>(v);        \
  }

DEFINE_SET_COMMON_OBJ_VALUE(int64, int8_t);
DEFINE_SET_COMMON_OBJ_VALUE(uint64, uint8_t);
DEFINE_SET_COMMON_OBJ_VALUE(int64, int16_t);
DEFINE_SET_COMMON_OBJ_VALUE(uint64, uint16_t);
DEFINE_SET_COMMON_OBJ_VALUE(int64, int32_t);
DEFINE_SET_COMMON_OBJ_VALUE(uint64, uint32_t);
DEFINE_SET_COMMON_OBJ_VALUE(float, float);
DEFINE_SET_COMMON_OBJ_VALUE(double, double);
DEFINE_SET_COMMON_OBJ_VALUE(int64, int64_t);
DEFINE_SET_COMMON_OBJ_VALUE(uint64, uint64_t);
template <>
inline void ObObj::set_obj_value<ObString>(const ObString& v)
{
  v_.string_ = v.ptr();
  val_len_ = v.length();
}

template <>
inline void ObObj::set_obj_value<ObIntervalYMValue>(const ObIntervalYMValue& v)
{
  v_.nmonth_ = v.nmonth_;
  interval_fractional_ = 0;
}

template <>
inline void ObObj::set_obj_value<ObIntervalDSValue>(const ObIntervalDSValue& v)
{
  v_.nsecond_ = v.nsecond_;
  interval_fractional_ = v.fractional_second_;
}

template <>
inline void ObObj::set_obj_value<ObURowIDData>(const ObURowIDData& urowid)
{
  v_.string_ = (const char*)urowid.rowid_content_;
  val_len_ = urowid.rowid_len_;
}

struct ParamFlag {
  ParamFlag()
      : need_to_check_type_(true),
        need_to_check_bool_value_(false),
        expected_bool_value_(false),
        need_to_check_extend_type_(false),
        is_ref_cursor_type_(false),
X
xj0 已提交
3807
        is_boolean_(false),
O
oceanbase-admin 已提交
3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826
        reserved_(0)
  {}
  TO_STRING_KV(K_(need_to_check_type), K_(need_to_check_bool_value), K_(expected_bool_value));
  void reset();

  static uint32_t flag_offset_bits()
  {
    return offsetof(ParamFlag, flag_) * 8;
  }

  union {
    uint8_t flag_;
    struct {
      uint8_t need_to_check_type_ : 1;         // TRUE if the type need to be checked by plan cache, FALSE otherwise
      uint8_t need_to_check_bool_value_ : 1;   // TRUE if the bool value need to be checked by plan cache, FALSE
                                               // otherwise
      uint8_t expected_bool_value_ : 1;        // bool value, effective only when need_to_check_bool_value_ is true
      uint8_t need_to_check_extend_type_ : 1;  // True if the extended type needs to be checked
      uint8_t is_ref_cursor_type_ : 1;         // in pl/sql context, this will be true if the local var is a ref cursor
X
xj0 已提交
3827 3828 3829
      uint8_t is_pl_mock_default_param_ : 1; // UNUSED
      uint8_t is_boolean_ : 1; // to distinguish T_BOOL and T_TINYINT
      uint8_t reserved_ : 1;
O
oceanbase-admin 已提交
3830 3831 3832 3833 3834 3835 3836
    };
  };

  OB_UNIS_VERSION_V(1);
};

class ObObjParam : public ObObj {
G
gm 已提交
3837
public:
O
oceanbase-admin 已提交
3838 3839 3840 3841 3842
  ObObjParam() : ObObj(), accuracy_(), res_flags_(0), raw_text_pos_(-1), raw_text_len_(-1)
  {}
  ObObjParam(const ObObj& other) : ObObj(other), accuracy_(), res_flags_(0), raw_text_pos_(-1), raw_text_len_(-1)
  {}

G
gm 已提交
3843
public:
O
oceanbase-admin 已提交
3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958
  void reset();
  // accuracy.
  OB_INLINE void set_accuracy(const common::ObAccuracy& accuracy)
  {
    accuracy_.set_accuracy(accuracy);
  }
  OB_INLINE void set_length(common::ObLength length)
  {
    accuracy_.set_length(length);
  }
  OB_INLINE void set_precision(common::ObPrecision precision)
  {
    accuracy_.set_precision(precision);
  }
  OB_INLINE void set_length_semantics(common::ObLengthSemantics length_semantics)
  {
    accuracy_.set_length_semantics(length_semantics);
  }
  OB_INLINE void set_scale(common::ObScale scale)
  {
    ObObj::set_scale(scale);
    accuracy_.set_scale(scale);
  }
  OB_INLINE void set_udt_id(uint64_t id)
  {
    accuracy_.set_accuracy(id);
  }
  OB_INLINE const common::ObAccuracy& get_accuracy() const
  {
    return accuracy_;
  }
  OB_INLINE common::ObLength get_length() const
  {
    return accuracy_.get_length();
  }
  OB_INLINE common::ObPrecision get_precision() const
  {
    return accuracy_.get_precision();
  }
  OB_INLINE common::ObScale get_scale() const
  {
    return accuracy_.get_scale();
  }
  OB_INLINE uint64_t get_udt_id() const
  {
    return is_ext() ? accuracy_.get_accuracy() : OB_INVALID_INDEX;
  }
  OB_INLINE void set_result_flag(uint32_t flag)
  {
    res_flags_ |= flag;
  }
  OB_INLINE void unset_result_flag(uint32_t flag)
  {
    res_flags_ &= (~flag);
  }
  OB_INLINE bool has_result_flag(uint32_t flag) const
  {
    return res_flags_ & flag;
  }
  OB_INLINE uint32_t get_result_flag() const
  {
    return res_flags_;
  }

  OB_INLINE const ParamFlag& get_param_flag() const
  {
    return flag_;
  }
  OB_INLINE void set_param_flag(const ParamFlag flag)
  {
    flag_ = flag;
  }
  OB_INLINE void set_need_to_check_type(bool flag)
  {
    flag_.need_to_check_type_ = flag;
  }
  OB_INLINE bool need_to_check_type() const
  {
    return flag_.need_to_check_type_;
  }
  OB_INLINE void set_need_to_check_extend_type(bool flag)
  {
    flag_.need_to_check_extend_type_ = flag;
  }
  OB_INLINE bool need_to_check_extend_type() const
  {
    return flag_.need_to_check_extend_type_;
  }

  OB_INLINE void set_need_to_check_bool_value(bool flag)
  {
    flag_.need_to_check_bool_value_ = flag;
  }
  OB_INLINE bool need_to_check_bool_value() const
  {
    return flag_.need_to_check_bool_value_;
  }

  OB_INLINE void set_expected_bool_value(bool b_value)
  {
    flag_.expected_bool_value_ = b_value;
  }
  OB_INLINE bool expected_bool_value() const
  {
    return flag_.expected_bool_value_;
  }

  OB_INLINE void set_is_ref_cursor_type(bool flag)
  {
    flag_.is_ref_cursor_type_ = flag;
  }
  OB_INLINE bool is_ref_cursor_type() const
  {
    return flag_.is_ref_cursor_type_;
  }
X
xj0 已提交
3959 3960 3961 3962 3963 3964 3965 3966
  OB_INLINE void set_is_boolean(bool flag) 
  { 
    flag_.is_boolean_ = flag; 
  }
  OB_INLINE bool is_boolean() const 
  { 
    return flag_.is_boolean_; 
  }
O
oceanbase-admin 已提交
3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010
  OB_INLINE void set_raw_text_info(int32_t pos, int32_t len)
  {
    raw_text_pos_ = pos;
    raw_text_len_ = len;
  }
  OB_INLINE int32_t get_raw_text_pos() const
  {
    return raw_text_pos_;
  }
  OB_INLINE int32_t get_raw_text_len() const
  {
    return raw_text_len_;
  }
  OB_INLINE void set_param_meta()
  {
    param_meta_ = get_meta();
  }
  OB_INLINE void set_param_meta(const ObObjMeta& meta)
  {
    param_meta_ = meta;
  }
  OB_INLINE const ObObjMeta& get_param_meta() const
  {
    return param_meta_;
  }

  // others.
  INHERIT_TO_STRING_KV(
      N_OBJ, ObObj, N_ACCURACY, accuracy_, N_FLAG, res_flags_, K_(raw_text_pos), K_(raw_text_len), K_(param_meta));
  NEED_SERIALIZE_AND_DESERIALIZE;

  static uint32_t accuracy_offset_bits()
  {
    return offsetof(ObObjParam, accuracy_) * 8;
  }
  static uint32_t res_flags_offset_bits()
  {
    return offsetof(ObObjParam, res_flags_) * 8;
  }
  static uint32_t flag_offset_bits()
  {
    return offsetof(ObObjParam, flag_) * 8;
  }

G
gm 已提交
4011
private:
O
oceanbase-admin 已提交
4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023
  ObAccuracy accuracy_;
  uint32_t res_flags_;  // BINARY, NUM, NOT_NULL, TIMESTAMP, etc
                        // reference: src/lib/regex/include/mysql_com.h
  ParamFlag flag_;
  int32_t raw_text_pos_;
  int32_t raw_text_len_;
  ObObjMeta param_meta_;  // meta for objparma, to solve Oracle NULL/'' problem
};

struct ObDataType {
  OB_UNIS_VERSION(1);

G
gm 已提交
4024
public:
O
oceanbase-admin 已提交
4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166
  ObDataType() : meta_(), accuracy_(), charset_(CHARSET_UTF8MB4), is_binary_collation_(false), is_zero_fill_(false)
  {}
  TO_STRING_KV(K_(meta), K_(accuracy), K_(charset), K_(is_binary_collation), K_(is_zero_fill));
  inline void reset()
  {
    meta_.reset();
    accuracy_.reset();
    charset_ = CHARSET_UTF8MB4;
    is_binary_collation_ = false;
    is_zero_fill_ = false;
  }
  inline bool operator==(const ObDataType& other) const
  {
    return meta_ == other.meta_ && accuracy_ == other.accuracy_ && charset_ == other.charset_ &&
           is_binary_collation_ == other.is_binary_collation_ && is_zero_fill_ == other.is_zero_fill_;
  }
  inline ObObjType get_obj_type() const
  {
    return meta_.get_type();
  }
  inline ObObjTypeClass get_type_class() const
  {
    return meta_.get_type_class();
  }
  inline ObLength get_length() const
  {
    return accuracy_.get_length();
  }
  inline ObPrecision get_precision() const
  {
    return accuracy_.get_precision();
  }
  inline ObLengthSemantics get_length_semantics() const
  {
    return accuracy_.get_length_semantics();
  }
  inline ObScale get_scale() const
  {
    return accuracy_.get_scale();
  }
  inline ObCharsetType get_charset_type() const
  {
    return charset_;
  }
  inline ObCollationType get_collation_type() const
  {
    return meta_.get_collation_type();
  }
  inline ObCollationLevel get_collation_level() const
  {
    return meta_.get_collation_level();
  }
  inline bool is_binary_collation() const
  {
    return is_binary_collation_;
  }
  inline bool is_zero_fill() const
  {
    return is_zero_fill_;
  }
  inline void set_obj_type(const ObObjType& type)
  {
    return meta_.set_type(type);
  }
  inline void set_length(const ObLength length)
  {
    accuracy_.set_length(length);
  }
  inline void set_precision(const ObPrecision precision)
  {
    accuracy_.set_precision(precision);
  }
  inline void set_length_semantics(const ObLengthSemantics length_semantics)
  {
    accuracy_.set_length_semantics(length_semantics);
  }
  inline void set_scale(const ObScale scale)
  {
    accuracy_.set_scale(scale);
  }
  inline void set_charset_type(const ObCharsetType charset_type)
  {
    charset_ = charset_type;
  }
  inline void set_collation_type(const ObCollationType coll_type)
  {
    meta_.set_collation_type(coll_type);
  }
  inline void set_collation_level(const ObCollationLevel coll_level)
  {
    meta_.set_collation_level(coll_level);
  }
  inline void set_binary_collation(const bool is_binary_collation)
  {
    is_binary_collation_ = is_binary_collation;
  }
  inline void set_zero_fill(const bool is_zero_fill)
  {
    is_zero_fill_ = is_zero_fill;
  }
  inline const ObObjMeta& get_meta_type() const
  {
    return meta_;
  }
  inline void set_meta_type(const ObObjMeta& meta_type)
  {
    meta_ = meta_type;
  }
  inline const ObAccuracy& get_accuracy() const
  {
    return accuracy_;
  }
  inline void set_accuracy(const ObAccuracy& accuracy)
  {
    accuracy_ = accuracy;
  }
  inline int64_t get_accuracy_value() const
  {
    return accuracy_.accuracy_;
  }
  inline void set_int()
  {
    meta_.set_int();
  }
  inline uint64_t get_udt_id() const
  {
    return accuracy_.get_accuracy();
  }
  inline void set_udt_id(uint64_t udt_id)
  {
    accuracy_.set_accuracy(udt_id);
  }
  ObObjMeta meta_;
  ObAccuracy accuracy_;
  ObCharsetType charset_;
  bool is_binary_collation_;
  bool is_zero_fill_;
};

OB_INLINE int64_t ObObj::get_deep_copy_size() const
{
  int64_t ret = 0;
X
xj0 已提交
4167
  if (is_string_type() || is_raw() || ob_is_rowid_tc(get_type()) || is_lob_locator() || is_json()) {
O
oceanbase-admin 已提交
4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185
    ret += val_len_;
  } else if (ob_is_number_tc(get_type())) {
    ret += (sizeof(uint32_t) * nmb_desc_.len_);
  }
  return ret;
}

typedef int (*ob_obj_print)(
    const ObObj& obj, char* buffer, int64_t length, int64_t& pos, const ObObjPrintParams& params);
typedef int64_t (*ob_obj_crc64)(const ObObj& obj, const int64_t current);
typedef void (*ob_obj_batch_checksum)(const ObObj& obj, ObBatchChecksum& bc);
typedef uint64_t (*ob_obj_hash)(const ObObj& obj, const uint64_t hash);
typedef int (*ob_obj_value_serialize)(const ObObj& obj, char* buf, const int64_t buf_len, int64_t& pos);
typedef int (*ob_obj_value_deserialize)(ObObj& obj, const char* buf, const int64_t data_len, int64_t& pos);
typedef int64_t (*ob_obj_value_get_serialize_size)(const ObObj& obj);
typedef uint64_t (*ob_obj_crc64_v3)(const ObObj& obj, const uint64_t hash);

class ObObjUtil {
G
gm 已提交
4186
public:
O
oceanbase-admin 已提交
4187 4188 4189 4190 4191 4192 4193 4194
  static ob_obj_hash get_murmurhash_v3(ObObjType type);
  static ob_obj_hash get_murmurhash_v2(ObObjType type);
  static ob_obj_crc64_v3 get_crc64_v3(ObObjType type);
  static ob_obj_hash get_xxhash64(ObObjType type);
  static ob_obj_hash get_wyhash(ObObjType type);
};

class ObHexEscapeSqlStr {
G
gm 已提交
4195
public:
4196 4197 4198
  ObHexEscapeSqlStr(const common::ObString &str) : str_(str), skip_escape_(false)
  {}
  ObHexEscapeSqlStr(const common::ObString &str, const bool skip_escape) : str_(str), skip_escape_(skip_escape)
O
oceanbase-admin 已提交
4199 4200 4201 4202 4203 4204 4205 4206
  {}
  ObString str() const
  {
    return str_;
  }
  int64_t get_extra_length() const;
  DECLARE_TO_STRING;

G
gm 已提交
4207
private:
O
oceanbase-admin 已提交
4208
  ObString str_;
4209
  bool skip_escape_;
O
oceanbase-admin 已提交
4210 4211 4212 4213 4214 4215
};

}  // namespace common
}  // namespace oceanbase

#endif  //