[CP] [CP] [Bugfix] cherry-pick bugfix from 421 for obkv

This commit is contained in:
WeiXinChan
2024-01-11 12:14:28 +00:00
committed by ob-robot
parent bc445d6721
commit 6716958634
33 changed files with 663 additions and 247 deletions

View File

@ -14,7 +14,6 @@
#include "ob_table.h"
#include "share/ob_errno.h"
#include "lib/utility/ob_unify_serialize.h"
#include "common/row/ob_row.h"
#include "rpc/obrpc/ob_rpc_packet.h"
#include "sql/engine/expr/ob_expr_lob_utils.h"
@ -1471,44 +1470,65 @@ int ObTableQueryResult::alloc_buf_if_need(const int64_t need_size)
int ObTableQueryResult::add_row(const ObNewRow &row)
{
int ret = OB_SUCCESS;
ret = alloc_buf_if_need(row.get_serialize_size());
// 1. check properties count and row count
const int64_t N = row.get_count();
if (OB_SUCC(ret)) {
if (0 != properties_names_.count()
&& N != properties_names_.count()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("cell count not match with property count", K(ret), K(N),
"properties_count", properties_names_.count());
}
}
for (int i = 0; OB_SUCCESS == ret && i < N; ++i)
{
// Output of TableApi does not have lob locator header, remove lob header before serialize.
// Functions defined by DEF_TEXT_SERIALIZE_FUNCS is called here, refer to ob_obj_funcs.h
ObObjType type = row.get_cell(i).get_type();
if (is_lob_storage(type)) {
ObObj tmp_obj = row.get_cell(i);
ObString read_data;
if (tmp_obj.has_lob_header()) {
if (OB_FAIL(sql::ObTextStringHelper::read_real_string_data(&allocator_, tmp_obj, read_data))) {
LOG_WARN("failed to get obj", K(ret), K_(buf));
} else {
tmp_obj.set_lob_value(type, read_data.ptr(), read_data.length());
if (0 != properties_names_.count()
&& N != properties_names_.count()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("cell count not match with property count", K(ret), K(N),
"properties_count", properties_names_.count());
} else {
// 2. construct new row
ObNewRow new_row = row;
ObObj *lob_cells = nullptr;
const int64_t lob_storage_count = get_lob_storage_count(new_row);
if (lob_storage_count != 0) {
if (OB_ISNULL(lob_cells = static_cast<ObObj*>(allocator_.alloc(sizeof(ObObj) * lob_storage_count)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to alloc cells buffer", K(ret), K(lob_storage_count));
}
for (int i = 0, lob_cell_idx = 0; OB_SUCC(ret) && i < N; ++i) {
const ObObj &cell = new_row.get_cell(i);
ObObjType type = cell.get_type();
if (is_lob_storage(type)) {
ObString real_data;
if (cell.has_lob_header()) {
if (OB_FAIL(sql::ObTextStringHelper::read_real_string_data(&allocator_, cell, real_data))) {
LOG_WARN("fail to read real string date", K(ret), K(cell));
} else if (lob_cell_idx >= lob_storage_count) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected index count", K(ret), K(lob_cell_idx), K(lob_storage_count));
} else {
lob_cells[lob_cell_idx].set_lob_value(type, real_data.ptr(), real_data.length());
lob_cells[lob_cell_idx].set_collation_type(cell.get_collation_type());
new_row.get_cell(i) = lob_cells[lob_cell_idx]; // switch lob cell
lob_cell_idx++;
}
}
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(tmp_obj.serialize(buf_.get_data(), buf_.get_capacity(), buf_.get_position()))) {
LOG_WARN("failed to serialize obj", K(ret), K_(buf));
}
} else {
}
// 3. alloc serialize size
int64_t size = new_row.get_serialize_size();
if (OB_FAIL(ret)) {
} else if (OB_FAIL(alloc_buf_if_need(size))) {
LOG_WARN("failed to alloc buff", K(ret), K(size));
}
// 4. serialize
for (int i = 0; OB_SUCC(ret) && i < N; ++i) {
if (OB_FAIL(row.get_cell(i).serialize(buf_.get_data(), buf_.get_capacity(), buf_.get_position()))) {
LOG_WARN("failed to serialize obj", K(ret), K_(buf));
}
}
} // end for
}
if (OB_SUCC(ret)) {
++row_count_;
}
return ret;
}