Gabriel39 commented on code in PR #8438:
URL: https://github.com/apache/incubator-doris/pull/8438#discussion_r848534364
##########
be/src/olap/rowset/beta_rowset_writer.cpp:
##########
@@ -88,6 +88,75 @@ OLAPStatus BetaRowsetWriter::init(const RowsetWriterContext&
rowset_writer_conte
return OLAP_SUCCESS;
}
+OLAPStatus BetaRowsetWriter::add_block(const vectorized::Block* block) {
+ if (UNLIKELY(_segment_writer == nullptr)) {
+ RETURN_NOT_OK(_create_segment_writer(&_segment_writer));
+ }
+ size_t block_size_in_bytes = block->bytes();
+ size_t block_row_num = block->rows();
+ if (UNLIKELY(block_row_num == 0)) {
+ return OLAP_SUCCESS;
+ }
+ size_t row_avg_size_in_bytes = std::max((size_t)1, block_size_in_bytes /
block_row_num);
+ size_t row_offset = 0;
+ int64_t segment_capacity_in_bytes = 0;
+ int64_t segment_capacity_in_rows = 0;
+ auto refresh_segment_capacity = [&]() {
+ segment_capacity_in_bytes =
+ (int64_t)MAX_SEGMENT_SIZE -
(int64_t)_segment_writer->estimate_segment_size();
+ segment_capacity_in_rows = (int64_t)_context.max_rows_per_segment -
+
(int64_t)_segment_writer->num_rows_written();
+ };
+
+ refresh_segment_capacity();
+ if (UNLIKELY(segment_capacity_in_bytes < row_avg_size_in_bytes ||
+ segment_capacity_in_rows <= 0)) {
+ // no space for another signle row, need flush now
Review Comment:
```suggestion
// no space for another single row, need flush now
```
--
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]