bugfix json_storage_size for scalar
This commit is contained in:
parent
63f76b5b53
commit
4db40e18c7
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
14
deps/oblib/src/lib/json_type/ob_json_bin.cpp
vendored
14
deps/oblib/src/lib/json_type/ob_json_bin.cpp
vendored
@ -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();
|
||||
|
1
deps/oblib/src/lib/json_type/ob_json_bin.h
vendored
1
deps/oblib/src/lib/json_type/ob_json_bin.h
vendored
@ -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()));
|
||||
|
@ -68,6 +68,19 @@ int ObExprJsonStorageSize::calc(ObEvalCtx &ctx, const ObDatum &data, ObDatumMeta
|
||||
LOG_WARN("invalid input type", K(type));
|
||||
} else if (OB_FAIL(ObJsonExprHelper::ensure_collation(type, cs_type))) {
|
||||
LOG_WARN("fail to ensure collation", K(ret), K(type), K(cs_type));
|
||||
} else if (ob_is_json(type)) {
|
||||
// json use lob storage, so no need read full data to get length
|
||||
ObString j_str = data.get_string();
|
||||
ObLobLocatorV2 locator(j_str, has_lob_header);
|
||||
int64_t size = 0;
|
||||
if (OB_FAIL(locator.get_lob_data_byte_len(size))) {
|
||||
LOG_WARN("get lob data byte length failed", K(ret), K(locator));
|
||||
} else if (size > INT32_MAX) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("size overflow", K(ret), K(size), K(locator));
|
||||
} else {
|
||||
res.set_int32(size);
|
||||
}
|
||||
} else {
|
||||
uint64_t size = 0;
|
||||
common::ObString j_str = data.get_string();
|
||||
|
Loading…
x
Reference in New Issue
Block a user