morningman commented on code in PR #9088:
URL: https://github.com/apache/incubator-doris/pull/9088#discussion_r857743923


##########
be/src/olap/rowset/beta_rowset_writer.cpp:
##########
@@ -99,6 +99,71 @@ Status BetaRowsetWriter::init(const RowsetWriterContext& 
rowset_writer_context)
     return Status::OK();
 }
 
+Status 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 Status::OK();
+    }
+    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 <= 0 || segment_capacity_in_rows <= 
0)) {
+        // no space for another single row, need flush now
+        RETURN_NOT_OK(_flush_segment_writer(&_segment_writer));
+        RETURN_NOT_OK(_create_segment_writer(&_segment_writer));
+        refresh_segment_capacity();
+    }
+
+    if (block_size_in_bytes > segment_capacity_in_bytes ||
+        block_row_num > segment_capacity_in_rows) {
+        size_t segment_max_row_num;
+        size_t input_row_num;
+        do {
+            assert(row_offset < block_row_num);
+            segment_max_row_num =
+                    std::max(std::min((size_t)segment_capacity_in_bytes / 
row_avg_size_in_bytes,
+                             (size_t)segment_capacity_in_rows), (size_t)1);
+            input_row_num = std::min(segment_max_row_num, block_row_num - 
row_offset);
+            assert(input_row_num > 0);

Review Comment:
   ```suggestion
               CHECK(input_row_num > 0);
   ```



##########
be/src/olap/rowset/segment_v2/segment_writer.h:
##########
@@ -83,6 +88,9 @@ class SegmentWriter {
     Status _write_footer();
     Status _write_raw_data(const std::vector<Slice>& slices);
 
+    std::string encode_short_keys(const std::vector<const void*> 
key_column_fields,

Review Comment:
   ```suggestion
       std::string encode_short_keys(const std::vector<const void*>& 
key_column_fields,
   ```



##########
be/src/olap/rowset/segment_v2/segment_writer.h:
##########
@@ -97,6 +105,11 @@ class SegmentWriter {
     std::vector<std::unique_ptr<ColumnWriter>> _column_writers;
     std::shared_ptr<MemTracker> _mem_tracker;
     uint32_t _row_count = 0;
+
+    vectorized::OlapBlockDataConvertor _olap_data_convertor;
+    std::vector< const KeyCoder* > _short_key_coders;

Review Comment:
   ```suggestion
       std::vector<const KeyCoder*> _short_key_coders;
   ```



##########
be/src/olap/rowset/beta_rowset_writer.cpp:
##########
@@ -99,6 +99,71 @@ Status BetaRowsetWriter::init(const RowsetWriterContext& 
rowset_writer_context)
     return Status::OK();
 }
 
+Status 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 Status::OK();
+    }
+    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 <= 0 || segment_capacity_in_rows <= 
0)) {
+        // no space for another single row, need flush now
+        RETURN_NOT_OK(_flush_segment_writer(&_segment_writer));
+        RETURN_NOT_OK(_create_segment_writer(&_segment_writer));
+        refresh_segment_capacity();
+    }
+
+    if (block_size_in_bytes > segment_capacity_in_bytes ||
+        block_row_num > segment_capacity_in_rows) {
+        size_t segment_max_row_num;
+        size_t input_row_num;
+        do {
+            assert(row_offset < block_row_num);

Review Comment:
   ```suggestion
               CHECK(row_offset < block_row_num);
   ```



##########
be/src/olap/rowset/beta_rowset_writer.cpp:
##########
@@ -99,6 +99,71 @@ Status BetaRowsetWriter::init(const RowsetWriterContext& 
rowset_writer_context)
     return Status::OK();
 }
 
+Status 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 Status::OK();
+    }
+    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 <= 0 || segment_capacity_in_rows <= 
0)) {
+        // no space for another single row, need flush now
+        RETURN_NOT_OK(_flush_segment_writer(&_segment_writer));
+        RETURN_NOT_OK(_create_segment_writer(&_segment_writer));
+        refresh_segment_capacity();
+    }
+
+    if (block_size_in_bytes > segment_capacity_in_bytes ||
+        block_row_num > segment_capacity_in_rows) {
+        size_t segment_max_row_num;
+        size_t input_row_num;
+        do {
+            assert(row_offset < block_row_num);

Review Comment:
   Use CHECK instead of assert, same as others



##########
be/src/olap/rowset/segment_v2/segment_writer.h:
##########
@@ -97,6 +105,11 @@ class SegmentWriter {
     std::vector<std::unique_ptr<ColumnWriter>> _column_writers;
     std::shared_ptr<MemTracker> _mem_tracker;
     uint32_t _row_count = 0;
+
+    vectorized::OlapBlockDataConvertor _olap_data_convertor;
+    std::vector< const KeyCoder* > _short_key_coders;
+    std::vector< uint16_t > _short_key_index_size;

Review Comment:
   ```suggestion
       std::vector<uint16_t> _short_key_index_size;
   ```



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to