@@ -86,6 +86,14 @@ Status OlapScanner::prepare(
8686 LOG (WARNING ) << ss.str ();
8787 return Status::InternalError (ss.str ());
8888 }
89+ _tablet_schema = _tablet->tablet_schema ();
90+ if (!_parent->_olap_scan_node .columns_desc .empty () &&
91+ _parent->_olap_scan_node .columns_desc [0 ].col_unique_id >= 0 ) {
92+ _tablet_schema.clear_columns ();
93+ for (const auto & column_desc : _parent->_olap_scan_node .columns_desc ) {
94+ _tablet_schema.append_column (TabletColumn (column_desc));
95+ }
96+ }
8997 {
9098 std::shared_lock rdlock (_tablet->get_header_lock ());
9199 const RowsetSharedPtr rowset = _tablet->rowset_with_max_version ();
@@ -150,6 +158,7 @@ Status OlapScanner::_init_tablet_reader_params(
150158 RETURN_IF_ERROR (_init_return_columns ());
151159
152160 _tablet_reader_params.tablet = _tablet;
161+ _tablet_reader_params.tablet_schema = &_tablet_schema;
153162 _tablet_reader_params.reader_type = READER_QUERY ;
154163 _tablet_reader_params.aggregation = _aggregation;
155164 _tablet_reader_params.version = Version (0 , _version);
@@ -207,7 +216,7 @@ Status OlapScanner::_init_tablet_reader_params(
207216 _tablet_reader_params.return_columns .push_back (i);
208217 }
209218 for (auto index : _return_columns) {
210- if (_tablet-> tablet_schema () .column (index).is_key ()) {
219+ if (_tablet_schema .column (index).is_key ()) {
211220 continue ;
212221 } else {
213222 _tablet_reader_params.return_columns .push_back (index);
@@ -216,13 +225,12 @@ Status OlapScanner::_init_tablet_reader_params(
216225 }
217226
218227 // use _tablet_reader_params.return_columns, because reader use this to merge sort
219- Status res =
220- _read_row_cursor.init (_tablet->tablet_schema (), _tablet_reader_params.return_columns );
228+ Status res = _read_row_cursor.init (_tablet_schema, _tablet_reader_params.return_columns );
221229 if (!res.ok ()) {
222230 LOG (WARNING ) << " fail to init row cursor.res = " << res;
223231 return Status::InternalError (" failed to initialize storage read row cursor" );
224232 }
225- _read_row_cursor.allocate_memory_for_string_type (_tablet-> tablet_schema () );
233+ _read_row_cursor.allocate_memory_for_string_type (_tablet_schema );
226234
227235 // If a agg node is this scan node direct parent
228236 // we will not call agg object finalize method in scan node,
@@ -241,30 +249,31 @@ Status OlapScanner::_init_return_columns() {
241249 if (!slot->is_materialized ()) {
242250 continue ;
243251 }
244- int32_t index = _tablet->field_index (slot->col_name ());
252+ int32_t index = slot->col_unique_id () >= 0 ? slot->col_unique_id ()
253+ : _tablet_schema.field_index (slot->col_name ());
245254 if (index < 0 ) {
246255 std::stringstream ss;
247256 ss << " field name is invalid. field=" << slot->col_name ();
248257 LOG (WARNING ) << ss.str ();
249258 return Status::InternalError (ss.str ());
250259 }
251260 _return_columns.push_back (index);
252- if (slot->is_nullable () && !_tablet-> tablet_schema () .column (index).is_nullable ())
261+ if (slot->is_nullable () && !_tablet_schema .column (index).is_nullable ())
253262 _tablet_columns_convert_to_null_set.emplace (index);
254263 _query_slots.push_back (slot);
255264 }
256265
257266 // expand the sequence column
258- if (_tablet-> tablet_schema () .has_sequence_col ()) {
267+ if (_tablet_schema .has_sequence_col ()) {
259268 bool has_replace_col = false ;
260269 for (auto col : _return_columns) {
261- if (_tablet-> tablet_schema () .column (col).aggregation () ==
270+ if (_tablet_schema .column (col).aggregation () ==
262271 FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE ) {
263272 has_replace_col = true ;
264273 break ;
265274 }
266275 }
267- if (auto sequence_col_idx = _tablet-> tablet_schema () .sequence_col_idx ();
276+ if (auto sequence_col_idx = _tablet_schema .sequence_col_idx ();
268277 has_replace_col && std::find (_return_columns.begin (), _return_columns.end (),
269278 sequence_col_idx) == _return_columns.end ()) {
270279 _return_columns.push_back (sequence_col_idx);
0 commit comments