bugfix json_storage_size for scalar

This commit is contained in:
obdev
2024-02-08 05:11:54 +00:00
committed by ob-robot
parent 63f76b5b53
commit 4db40e18c7
4 changed files with 30 additions and 2 deletions

View File

@ -4827,14 +4827,14 @@ int ObIJsonBase::get_used_size(uint64_t &size)
if (is_bin()) {
const ObJsonBin *j_bin = static_cast<const ObJsonBin *>(this);
size = j_bin->get_used_bytes();
size = j_bin->get_serialize_size();
} else { // is tree
ObArenaAllocator allocator;
ObIJsonBase *j_bin = NULL;
if (OB_FAIL(ObJsonBaseFactory::transform(&allocator, this, ObJsonInType::JSON_BIN, j_bin))) {
LOG_WARN("fail to transform to tree", K(ret));
} else {
size = static_cast<const ObJsonBin *>(j_bin)->get_used_bytes();
size = static_cast<const ObJsonBin *>(j_bin)->get_serialize_size();
}
}

View File

@ -4009,6 +4009,20 @@ int ObJsonBin::rebuild(ObJsonBuffer &result)
return ret;
}
uint64_t ObJsonBin::get_serialize_size() const
{
uint64_t size = 0;
ObJBVerType ver_type = get_vertype();
if (ObJsonVerType::is_array(ver_type)
|| ObJsonVerType::is_object(ver_type)
|| ObJsonVerType::is_opaque_or_string(ver_type)) {
size = get_used_bytes();
} else {
size = 1 /*vertype byte*/ + get_used_bytes();
}
return size;
}
void ObJsonBin::destroy()
{
result_.reset();

View File

@ -185,6 +185,7 @@ public:
OB_INLINE ObJsonInType get_internal_type() const override { return ObJsonInType::JSON_BIN; }
OB_INLINE uint64_t element_count() const override { return element_count_; }
OB_INLINE uint64_t get_used_bytes() const { return bytes_; } // return acutal used bytes for curr iter
uint64_t get_serialize_size() const;
OB_INLINE ObJsonNodeType json_type() const override
{
return static_cast<ObJsonNodeType>(ObJsonVerType::get_json_type(get_vertype()));