[ARRAY] fix array prepare_allocate failed
This commit is contained in:
parent
24962e3cee
commit
e69d21839f
54
deps/oblib/src/lib/udt/ob_array_type.cpp
vendored
54
deps/oblib/src/lib/udt/ob_array_type.cpp
vendored
@ -467,10 +467,13 @@ int ret = OB_SUCCESS;
|
||||
const uint32_t src_data_offset = begin * sizeof(float);
|
||||
int64_t curr_pos = data_container_->raw_data_.size();
|
||||
int64_t capacity = curr_pos + len;
|
||||
data_container_->raw_data_.prepare_allocate(capacity);
|
||||
char *cur_data = reinterpret_cast<char *>(data_container_->raw_data_.get_data() + curr_pos);
|
||||
MEMCPY(cur_data, src.get_data() + src_data_offset, len * sizeof(float));
|
||||
length_ += len;
|
||||
if (OB_FAIL(data_container_->raw_data_.prepare_allocate(capacity))) {
|
||||
OB_LOG(WARN, "allocate memory failed", K(ret), K(capacity));
|
||||
} else {
|
||||
char *cur_data = reinterpret_cast<char *>(data_container_->raw_data_.get_data() + curr_pos);
|
||||
MEMCPY(cur_data, src.get_data() + src_data_offset, len * sizeof(float));
|
||||
length_ += len;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -585,28 +588,31 @@ int ObArrayBinary::insert_from(const ObIArrayType &src, uint32_t begin, uint32_t
|
||||
uint32_t src_len = src.get_offsets()[begin + len - 1] - src_offset;
|
||||
int64_t curr_pos = data_container_->raw_data_.size();
|
||||
int64_t capacity = curr_pos + src_len;
|
||||
data_container_->raw_data_.prepare_allocate(capacity);
|
||||
char *cur_data = data_container_->raw_data_.get_data() + curr_pos;
|
||||
MEMCPY(cur_data, src.get_data() + src_offset, src_len);
|
||||
// insert offsets
|
||||
uint32_t last_offset = src_offset;
|
||||
uint32_t pre_max_offset = data_container_->offset_at(length_);
|
||||
for (uint32_t i = 0; i < len && OB_SUCC(ret); ++i) {
|
||||
if (OB_FAIL(data_container_->offsets_.push_back(pre_max_offset + src.get_offsets()[begin + i] - last_offset))) {
|
||||
OB_LOG(WARN, "failed to push value to array data", K(ret));
|
||||
} else {
|
||||
last_offset = src.get_offsets()[begin + i];
|
||||
pre_max_offset = data_container_->offset_at(data_container_->offsets_.size());
|
||||
if (OB_FAIL(data_container_->raw_data_.prepare_allocate(capacity))) {
|
||||
OB_LOG(WARN, "allocate memory failed", K(ret), K(capacity));
|
||||
} else {
|
||||
char *cur_data = data_container_->raw_data_.get_data() + curr_pos;
|
||||
MEMCPY(cur_data, src.get_data() + src_offset, src_len);
|
||||
// insert offsets
|
||||
uint32_t last_offset = src_offset;
|
||||
uint32_t pre_max_offset = data_container_->offset_at(length_);
|
||||
for (uint32_t i = 0; i < len && OB_SUCC(ret); ++i) {
|
||||
if (OB_FAIL(data_container_->offsets_.push_back(pre_max_offset + src.get_offsets()[begin + i] - last_offset))) {
|
||||
OB_LOG(WARN, "failed to push value to array data", K(ret));
|
||||
} else {
|
||||
last_offset = src.get_offsets()[begin + i];
|
||||
pre_max_offset = data_container_->offset_at(data_container_->offsets_.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
// insert nullbitmaps
|
||||
for (uint32_t i = 0; i < len && OB_SUCC(ret); ++i) {
|
||||
if (OB_FAIL(data_container_->null_bitmaps_.push_back(src.get_nullbitmap()[begin + i]))) {
|
||||
OB_LOG(WARN, "failed to push null", K(ret));
|
||||
// insert nullbitmaps
|
||||
for (uint32_t i = 0; i < len && OB_SUCC(ret); ++i) {
|
||||
if (OB_FAIL(data_container_->null_bitmaps_.push_back(src.get_nullbitmap()[begin + i]))) {
|
||||
OB_LOG(WARN, "failed to push null", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
length_ += len;
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
length_ += len;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
51
deps/oblib/src/lib/udt/ob_array_type.h
vendored
51
deps/oblib/src/lib/udt/ob_array_type.h
vendored
@ -144,9 +144,12 @@ public :
|
||||
} else {
|
||||
int64_t curr_pos = data_container_->null_bitmaps_.size();
|
||||
int64_t capacity = curr_pos + length;
|
||||
data_container_->null_bitmaps_.prepare_allocate(capacity);
|
||||
uint8_t *cur_null_bitmap = data_container_->null_bitmaps_.get_data() + curr_pos;
|
||||
MEMCPY(cur_null_bitmap, nulls, length * sizeof(uint8_t));
|
||||
if (OB_FAIL(data_container_->null_bitmaps_.prepare_allocate(capacity))) {
|
||||
OB_LOG(WARN, "allocate memory failed", K(ret), K(capacity));
|
||||
} else {
|
||||
uint8_t *cur_null_bitmap = data_container_->null_bitmaps_.get_data() + curr_pos;
|
||||
MEMCPY(cur_null_bitmap, nulls, length * sizeof(uint8_t));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -159,9 +162,12 @@ public :
|
||||
} else {
|
||||
int64_t curr_pos = data_container_->offsets_.size();
|
||||
int64_t capacity = curr_pos + length;
|
||||
data_container_->offsets_.prepare_allocate(capacity);
|
||||
char *cur_offsets = reinterpret_cast<char *>(data_container_->offsets_.get_data() + curr_pos * sizeof(uint32_t));
|
||||
MEMCPY(cur_offsets, offsets, length * sizeof(uint32_t));
|
||||
if (OB_FAIL(data_container_->offsets_.prepare_allocate(capacity))) {
|
||||
OB_LOG(WARN, "allocate memory failed", K(ret), K(capacity));
|
||||
} else {
|
||||
char *cur_offsets = reinterpret_cast<char *>(data_container_->offsets_.get_data() + curr_pos * sizeof(uint32_t));
|
||||
MEMCPY(cur_offsets, offsets, length * sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -174,8 +180,11 @@ public :
|
||||
} else {
|
||||
int64_t curr_pos = data_container_->raw_data_.size();
|
||||
int64_t capacity = curr_pos + length;
|
||||
data_container_->raw_data_.prepare_allocate(capacity);
|
||||
data = reinterpret_cast<T *>(data_container_->raw_data_.get_data() + curr_pos);
|
||||
if (OB_FAIL(data_container_->raw_data_.prepare_allocate(capacity))) {
|
||||
OB_LOG(WARN, "allocate memory failed", K(ret), K(capacity));
|
||||
} else {
|
||||
data = reinterpret_cast<T *>(data_container_->raw_data_.get_data() + curr_pos);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -470,16 +479,22 @@ public :
|
||||
const uint32_t src_null_offset = begin * sizeof(uint8_t);
|
||||
int64_t curr_pos = this->data_container_->raw_data_.size();
|
||||
int64_t capacity = curr_pos + len;
|
||||
this->data_container_->raw_data_.prepare_allocate(capacity);
|
||||
char *cur_data = reinterpret_cast<char *>(this->data_container_->raw_data_.get_data() + curr_pos);
|
||||
MEMCPY(cur_data, src.get_data() + src_data_offset, len * sizeof(T));
|
||||
// insert nullbitmaps
|
||||
curr_pos = this->data_container_->null_bitmaps_.size();
|
||||
capacity = curr_pos + len;
|
||||
this->data_container_->null_bitmaps_.prepare_allocate(capacity);
|
||||
uint8_t *cur_null_bitmap = this->data_container_->null_bitmaps_.get_data() + curr_pos;
|
||||
MEMCPY(cur_null_bitmap, src.get_nullbitmap() + src_null_offset, len * sizeof(uint8_t));
|
||||
this->length_ += len;
|
||||
if (OB_FAIL(this->data_container_->raw_data_.prepare_allocate(capacity))) {
|
||||
OB_LOG(WARN, "allocate memory failed", K(ret), K(capacity));
|
||||
} else {
|
||||
char *cur_data = reinterpret_cast<char *>(this->data_container_->raw_data_.get_data() + curr_pos);
|
||||
MEMCPY(cur_data, src.get_data() + src_data_offset, len * sizeof(T));
|
||||
// insert nullbitmaps
|
||||
curr_pos = this->data_container_->null_bitmaps_.size();
|
||||
capacity = curr_pos + len;
|
||||
if (OB_FAIL(this->data_container_->null_bitmaps_.prepare_allocate(capacity))) {
|
||||
OB_LOG(WARN, "allocate memory failed", K(ret), K(capacity));
|
||||
} else {
|
||||
uint8_t *cur_null_bitmap = this->data_container_->null_bitmaps_.get_data() + curr_pos;
|
||||
MEMCPY(cur_null_bitmap, src.get_nullbitmap() + src_null_offset, len * sizeof(uint8_t));
|
||||
this->length_ += len;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user