kangpinghuang 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_r268632037
##########
File path: be/src/olap/rowset/alpha_rowset_reader.cpp
##########
@@ -51,71 +43,66 @@ OLAPStatus AlphaRowsetReader::init(RowsetReaderContext*
read_context) {
if (_current_read_context->stats != nullptr) {
_stats = _current_read_context->stats;
}
- _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;
- }
- }
- }
+ Version version = _alpha_rowset_meta->version();
+ _is_singleton_rowset = (version.first == version.second);
+ _ordinal = 0;
+ bool merge = false;
+ /*
+ * For singleton rowset, there exists three situations.
+ * 1. QUERY task will set preaggregation.
+ * If preaggregation is set to be true
+ * there is not necessary to merge row in advance.
+ * 2. QEURY task for DUP_KEYS tablet has no necessities
+ * to merge row in advance.
+ * 2. COMPACTION/CHECKSUM/ALTER_TABLET task should merge
+ * row in advance.
+ * For cumulative rowset, there are no necessities to merge row in advance.
+ */
+ RETURN_NOT_OK(_init_merge_ctxs(read_context));
+ if (_is_singleton_rowset && _merge_ctxs.size() > 1) {
+ if (_current_read_context->reader_type == READER_QUERY
+ && _current_read_context->preaggregation) {
+ // 1. QUERY task which set pregaggregation to be true
+ _next_block = &AlphaRowsetReader::_union_block;
+ } else if (_current_read_context->reader_type == READER_QUERY
+ && _current_read_context->tablet_schema->keys_type() ==
DUP_KEYS) {
+ // 2. QUERY task for DUP_KEYS tablet
+ _next_block = &AlphaRowsetReader::_union_block;
+ } else {
+ // 3. COMPACTION/CHECKSUM/ALTER_TABLET task
+ _next_block = &AlphaRowsetReader::_merge_block;
+ merge = true;
}
- }
- 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);
+ // query task to scan cumulative rowset
+ _next_block = &AlphaRowsetReader::_union_block;
}
- return status;
-}
-OLAPStatus AlphaRowsetReader::next_block(std::shared_ptr<RowBlock> block) {
- block->clear();
- 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 (merge) {
+ _read_block.reset(new (std::nothrow)
RowBlock(_current_read_context->tablet_schema));
+ if (_read_block == nullptr) {
+ LOG(WARNING) << "new row block failed in reader";
+ return OLAP_ERR_MALLOC_ERROR;
+ }
+ 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();
Review comment:
add if (_dst_cursor == nullptr)
----------------------------------------------------------------
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]