imay commented on a change in pull request #764: Convert next_row interface to
next_block
URL: https://github.com/apache/incubator-doris/pull/764#discussion_r266238144
##########
File path: be/src/olap/rowset/alpha_rowset_reader.cpp
##########
@@ -54,65 +54,46 @@ OLAPStatus AlphaRowsetReader::init(RowsetReaderContext*
read_context) {
_dst_cursor = new(std::nothrow)RowCursor();
_dst_cursor->init(*(_current_read_context->tablet_schema));
OLAPStatus status = _init_column_datas(read_context);
- return status;
-}
-
-bool AlphaRowsetReader::has_next() {
- bool next_flag = false;
- for (int i = 0; i < _column_datas.size(); ++i) {
- auto& row_block = _row_blocks[i];
- if (row_block != nullptr) {
- if (row_block->has_remaining()) {
- next_flag = true;
- } else {
- OLAPStatus status = _get_next_block(i, &_row_blocks[i]);
- if (status == OLAP_ERR_DATA_EOF) {
- _row_blocks[i] = nullptr;
- continue;
- } else if (status != OLAP_SUCCESS) {
- LOG(WARNING) << "_get_next_block failed, status:" <<
status;
- return false;
- } else {
- if (_row_blocks[i] != nullptr &&
_row_blocks[i]->has_remaining()) {
- next_flag = true;
- }
- }
- }
+ if (!_is_cumulative_rowset) {
+ _read_block.reset(new RowBlock(_current_read_context->tablet_schema));
+ if (_read_block == nullptr) {
+ LOG(WARNING) << "new row block failed in reader";
+ return OLAP_ERR_MALLOC_ERROR;
}
- }
- return next_flag;
-}
-
-OLAPStatus AlphaRowsetReader::next(RowCursor** row) {
- OLAPStatus status = OLAP_SUCCESS;
- if (_is_cumulative_rowset) {
- status = _get_next_row_for_cumulative_rowset(row);
- } else {
- status = _get_next_row_for_singleton_rowset(row);
+ RowBlockInfo block_info;
+ block_info.row_num =
_current_read_context->tablet_schema->num_rows_per_row_block();
+ block_info.null_supported = true;
+ _read_block->init(block_info);
+ _dst_cursor = new(std::nothrow)RowCursor();
+ _dst_cursor->init(*(_current_read_context->tablet_schema));
}
return status;
}
-OLAPStatus AlphaRowsetReader::next_block(std::shared_ptr<RowBlock> block) {
- block->clear();
+OLAPStatus AlphaRowsetReader::next_block(RowBlock** block) {
size_t num_rows_in_block = 0;
- while (block->pos() < _num_rows_per_row_block) {
- RowCursor* row_cursor = nullptr;
- OLAPStatus status = next(&row_cursor);
- if (status == OLAP_ERR_DATA_EOF && block->pos() > 0) {
- break;
- } else if (status != OLAP_SUCCESS) {
- LOG(WARNING) << "next block failed.status:" << status;
- return status;
+ if (_is_cumulative_rowset) {
Review comment:
You can use a function pointer which points to real `next` function, and
this pointer can be set in init function. Then in this function, you don't
need this if statement which can reduce CPU execution and branches.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]