@@ -1394,6 +1394,33 @@ Status SegmentIterator::_read_columns_by_index(uint32_t nrows_read_limit, uint32
13941394 return Status::OK ();
13951395}
13961396
1397+ void SegmentIterator::_replace_version_col (size_t num_rows) {
1398+ // Only the rowset with single version need to replace the version column.
1399+ // Doris can't determine the version before publish_version finished, so
1400+ // we can't write data to __DORIS_VERSION_COL__ in segment writer, the value
1401+ // is 0 by default.
1402+ // So we need to replace the value to real version while reading.
1403+ if (_opts.version .first != _opts.version .second ) {
1404+ return ;
1405+ }
1406+ auto cids = _schema.column_ids ();
1407+ int32_t version_idx = _schema.version_col_idx ();
1408+ auto iter = std::find (cids.begin (), cids.end (), version_idx);
1409+ if (iter == cids.end ()) {
1410+ return ;
1411+ }
1412+
1413+ auto column_desc = _schema.column (version_idx);
1414+ auto column = Schema::get_data_type_ptr (*column_desc)->create_column ();
1415+ DCHECK (_schema.column (version_idx)->type () == FieldType::OLAP_FIELD_TYPE_BIGINT );
1416+ auto col_ptr = reinterpret_cast <vectorized::ColumnVector<vectorized::Int64>*>(column.get ());
1417+ for (size_t j = 0 ; j < num_rows; j++) {
1418+ col_ptr->insert_value (_opts.version .second );
1419+ }
1420+ _current_return_columns[version_idx] = std::move (column);
1421+ VLOG_DEBUG << " replaced version column in segment iterator, version_col_idx:" << version_idx;
1422+ }
1423+
13971424uint16_t SegmentIterator::_evaluate_vectorization_predicate (uint16_t * sel_rowid_idx,
13981425 uint16_t selected_size) {
13991426 SCOPED_RAW_TIMER (&_opts.stats ->vec_cond_ns );
@@ -1559,6 +1586,7 @@ Status SegmentIterator::next_batch(vectorized::Block* block) {
15591586 }
15601587
15611588 if (!_is_need_vec_eval && !_is_need_short_eval) {
1589+ _replace_version_col (_current_batch_rows_read);
15621590 _output_non_pred_columns (block);
15631591 _output_index_result_column (nullptr , 0 , block);
15641592 } else {
@@ -1586,6 +1614,7 @@ Status SegmentIterator::next_batch(vectorized::Block* block) {
15861614 if (!_lazy_materialization_read) {
15871615 Status ret = Status::OK ();
15881616 if (selected_size > 0 ) {
1617+ _replace_version_col (selected_size);
15891618 ret = _output_column_by_sel_idx (block, _first_read_column_ids, sel_rowid_idx,
15901619 selected_size);
15911620 }
@@ -1606,6 +1635,8 @@ Status SegmentIterator::next_batch(vectorized::Block* block) {
16061635 sel_rowid_idx, selected_size,
16071636 &_current_return_columns));
16081637
1638+ _replace_version_col (selected_size);
1639+
16091640 // step4: output columns
16101641 // 4.1 output non-predicate column
16111642 _output_non_pred_columns (block);
0 commit comments