amorynan commented on code in PR #52676:
URL: https://github.com/apache/doris/pull/52676#discussion_r2180279203
##########
be/src/vec/data_types/serde/data_type_bitmap_serde.cpp:
##########
@@ -194,23 +194,41 @@ Status DataTypeBitMapSerDe::write_column_to_orc(const
std::string& timezone, con
std::vector<StringRef>&
buffer_list) const {
auto& col_data = assert_cast<const ColumnBitmap&>(column);
orc::StringVectorBatch* cur_batch =
dynamic_cast<orc::StringVectorBatch*>(orc_col_batch);
-
- INIT_MEMORY_FOR_ORC_WRITER()
-
+ // First pass: calculate total memory needed and collect serialized values
+ size_t total_size = 0;
for (size_t row_id = start; row_id < end; row_id++) {
if (cur_batch->notNull[row_id] == 1) {
auto bitmap_value =
const_cast<BitmapValue&>(col_data.get_element(row_id));
size_t len = bitmap_value.getSizeInBytes();
-
- REALLOC_MEMORY_FOR_ORC_WRITER()
-
+ total_size += len;
+ }
+ }
+ // Allocate continues memory based on calculated size
+ char* ptr = (char*)malloc(total_size);
+ if (!ptr) {
+ return Status::InternalError(
+ "malloc memory error when write variant column data to orc
file.");
+ }
+ StringRef bufferRef;
+ bufferRef.data = ptr;
+ bufferRef.size = total_size;
+ buffer_list.emplace_back(bufferRef);
+ // Second pass: copy data to allocated memory
+ size_t offset = 0;
+ for (size_t row_id = start; row_id < end; row_id++) {
+ if (cur_batch->notNull[row_id] == 1) {
+ auto bitmap_value =
const_cast<BitmapValue&>(col_data.get_element(row_id));
+ size_t len = bitmap_value.getSizeInBytes();
+ if (offset > total_size) {
+ return Status::InternalError(
+ "offset exceeds total size when write variant column
data to orc file.");
Review Comment:
yes I rewrite it
##########
be/src/vec/data_types/serde/data_type_hll_serde.cpp:
##########
@@ -189,23 +189,41 @@ Status DataTypeHLLSerDe::write_column_to_orc(const
std::string& timezone, const
std::vector<StringRef>&
buffer_list) const {
auto& col_data = assert_cast<const ColumnHLL&>(column);
orc::StringVectorBatch* cur_batch =
dynamic_cast<orc::StringVectorBatch*>(orc_col_batch);
-
- INIT_MEMORY_FOR_ORC_WRITER()
-
+ // First pass: calculate total memory needed and collect serialized values
+ size_t total_size = 0;
for (size_t row_id = start; row_id < end; row_id++) {
if (cur_batch->notNull[row_id] == 1) {
auto hll_value =
const_cast<HyperLogLog&>(col_data.get_element(row_id));
size_t len = hll_value.max_serialized_size();
-
- REALLOC_MEMORY_FOR_ORC_WRITER()
-
+ total_size += len;
+ }
+ }
+ // Allocate continues memory based on calculated size
+ char* ptr = (char*)malloc(total_size);
+ if (!ptr) {
+ return Status::InternalError(
+ "malloc memory error when write variant column data to orc
file.");
+ }
+ StringRef bufferRef;
+ bufferRef.data = ptr;
+ bufferRef.size = total_size;
+ buffer_list.emplace_back(bufferRef);
+ // Second pass: copy data to allocated memory
+ size_t offset = 0;
+ for (size_t row_id = start; row_id < end; row_id++) {
+ if (cur_batch->notNull[row_id] == 1) {
+ auto hll_value =
const_cast<HyperLogLog&>(col_data.get_element(row_id));
+ size_t len = hll_value.max_serialized_size();
+ if (offset > total_size) {
+ return Status::InternalError(
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]