Coverage Report

Created: 2026-06-12 03:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/segment/column_reader.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "storage/segment/column_reader.h"
19
20
#include <assert.h>
21
#include <gen_cpp/Descriptors_types.h>
22
#include <gen_cpp/segment_v2.pb.h>
23
#include <glog/logging.h>
24
25
#include <algorithm>
26
#include <memory>
27
#include <ostream>
28
#include <set>
29
#include <utility>
30
31
#include "common/compiler_util.h" // IWYU pragma: keep
32
#include "common/status.h"
33
#include "core/assert_cast.h"
34
#include "core/binary_cast.hpp"
35
#include "core/column/column.h"
36
#include "core/column/column_array.h"
37
#include "core/column/column_map.h"
38
#include "core/column/column_nullable.h"
39
#include "core/column/column_struct.h"
40
#include "core/column/column_vector.h"
41
#include "core/data_type/data_type_agg_state.h"
42
#include "core/data_type/data_type_factory.hpp"
43
#include "core/data_type/data_type_nullable.h"
44
#include "core/data_type/define_primitive_type.h"
45
#include "core/decimal12.h"
46
#include "core/string_ref.h"
47
#include "core/types.h"
48
#include "core/value/decimalv2_value.h"
49
#include "core/value/vdatetime_value.h" //for VecDateTime
50
#include "io/fs/file_reader.h"
51
#include "storage/index/ann/ann_index_reader.h"
52
#include "storage/index/bloom_filter/bloom_filter.h"
53
#include "storage/index/bloom_filter/bloom_filter_index_reader.h"
54
#include "storage/index/index_file_reader.h"
55
#include "storage/index/index_reader.h"
56
#include "storage/index/inverted/analyzer/analyzer.h"
57
#include "storage/index/inverted/inverted_index_reader.h"
58
#include "storage/index/zone_map/zone_map_index.h"
59
#include "storage/iterators.h"
60
#include "storage/olap_common.h"
61
#include "storage/predicate/block_column_predicate.h"
62
#include "storage/predicate/column_predicate.h"
63
#include "storage/segment/binary_dict_page.h" // for BinaryDictPageDecoder
64
#include "storage/segment/binary_plain_page.h"
65
#include "storage/segment/column_meta_accessor.h"
66
#include "storage/segment/encoding_info.h" // for EncodingInfo
67
#include "storage/segment/page_decoder.h"
68
#include "storage/segment/page_handle.h" // for PageHandle
69
#include "storage/segment/page_io.h"
70
#include "storage/segment/page_pointer.h" // for PagePointer
71
#include "storage/segment/row_ranges.h"
72
#include "storage/segment/segment.h"
73
#include "storage/segment/segment_prefetcher.h"
74
#include "storage/segment/variant/variant_column_reader.h"
75
#include "storage/tablet/tablet_schema.h"
76
#include "storage/types.h" // for TypeInfo
77
#include "util/bitmap.h"
78
#include "util/block_compression.h"
79
#include "util/concurrency_stats.h"
80
#include "util/defer_op.h"
81
#include "util/rle_encoding.h" // for RleDecoder
82
#include "util/slice.h"
83
84
namespace doris::segment_v2 {
85
#include "storage/segment/column_reader.h"
86
87
26
inline bool read_as_string(PrimitiveType type) {
88
26
    return type == PrimitiveType::TYPE_STRING || type == PrimitiveType::INVALID_TYPE ||
89
26
           type == PrimitiveType::TYPE_BITMAP || type == PrimitiveType::TYPE_FIXED_LENGTH_OBJECT;
90
26
}
91
92
Status ColumnReader::create_array(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
93
                                  const io::FileReaderSPtr& file_reader,
94
17.4k
                                  std::shared_ptr<ColumnReader>* reader) {
95
17.4k
    DCHECK(meta.children_columns_size() == 2 || meta.children_columns_size() == 3);
96
97
17.4k
    std::shared_ptr<ColumnReader> item_reader;
98
17.4k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(0),
99
17.4k
                                         meta.children_columns(0).num_rows(), file_reader,
100
17.4k
                                         &item_reader));
101
102
17.4k
    std::shared_ptr<ColumnReader> offset_reader;
103
17.4k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(1),
104
17.4k
                                         meta.children_columns(1).num_rows(), file_reader,
105
17.4k
                                         &offset_reader));
106
107
17.4k
    std::shared_ptr<ColumnReader> null_reader;
108
17.4k
    if (meta.is_nullable()) {
109
15.5k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(2),
110
15.5k
                                             meta.children_columns(2).num_rows(), file_reader,
111
15.5k
                                             &null_reader));
112
15.5k
    }
113
114
    // The num rows of the array reader equals to the num rows of the length reader.
115
17.4k
    uint64_t array_num_rows = meta.children_columns(1).num_rows();
116
17.4k
    std::shared_ptr<ColumnReader> array_reader(
117
17.4k
            new ColumnReader(opts, meta, array_num_rows, file_reader));
118
    //  array reader do not need to init
119
17.4k
    array_reader->_sub_readers.resize(meta.children_columns_size());
120
17.4k
    array_reader->_sub_readers[0] = std::move(item_reader);
121
17.4k
    array_reader->_sub_readers[1] = std::move(offset_reader);
122
17.4k
    if (meta.is_nullable()) {
123
15.5k
        array_reader->_sub_readers[2] = std::move(null_reader);
124
15.5k
    }
125
17.4k
    array_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_ARRAY;
126
17.4k
    *reader = std::move(array_reader);
127
17.4k
    return Status::OK();
128
17.4k
}
129
130
Status ColumnReader::create_map(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
131
                                const io::FileReaderSPtr& file_reader,
132
8.94k
                                std::shared_ptr<ColumnReader>* reader) {
133
    // map reader now has 3 sub readers for key, value, offsets(scalar), null(scala)
134
8.94k
    DCHECK(meta.children_columns_size() == 3 || meta.children_columns_size() == 4);
135
8.94k
    std::shared_ptr<ColumnReader> key_reader;
136
8.94k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(0),
137
8.94k
                                         meta.children_columns(0).num_rows(), file_reader,
138
8.94k
                                         &key_reader));
139
8.94k
    std::shared_ptr<ColumnReader> val_reader;
140
8.94k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(1),
141
8.94k
                                         meta.children_columns(1).num_rows(), file_reader,
142
8.94k
                                         &val_reader));
143
8.94k
    std::shared_ptr<ColumnReader> offset_reader;
144
8.94k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(2),
145
8.94k
                                         meta.children_columns(2).num_rows(), file_reader,
146
8.94k
                                         &offset_reader));
147
8.94k
    std::shared_ptr<ColumnReader> null_reader;
148
8.94k
    if (meta.is_nullable()) {
149
3.84k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(3),
150
3.84k
                                             meta.children_columns(3).num_rows(), file_reader,
151
3.84k
                                             &null_reader));
152
3.84k
    }
153
154
    // The num rows of the map reader equals to the num rows of the length reader.
155
8.94k
    uint64_t map_num_rows = meta.children_columns(2).num_rows();
156
8.94k
    std::shared_ptr<ColumnReader> map_reader(
157
8.94k
            new ColumnReader(opts, meta, map_num_rows, file_reader));
158
8.94k
    map_reader->_sub_readers.resize(meta.children_columns_size());
159
160
8.94k
    map_reader->_sub_readers[0] = std::move(key_reader);
161
8.94k
    map_reader->_sub_readers[1] = std::move(val_reader);
162
8.94k
    map_reader->_sub_readers[2] = std::move(offset_reader);
163
8.94k
    if (meta.is_nullable()) {
164
3.84k
        map_reader->_sub_readers[3] = std::move(null_reader);
165
3.84k
    }
166
8.94k
    map_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_MAP;
167
8.94k
    *reader = std::move(map_reader);
168
8.94k
    return Status::OK();
169
8.94k
}
170
171
Status ColumnReader::create_struct(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
172
                                   uint64_t num_rows, const io::FileReaderSPtr& file_reader,
173
5.20k
                                   std::shared_ptr<ColumnReader>* reader) {
174
    // not support empty struct
175
5.20k
    DCHECK(meta.children_columns_size() >= 1);
176
    // create struct column reader
177
5.20k
    std::shared_ptr<ColumnReader> struct_reader(
178
5.20k
            new ColumnReader(opts, meta, num_rows, file_reader));
179
5.20k
    struct_reader->_sub_readers.reserve(meta.children_columns_size());
180
    // now we support struct column can add the children columns according to the schema-change behavior
181
28.9k
    for (int i = 0; i < meta.children_columns_size(); i++) {
182
23.7k
        std::shared_ptr<ColumnReader> sub_reader;
183
23.7k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(i),
184
23.7k
                                             meta.children_columns(i).num_rows(), file_reader,
185
23.7k
                                             &sub_reader));
186
23.7k
        struct_reader->_sub_readers.push_back(std::move(sub_reader));
187
23.7k
    }
188
5.20k
    struct_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_STRUCT;
189
5.20k
    *reader = std::move(struct_reader);
190
5.20k
    return Status::OK();
191
5.20k
}
192
193
Status ColumnReader::create_agg_state(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
194
                                      uint64_t num_rows, const io::FileReaderSPtr& file_reader,
195
26
                                      std::shared_ptr<ColumnReader>* reader) {
196
26
    if (!meta.has_function_name()) { // meet old version ColumnMetaPB
197
0
        std::shared_ptr<ColumnReader> reader_local(
198
0
                new ColumnReader(opts, meta, num_rows, file_reader));
199
0
        RETURN_IF_ERROR(reader_local->init(&meta));
200
0
        *reader = std::move(reader_local);
201
0
        return Status::OK();
202
0
    }
203
204
26
    auto data_type = DataTypeFactory::instance().create_data_type(meta);
205
26
    const auto* agg_state_type = assert_cast<const DataTypeAggState*>(data_type.get());
206
26
    agg_state_type->check_function_compatibility(opts.be_exec_version);
207
26
    auto type = agg_state_type->get_serialized_type()->get_primitive_type();
208
209
26
    if (read_as_string(type)) {
210
26
        std::shared_ptr<ColumnReader> reader_local(
211
26
                new ColumnReader(opts, meta, num_rows, file_reader));
212
26
        RETURN_IF_ERROR(reader_local->init(&meta));
213
26
        *reader = std::move(reader_local);
214
26
        return Status::OK();
215
26
    } else if (type == PrimitiveType::TYPE_MAP) {
216
0
        return create_map(opts, meta, file_reader, reader);
217
0
    } else if (type == PrimitiveType::TYPE_ARRAY) {
218
0
        return create_array(opts, meta, file_reader, reader);
219
0
    } else if (type == PrimitiveType::TYPE_STRUCT) {
220
0
        return create_struct(opts, meta, num_rows, file_reader, reader);
221
0
    }
222
223
0
    return Status::InternalError("Not supported type: {}, serialized type: {}",
224
0
                                 agg_state_type->get_name(), int(type));
225
26
}
226
227
42.8k
bool ColumnReader::is_compaction_reader_type(ReaderType type) {
228
42.8k
    return type == ReaderType::READER_BASE_COMPACTION ||
229
42.8k
           type == ReaderType::READER_CUMULATIVE_COMPACTION ||
230
42.8k
           type == ReaderType::READER_COLD_DATA_COMPACTION ||
231
42.8k
           type == ReaderType::READER_SEGMENT_COMPACTION ||
232
42.8k
           type == ReaderType::READER_FULL_COMPACTION;
233
42.8k
}
234
235
Status ColumnReader::create(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
236
                            uint64_t num_rows, const io::FileReaderSPtr& file_reader,
237
1.29M
                            std::shared_ptr<ColumnReader>* reader) {
238
1.29M
    if (is_scalar_type((FieldType)meta.type())) {
239
1.25M
        std::shared_ptr<ColumnReader> reader_local(
240
1.25M
                new ColumnReader(opts, meta, num_rows, file_reader));
241
1.25M
        RETURN_IF_ERROR(reader_local->init(&meta));
242
1.25M
        *reader = std::move(reader_local);
243
1.25M
        return Status::OK();
244
1.25M
    } else {
245
33.6k
        auto type = (FieldType)meta.type();
246
33.6k
        switch (type) {
247
26
        case FieldType::OLAP_FIELD_TYPE_AGG_STATE: {
248
26
            return create_agg_state(opts, meta, num_rows, file_reader, reader);
249
0
        }
250
5.20k
        case FieldType::OLAP_FIELD_TYPE_STRUCT: {
251
5.20k
            return create_struct(opts, meta, num_rows, file_reader, reader);
252
0
        }
253
17.4k
        case FieldType::OLAP_FIELD_TYPE_ARRAY: {
254
17.4k
            return create_array(opts, meta, file_reader, reader);
255
0
        }
256
8.94k
        case FieldType::OLAP_FIELD_TYPE_MAP: {
257
8.94k
            return create_map(opts, meta, file_reader, reader);
258
0
        }
259
1.98k
        case FieldType::OLAP_FIELD_TYPE_VARIANT: {
260
            // Read variant only root data using a single ColumnReader
261
1.98k
            std::shared_ptr<ColumnReader> reader_local(
262
1.98k
                    new ColumnReader(opts, meta, num_rows, file_reader));
263
1.98k
            RETURN_IF_ERROR(reader_local->init(&meta));
264
1.98k
            *reader = std::move(reader_local);
265
1.98k
            return Status::OK();
266
1.98k
        }
267
0
        default:
268
0
            return Status::NotSupported("unsupported type for ColumnReader: {}",
269
0
                                        std::to_string(int(type)));
270
33.6k
        }
271
33.6k
    }
272
1.29M
}
273
274
2.01k
ColumnReader::ColumnReader() = default;
275
276
ColumnReader::ColumnReader(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
277
                           uint64_t num_rows, io::FileReaderSPtr file_reader)
278
1.29M
        : _use_index_page_cache(!config::disable_storage_page_cache),
279
1.29M
          _opts(opts),
280
1.29M
          _num_rows(num_rows),
281
1.29M
          _file_reader(std::move(file_reader)),
282
1.29M
          _dict_encoding_type(UNKNOWN_DICT_ENCODING) {
283
1.29M
    _meta_length = meta.length();
284
1.29M
    _meta_type = (FieldType)meta.type();
285
1.29M
    if (_meta_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
286
17.4k
        _meta_children_column_type = (FieldType)meta.children_columns(0).type();
287
17.4k
    }
288
1.29M
    _data_type = DataTypeFactory::instance().create_data_type(meta);
289
1.29M
    _meta_is_nullable = meta.is_nullable();
290
1.29M
    _meta_dict_page = meta.dict_page();
291
1.29M
    _meta_compression = meta.compression();
292
1.29M
}
293
294
1.23M
ColumnReader::~ColumnReader() = default;
295
296
1.25M
int64_t ColumnReader::get_metadata_size() const {
297
1.25M
    return sizeof(ColumnReader) + (_segment_zone_map ? _segment_zone_map->ByteSizeLong() : 0);
298
1.25M
}
299
300
#ifdef BE_TEST
301
/// This function is only used in UT to verify the correctness of data read from zone map
302
/// See UT case 'SegCompactionMoWTest.SegCompactionInterleaveWithBig_ooooOOoOooooooooO'
303
/// be/test/olap/segcompaction_mow_test.cpp
304
void ColumnReader::check_data_by_zone_map_for_test(const MutableColumnPtr& dst) const {
305
    if (!_segment_zone_map) {
306
        return;
307
    }
308
309
    const auto rows = dst->size();
310
    if (rows == 0) {
311
        return;
312
    }
313
314
    FieldType type = _type;
315
316
    if (type != FieldType::OLAP_FIELD_TYPE_INT) {
317
        return;
318
    }
319
320
    auto* non_nullable_column =
321
            dst->is_nullable()
322
                    ? assert_cast<ColumnNullable*>(dst.get())->get_nested_column_ptr().get()
323
                    : dst.get();
324
325
    /// `PredicateColumnType<TYPE_INT>` does not support `void get(size_t n, Field& res)`,
326
    /// So here only check `CoumnVector<TYPE_INT>`
327
    if (check_and_get_column<ColumnVector<TYPE_INT>>(non_nullable_column) == nullptr) {
328
        return;
329
    }
330
331
    ZoneMap zone_map;
332
    THROW_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
333
334
    if (zone_map.has_null) {
335
        return;
336
    }
337
338
    for (size_t i = 0; i != rows; ++i) {
339
        Field field;
340
        dst->get(i, field);
341
        DCHECK(!field.is_null());
342
        const auto v = field.get<TYPE_INT>();
343
        DCHECK_GE(v, zone_map.min_value.get<TYPE_INT>());
344
        DCHECK_LE(v, zone_map.max_value.get<TYPE_INT>());
345
    }
346
}
347
#endif
348
349
1.25M
Status ColumnReader::init(const ColumnMetaPB* meta) {
350
1.25M
    _type = (FieldType)meta->type();
351
352
1.25M
    if (meta->has_be_exec_version()) {
353
1.17M
        _be_exec_version = meta->be_exec_version();
354
1.17M
    }
355
356
1.25M
    if (_type == FieldType::OLAP_FIELD_TYPE_NONE || _type == FieldType::OLAP_FIELD_TYPE_UNKNOWN) {
357
0
        return Status::NotSupported("unsupported typeinfo, type={}", meta->type());
358
0
    }
359
1.25M
    RETURN_IF_ERROR(EncodingInfo::get(_type, meta->encoding(), &_encoding_info));
360
361
3.63M
    for (int i = 0; i < meta->indexes_size(); i++) {
362
2.37M
        const auto& index_meta = meta->indexes(i);
363
2.37M
        switch (index_meta.type()) {
364
0
        case BITMAP_INDEX:
365
0
            break;
366
1.24M
        case ORDINAL_INDEX:
367
1.24M
            _ordinal_index.reset(
368
1.24M
                    new OrdinalIndexReader(_file_reader, _num_rows, index_meta.ordinal_index()));
369
1.24M
            break;
370
1.13M
        case ZONE_MAP_INDEX:
371
1.13M
            _segment_zone_map =
372
1.13M
                    std::make_unique<ZoneMapPB>(index_meta.zone_map_index().segment_zone_map());
373
1.13M
            _zone_map_index.reset(new ZoneMapIndexReader(
374
1.13M
                    _file_reader, index_meta.zone_map_index().page_zone_maps()));
375
1.13M
            break;
376
145
        case BLOOM_FILTER_INDEX:
377
145
            _bloom_filter_index.reset(
378
145
                    new BloomFilterIndexReader(_file_reader, index_meta.bloom_filter_index()));
379
145
            break;
380
0
        case NESTED_OFFSETS_INDEX:
381
0
            break;
382
0
        default:
383
0
            return Status::Corruption("Bad file {}: invalid column index type {}",
384
0
                                      _file_reader->path().native(), index_meta.type());
385
2.37M
        }
386
2.37M
    }
387
1.25M
    update_metadata_size();
388
389
    // ArrayColumnWriter writes a single empty array and flushes. In this scenario,
390
    // the item writer doesn't write any data and the corresponding ordinal index is empty.
391
1.25M
    if (_ordinal_index == nullptr && !is_empty()) {
392
0
        return Status::Corruption("Bad file {}: missing ordinal index for column {}",
393
0
                                  _file_reader->path().native(), meta->column_id());
394
0
    }
395
396
1.25M
    return Status::OK();
397
1.25M
}
398
399
Status ColumnReader::new_index_iterator(const std::shared_ptr<IndexFileReader>& index_file_reader,
400
                                        const TabletIndex* index_meta, const std::string& rowset_id,
401
                                        uint32_t segment_id, size_t rows_of_segment,
402
32.4k
                                        std::unique_ptr<IndexIterator>* iterator) {
403
32.4k
    RETURN_IF_ERROR(
404
32.4k
            _load_index(index_file_reader, index_meta, rowset_id, segment_id, rows_of_segment));
405
32.4k
    {
406
32.4k
        std::shared_lock<std::shared_mutex> rlock(_load_index_lock);
407
32.4k
        auto iter = _index_readers.find(index_meta->index_id());
408
32.5k
        if (iter != _index_readers.end()) {
409
32.5k
            if (iter->second != nullptr) {
410
32.5k
                RETURN_IF_ERROR(iter->second->new_iterator(iterator));
411
32.5k
            }
412
32.5k
        }
413
32.4k
    }
414
32.4k
    return Status::OK();
415
32.4k
}
416
417
Status ColumnReader::read_page(const ColumnIteratorOptions& iter_opts, const PagePointer& pp,
418
                               PageHandle* handle, Slice* page_body, PageFooterPB* footer,
419
600k
                               BlockCompressionCodec* codec) const {
420
600k
    SCOPED_CONCURRENCY_COUNT(ConcurrencyStatsManager::instance().column_reader_read_page);
421
600k
    iter_opts.sanity_check();
422
600k
    PageReadOptions opts(iter_opts.io_ctx);
423
600k
    opts.verify_checksum = _opts.verify_checksum;
424
600k
    opts.use_page_cache = iter_opts.use_page_cache;
425
600k
    opts.kept_in_memory = _opts.kept_in_memory;
426
600k
    opts.type = iter_opts.type;
427
600k
    opts.file_reader = iter_opts.file_reader;
428
600k
    opts.page_pointer = pp;
429
600k
    opts.codec = codec;
430
600k
    opts.stats = iter_opts.stats;
431
600k
    opts.encoding_info = _encoding_info;
432
433
600k
    return PageIO::read_and_decompress_page(opts, handle, page_body, footer);
434
600k
}
435
436
Status ColumnReader::get_row_ranges_by_zone_map(
437
        const AndBlockColumnPredicate* col_predicates,
438
        const std::vector<std::shared_ptr<const ColumnPredicate>>* delete_predicates,
439
44.7k
        RowRanges* row_ranges, const ColumnIteratorOptions& iter_opts) {
440
44.7k
    std::vector<uint32_t> page_indexes;
441
44.7k
    RETURN_IF_ERROR(
442
44.7k
            _get_filtered_pages(col_predicates, delete_predicates, &page_indexes, iter_opts));
443
44.7k
    RETURN_IF_ERROR(_calculate_row_ranges(page_indexes, row_ranges, iter_opts));
444
44.7k
    return Status::OK();
445
44.7k
}
446
447
1.25k
Status ColumnReader::next_batch_of_zone_map(size_t* n, MutableColumnPtr& dst) const {
448
1.25k
    if (_segment_zone_map == nullptr) {
449
0
        return Status::InternalError("segment zonemap not exist");
450
0
    }
451
    // TODO: this work to get min/max value seems should only do once
452
1.25k
    ZoneMap zone_map;
453
1.25k
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
454
455
1.25k
    dst->reserve(*n);
456
1.25k
    if (!zone_map.has_not_null) {
457
13
        assert_cast<ColumnNullable&>(*dst).insert_many_defaults(*n);
458
13
        return Status::OK();
459
13
    }
460
1.24k
    dst->insert(zone_map.max_value);
461
2.49k
    for (int i = 1; i < *n; ++i) {
462
1.24k
        dst->insert(zone_map.min_value);
463
1.24k
    }
464
1.24k
    return Status::OK();
465
1.25k
}
466
467
Status ColumnReader::match_condition(const AndBlockColumnPredicate* col_predicates,
468
470k
                                     bool* matched) const {
469
470k
    *matched = true;
470
470k
    if (_zone_map_index == nullptr) {
471
0
        return Status::OK();
472
0
    }
473
470k
    ZoneMap zone_map;
474
470k
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
475
476
470k
    *matched = _zone_map_match_condition(zone_map, col_predicates);
477
470k
    return Status::OK();
478
470k
}
479
480
Status ColumnReader::prune_predicates_by_zone_map(
481
        std::vector<std::shared_ptr<ColumnPredicate>>& predicates, const int column_id,
482
5.45M
        bool* pruned) const {
483
5.45M
    *pruned = false;
484
5.45M
    if (_zone_map_index == nullptr) {
485
7.60k
        return Status::OK();
486
7.60k
    }
487
488
5.45M
    ZoneMap zone_map;
489
5.45M
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
490
5.45M
    if (zone_map.pass_all) {
491
0
        return Status::OK();
492
0
    }
493
494
11.0M
    for (auto it = predicates.begin(); it != predicates.end();) {
495
5.61M
        auto predicate = *it;
496
5.61M
        if (predicate->column_id() == column_id && predicate->is_always_true(zone_map)) {
497
3.77k
            *pruned = true;
498
3.77k
            it = predicates.erase(it);
499
5.61M
        } else {
500
5.61M
            ++it;
501
5.61M
        }
502
5.61M
    }
503
5.45M
    return Status::OK();
504
5.45M
}
505
506
bool ColumnReader::_zone_map_match_condition(const ZoneMap& zone_map,
507
521k
                                             const AndBlockColumnPredicate* col_predicates) const {
508
521k
    if (zone_map.pass_all) {
509
0
        return true;
510
0
    }
511
512
521k
    return col_predicates->evaluate_and(zone_map);
513
521k
}
514
515
Status ColumnReader::_get_filtered_pages(
516
        const AndBlockColumnPredicate* col_predicates,
517
        const std::vector<std::shared_ptr<const ColumnPredicate>>* delete_predicates,
518
44.8k
        std::vector<uint32_t>* page_indexes, const ColumnIteratorOptions& iter_opts) {
519
44.8k
    RETURN_IF_ERROR(_load_zone_map_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
520
521
44.8k
    const std::vector<ZoneMapPB>& zone_maps = _zone_map_index->page_zone_maps();
522
44.8k
    size_t page_size = _zone_map_index->num_pages();
523
113k
    for (size_t i = 0; i < page_size; ++i) {
524
68.2k
        if (zone_maps[i].pass_all()) {
525
16.5k
            page_indexes->push_back(cast_set<uint32_t>(i));
526
51.7k
        } else {
527
51.7k
            segment_v2::ZoneMap zone_map;
528
51.7k
            RETURN_IF_ERROR(ZoneMap::from_proto(zone_maps[i], _data_type, zone_map));
529
51.7k
            if (_zone_map_match_condition(zone_map, col_predicates)) {
530
51.4k
                bool should_read = true;
531
51.4k
                if (delete_predicates != nullptr) {
532
0
                    for (auto del_pred : *delete_predicates) {
533
                        // TODO: Both `min_value` and `max_value` should be 0 or neither should be 0.
534
                        //  So nullable only need to judge once.
535
0
                        if (del_pred->evaluate_del(zone_map)) {
536
0
                            should_read = false;
537
0
                            break;
538
0
                        }
539
0
                    }
540
0
                }
541
51.4k
                if (should_read) {
542
51.4k
                    page_indexes->push_back(cast_set<uint32_t>(i));
543
51.4k
                }
544
51.4k
            }
545
51.7k
        }
546
68.2k
    }
547
18.4E
    VLOG(1) << "total-pages: " << page_size << " not-filtered-pages: " << page_indexes->size()
548
18.4E
            << " filtered-percent:"
549
18.4E
            << 1.0 - (static_cast<double>(page_indexes->size()) /
550
18.4E
                      (static_cast<double>(page_size) * 1.0));
551
44.8k
    return Status::OK();
552
44.8k
}
553
554
Status ColumnReader::_calculate_row_ranges(const std::vector<uint32_t>& page_indexes,
555
                                           RowRanges* row_ranges,
556
44.8k
                                           const ColumnIteratorOptions& iter_opts) {
557
44.8k
    row_ranges->clear();
558
44.8k
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
559
68.0k
    for (auto i : page_indexes) {
560
68.0k
        ordinal_t page_first_id = _ordinal_index->get_first_ordinal(i);
561
68.0k
        ordinal_t page_last_id = _ordinal_index->get_last_ordinal(i);
562
68.0k
        RowRanges page_row_ranges(RowRanges::create_single(page_first_id, page_last_id + 1));
563
68.0k
        RowRanges::ranges_union(*row_ranges, page_row_ranges, row_ranges);
564
68.0k
    }
565
44.8k
    return Status::OK();
566
44.8k
}
567
568
Status ColumnReader::get_row_ranges_by_bloom_filter(const AndBlockColumnPredicate* col_predicates,
569
                                                    RowRanges* row_ranges,
570
4
                                                    const ColumnIteratorOptions& iter_opts) {
571
4
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
572
4
    RETURN_IF_ERROR(
573
4
            _load_bloom_filter_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
574
4
    RowRanges bf_row_ranges;
575
4
    std::unique_ptr<BloomFilterIndexIterator> bf_iter;
576
4
    RETURN_IF_ERROR(_bloom_filter_index->new_iterator(&bf_iter, iter_opts.stats));
577
4
    size_t range_size = row_ranges->range_size();
578
    // get covered page ids
579
4
    std::set<uint32_t> page_ids;
580
9
    for (int i = 0; i < range_size; ++i) {
581
5
        int64_t from = row_ranges->get_range_from(i);
582
5
        int64_t idx = from;
583
5
        int64_t to = row_ranges->get_range_to(i);
584
5
        auto iter = _ordinal_index->seek_at_or_before(from);
585
10
        while (idx < to && iter.valid()) {
586
5
            page_ids.insert(iter.page_index());
587
5
            idx = iter.last_ordinal() + 1;
588
5
            iter.next();
589
5
        }
590
5
    }
591
5
    for (auto& pid : page_ids) {
592
5
        std::unique_ptr<BloomFilter> bf;
593
5
        RETURN_IF_ERROR(bf_iter->read_bloom_filter(pid, &bf));
594
5
        if (col_predicates->evaluate_and(bf.get())) {
595
5
            bf_row_ranges.add(RowRange(_ordinal_index->get_first_ordinal(pid),
596
5
                                       _ordinal_index->get_last_ordinal(pid) + 1));
597
5
        }
598
5
    }
599
4
    RowRanges::ranges_intersection(*row_ranges, bf_row_ranges, row_ranges);
600
4
    return Status::OK();
601
4
}
602
603
Status ColumnReader::_load_ordinal_index(bool use_page_cache, bool kept_in_memory,
604
510k
                                         const ColumnIteratorOptions& iter_opts) {
605
510k
    if (!_ordinal_index) {
606
0
        return Status::InternalError("ordinal_index not inited");
607
0
    }
608
510k
    return _ordinal_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
609
510k
}
610
611
Status ColumnReader::_load_zone_map_index(bool use_page_cache, bool kept_in_memory,
612
44.8k
                                          const ColumnIteratorOptions& iter_opts) {
613
44.8k
    if (_zone_map_index != nullptr) {
614
44.8k
        return _zone_map_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
615
44.8k
    }
616
18.4E
    return Status::OK();
617
44.8k
}
618
619
42
Status ColumnReader::get_segment_zone_map(segment_v2::ZoneMap* zone_map) const {
620
42
    DORIS_CHECK(zone_map != nullptr);
621
42
    DORIS_CHECK(_segment_zone_map != nullptr);
622
42
    return ZoneMap::from_proto(*_segment_zone_map, _data_type, *zone_map);
623
42
}
624
625
Status ColumnReader::get_page_zone_maps(const ColumnIteratorOptions& iter_opts,
626
33
                                        const std::vector<ZoneMapPB>** zone_maps) {
627
33
    DORIS_CHECK(zone_maps != nullptr);
628
33
    if (_zone_map_index == nullptr) {
629
0
        *zone_maps = nullptr;
630
0
        return Status::OK();
631
0
    }
632
33
    RETURN_IF_ERROR(_load_zone_map_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
633
33
    *zone_maps = &_zone_map_index->page_zone_maps();
634
33
    return Status::OK();
635
33
}
636
637
Status ColumnReader::get_row_range_for_page(uint32_t page_index,
638
                                            const ColumnIteratorOptions& iter_opts,
639
484
                                            RowRange* row_range) {
640
484
    DORIS_CHECK(row_range != nullptr);
641
484
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
642
484
    DORIS_CHECK(page_index < _ordinal_index->num_data_pages());
643
484
    *row_range = RowRange(_ordinal_index->get_first_ordinal(page_index),
644
484
                          _ordinal_index->get_last_ordinal(page_index) + 1);
645
484
    return Status::OK();
646
484
}
647
648
Status ColumnReader::_load_index(const std::shared_ptr<IndexFileReader>& index_file_reader,
649
                                 const TabletIndex* index_meta, const std::string& rowset_id,
650
32.4k
                                 uint32_t segment_id, size_t rows_of_segment) {
651
32.4k
    std::unique_lock<std::shared_mutex> wlock(_load_index_lock);
652
653
32.4k
    if (index_meta == nullptr) {
654
0
        return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
655
0
                "Failed to load inverted index: index metadata is null");
656
0
    }
657
658
32.4k
    auto it = _index_readers.find(index_meta->index_id());
659
32.4k
    if (it != _index_readers.end()) {
660
5.73k
        return Status::OK();
661
5.73k
    }
662
663
26.7k
    bool should_analyzer =
664
26.7k
            inverted_index::InvertedIndexAnalyzer::should_analyzer(index_meta->properties());
665
666
26.7k
    FieldType type;
667
26.7k
    if (_meta_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
668
1.60k
        type = _meta_children_column_type;
669
25.1k
    } else {
670
25.1k
        type = _type;
671
25.1k
    }
672
673
26.7k
    if (index_meta->index_type() == IndexType::ANN) {
674
1
        _index_readers[index_meta->index_id()] = std::make_shared<AnnIndexReader>(
675
1
                index_meta, index_file_reader, rowset_id, segment_id, rows_of_segment);
676
1
        return Status::OK();
677
1
    }
678
679
26.7k
    IndexReaderPtr index_reader;
680
681
26.7k
    if (is_string_type(type)) {
682
9.11k
        if (should_analyzer) {
683
3.77k
            try {
684
3.77k
                index_reader = FullTextIndexReader::create_shared(index_meta, index_file_reader);
685
3.77k
            } catch (const CLuceneError& e) {
686
0
                return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
687
0
                        "create FullTextIndexReader error: {}", e.what());
688
0
            }
689
5.34k
        } else {
690
5.34k
            try {
691
5.34k
                index_reader =
692
5.34k
                        StringTypeInvertedIndexReader::create_shared(index_meta, index_file_reader);
693
5.34k
            } catch (const CLuceneError& e) {
694
0
                return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
695
0
                        "create StringTypeInvertedIndexReader error: {}", e.what());
696
0
            }
697
5.34k
        }
698
17.6k
    } else if (is_numeric_type(type)) {
699
17.6k
        try {
700
17.6k
            index_reader = BkdIndexReader::create_shared(index_meta, index_file_reader);
701
17.6k
        } catch (const CLuceneError& e) {
702
0
            return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
703
0
                    "create BkdIndexReader error: {}", e.what());
704
0
        }
705
18.4E
    } else {
706
18.4E
        return Status::Error<ErrorCode::INVERTED_INDEX_NOT_SUPPORTED>(
707
18.4E
                "Field type {} is not supported for inverted index", type);
708
18.4E
    }
709
26.7k
    _index_readers[index_meta->index_id()] = index_reader;
710
26.7k
    return Status::OK();
711
26.7k
}
712
713
31.8k
bool ColumnReader::has_bloom_filter_index(bool ngram) const {
714
31.8k
    if (_bloom_filter_index == nullptr) return false;
715
716
18.4E
    if (ngram) {
717
0
        return _bloom_filter_index->algorithm() == BloomFilterAlgorithmPB::NGRAM_BLOOM_FILTER;
718
18.4E
    } else {
719
18.4E
        return _bloom_filter_index->algorithm() != BloomFilterAlgorithmPB::NGRAM_BLOOM_FILTER;
720
18.4E
    }
721
18.4E
}
722
723
Status ColumnReader::_load_bloom_filter_index(bool use_page_cache, bool kept_in_memory,
724
5
                                              const ColumnIteratorOptions& iter_opts) {
725
5
    if (_bloom_filter_index != nullptr) {
726
5
        return _bloom_filter_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
727
5
    }
728
0
    return Status::OK();
729
5
}
730
731
Status ColumnReader::seek_at_or_before(ordinal_t ordinal, OrdinalPageIndexIterator* iter,
732
465k
                                       const ColumnIteratorOptions& iter_opts) {
733
465k
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
734
465k
    *iter = _ordinal_index->seek_at_or_before(ordinal);
735
465k
    if (!iter->valid()) {
736
0
        return Status::NotFound("Failed to seek to ordinal {}, ", ordinal);
737
0
    }
738
465k
    return Status::OK();
739
465k
}
740
741
Status ColumnReader::get_ordinal_index_reader(OrdinalIndexReader*& reader,
742
87.9k
                                              OlapReaderStatistics* index_load_stats) {
743
18.4E
    CHECK(_ordinal_index) << fmt::format("ordinal index is null for column reader of type {}",
744
18.4E
                                         std::to_string(int(_meta_type)));
745
87.9k
    RETURN_IF_ERROR(
746
87.9k
            _ordinal_index->load(_use_index_page_cache, _opts.kept_in_memory, index_load_stats));
747
87.9k
    reader = _ordinal_index.get();
748
87.9k
    return Status::OK();
749
87.9k
}
750
751
141k
Status ColumnReader::new_iterator(ColumnIteratorUPtr* iterator, const TabletColumn* tablet_column) {
752
141k
    return new_iterator(iterator, tablet_column, nullptr);
753
141k
}
754
755
Status ColumnReader::new_iterator(ColumnIteratorUPtr* iterator, const TabletColumn* tablet_column,
756
6.23M
                                  const StorageReadOptions* opt) {
757
6.23M
    if (is_empty()) {
758
10.2k
        *iterator = std::make_unique<EmptyFileColumnIterator>();
759
10.2k
        return Status::OK();
760
10.2k
    }
761
6.22M
    if (is_scalar_type(_meta_type)) {
762
6.19M
        if (is_string_type(_meta_type)) {
763
3.67M
            *iterator = std::make_unique<StringFileColumnIterator>(shared_from_this());
764
3.67M
        } else {
765
2.52M
            *iterator = std::make_unique<FileColumnIterator>(shared_from_this());
766
2.52M
        }
767
6.19M
        (*iterator)->set_column_name(tablet_column ? tablet_column->name() : "");
768
6.19M
        return Status::OK();
769
6.19M
    } else {
770
31.9k
        auto type = _meta_type;
771
31.9k
        switch (type) {
772
66
        case FieldType::OLAP_FIELD_TYPE_AGG_STATE: {
773
66
            return new_agg_state_iterator(iterator);
774
0
        }
775
5.93k
        case FieldType::OLAP_FIELD_TYPE_STRUCT: {
776
5.93k
            return new_struct_iterator(iterator, tablet_column);
777
0
        }
778
18.1k
        case FieldType::OLAP_FIELD_TYPE_ARRAY: {
779
18.1k
            return new_array_iterator(iterator, tablet_column);
780
0
        }
781
9.40k
        case FieldType::OLAP_FIELD_TYPE_MAP: {
782
9.40k
            return new_map_iterator(iterator, tablet_column);
783
0
        }
784
0
        default:
785
0
            return Status::NotSupported("unsupported type to create iterator: {}",
786
0
                                        std::to_string(int(type)));
787
31.9k
        }
788
31.9k
    }
789
6.22M
}
790
791
66
Status ColumnReader::new_agg_state_iterator(ColumnIteratorUPtr* iterator) {
792
66
    *iterator = std::make_unique<FileColumnIterator>(shared_from_this());
793
66
    return Status::OK();
794
66
}
795
796
Status ColumnReader::new_array_iterator(ColumnIteratorUPtr* iterator,
797
18.1k
                                        const TabletColumn* tablet_column) {
798
18.1k
    ColumnIteratorUPtr item_iterator;
799
18.1k
    RETURN_IF_ERROR(_sub_readers[0]->new_iterator(
800
18.1k
            &item_iterator, tablet_column && tablet_column->get_subtype_count() > 0
801
18.1k
                                    ? &tablet_column->get_sub_column(0)
802
18.1k
                                    : nullptr));
803
804
18.1k
    item_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(0).name() : "");
805
806
18.1k
    ColumnIteratorUPtr offset_iterator;
807
18.1k
    RETURN_IF_ERROR(_sub_readers[1]->new_iterator(&offset_iterator, nullptr));
808
18.1k
    auto* file_iter = static_cast<FileColumnIterator*>(offset_iterator.release());
809
18.1k
    OffsetFileColumnIteratorUPtr ofcIter = std::make_unique<OffsetFileColumnIterator>(
810
18.1k
            std::unique_ptr<FileColumnIterator>(file_iter));
811
812
18.1k
    ColumnIteratorUPtr null_iterator;
813
18.1k
    if (is_nullable()) {
814
16.0k
        RETURN_IF_ERROR(_sub_readers[2]->new_iterator(&null_iterator, nullptr));
815
16.0k
    }
816
18.1k
    *iterator = std::make_unique<ArrayFileColumnIterator>(shared_from_this(), std::move(ofcIter),
817
18.1k
                                                          std::move(item_iterator),
818
18.1k
                                                          std::move(null_iterator));
819
18.1k
    return Status::OK();
820
18.1k
}
821
822
Status ColumnReader::new_map_iterator(ColumnIteratorUPtr* iterator,
823
9.40k
                                      const TabletColumn* tablet_column) {
824
9.40k
    ColumnIteratorUPtr key_iterator;
825
9.40k
    RETURN_IF_ERROR(_sub_readers[0]->new_iterator(
826
9.40k
            &key_iterator, tablet_column && tablet_column->get_subtype_count() > 1
827
9.40k
                                   ? &tablet_column->get_sub_column(0)
828
9.40k
                                   : nullptr));
829
9.40k
    key_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(0).name() : "");
830
9.40k
    ColumnIteratorUPtr val_iterator;
831
9.40k
    RETURN_IF_ERROR(_sub_readers[1]->new_iterator(
832
9.40k
            &val_iterator, tablet_column && tablet_column->get_subtype_count() > 1
833
9.40k
                                   ? &tablet_column->get_sub_column(1)
834
9.40k
                                   : nullptr));
835
9.40k
    val_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(1).name() : "");
836
9.40k
    ColumnIteratorUPtr offsets_iterator;
837
9.40k
    RETURN_IF_ERROR(_sub_readers[2]->new_iterator(&offsets_iterator, nullptr));
838
9.40k
    auto* file_iter = static_cast<FileColumnIterator*>(offsets_iterator.release());
839
9.40k
    OffsetFileColumnIteratorUPtr ofcIter = std::make_unique<OffsetFileColumnIterator>(
840
9.40k
            std::unique_ptr<FileColumnIterator>(file_iter));
841
842
9.40k
    ColumnIteratorUPtr null_iterator;
843
9.40k
    if (is_nullable()) {
844
4.15k
        RETURN_IF_ERROR(_sub_readers[3]->new_iterator(&null_iterator, nullptr));
845
4.15k
    }
846
9.40k
    *iterator = std::make_unique<MapFileColumnIterator>(
847
9.40k
            shared_from_this(), std::move(null_iterator), std::move(ofcIter),
848
9.40k
            std::move(key_iterator), std::move(val_iterator));
849
9.40k
    return Status::OK();
850
9.40k
}
851
852
Status ColumnReader::new_struct_iterator(ColumnIteratorUPtr* iterator,
853
5.93k
                                         const TabletColumn* tablet_column) {
854
5.93k
    std::vector<ColumnIteratorUPtr> sub_column_iterators;
855
5.93k
    size_t child_size = is_nullable() ? _sub_readers.size() - 1 : _sub_readers.size();
856
18.4E
    size_t tablet_column_size = tablet_column ? tablet_column->get_sub_columns().size() : 0;
857
5.93k
    sub_column_iterators.reserve(child_size);
858
859
26.7k
    for (uint64_t i = 0; i < child_size; i++) {
860
20.8k
        ColumnIteratorUPtr sub_column_iterator;
861
20.8k
        RETURN_IF_ERROR(_sub_readers[i]->new_iterator(
862
20.8k
                &sub_column_iterator, tablet_column ? &tablet_column->get_sub_column(i) : nullptr));
863
20.8k
        sub_column_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(i).name()
864
20.8k
                                                           : "");
865
20.8k
        sub_column_iterators.emplace_back(std::move(sub_column_iterator));
866
20.8k
    }
867
868
    // create default_iterator for schema-change behavior which increase column
869
7.23k
    for (size_t i = child_size; i < tablet_column_size; i++) {
870
1.30k
        TabletColumn column = tablet_column->get_sub_column(i);
871
1.30k
        ColumnIteratorUPtr it;
872
1.30k
        RETURN_IF_ERROR(Segment::new_default_iterator(column, &it));
873
1.30k
        it->set_column_name(column.name());
874
1.30k
        sub_column_iterators.emplace_back(std::move(it));
875
1.30k
    }
876
877
5.93k
    ColumnIteratorUPtr null_iterator;
878
5.93k
    if (is_nullable()) {
879
5.19k
        RETURN_IF_ERROR(_sub_readers[child_size]->new_iterator(&null_iterator, nullptr));
880
5.19k
    }
881
5.93k
    *iterator = std::make_unique<StructFileColumnIterator>(
882
5.93k
            shared_from_this(), std::move(null_iterator), std::move(sub_column_iterators));
883
5.93k
    return Status::OK();
884
5.93k
}
885
886
Result<TColumnAccessPaths> ColumnIterator::_get_sub_access_paths(
887
29.3k
        const TColumnAccessPaths& access_paths) {
888
29.3k
    TColumnAccessPaths sub_access_paths = access_paths;
889
45.0k
    for (auto it = sub_access_paths.begin(); it != sub_access_paths.end();) {
890
15.6k
        TColumnAccessPath& name_path = *it;
891
15.6k
        if (name_path.data_access_path.path.empty()) {
892
1
            return ResultError(
893
1
                    Status::InternalError("Invalid access path for struct column: path is empty"));
894
1
        }
895
896
15.6k
        if (!StringCaseEqual()(name_path.data_access_path.path[0], _column_name)) {
897
1
            return ResultError(Status::InternalError(
898
1
                    R"(Invalid access path for column: expected name "{}", got "{}")", _column_name,
899
1
                    name_path.data_access_path.path[0]));
900
1
        }
901
902
15.6k
        name_path.data_access_path.path.erase(name_path.data_access_path.path.begin());
903
15.6k
        if (!name_path.data_access_path.path.empty()) {
904
767
            ++it;
905
14.8k
        } else {
906
14.8k
            set_need_to_read();
907
14.8k
            it = sub_access_paths.erase(it);
908
14.8k
        }
909
15.6k
    }
910
29.3k
    return sub_access_paths;
911
29.3k
}
912
913
///====================== MapFileColumnIterator ============================////
914
MapFileColumnIterator::MapFileColumnIterator(std::shared_ptr<ColumnReader> reader,
915
                                             ColumnIteratorUPtr null_iterator,
916
                                             OffsetFileColumnIteratorUPtr offsets_iterator,
917
                                             ColumnIteratorUPtr key_iterator,
918
                                             ColumnIteratorUPtr val_iterator)
919
9.40k
        : _map_reader(reader),
920
9.40k
          _offsets_iterator(std::move(offsets_iterator)),
921
9.40k
          _key_iterator(std::move(key_iterator)),
922
9.40k
          _val_iterator(std::move(val_iterator)) {
923
9.40k
    if (_map_reader->is_nullable()) {
924
4.15k
        _null_iterator = std::move(null_iterator);
925
4.15k
    }
926
9.40k
}
927
928
9.39k
Status MapFileColumnIterator::init(const ColumnIteratorOptions& opts) {
929
9.39k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
930
8
        DLOG(INFO) << "Map column iterator column " << _column_name << " skip reading.";
931
8
        return Status::OK();
932
8
    }
933
9.38k
    RETURN_IF_ERROR(_key_iterator->init(opts));
934
9.38k
    RETURN_IF_ERROR(_val_iterator->init(opts));
935
9.38k
    RETURN_IF_ERROR(_offsets_iterator->init(opts));
936
9.38k
    if (_map_reader->is_nullable()) {
937
4.14k
        RETURN_IF_ERROR(_null_iterator->init(opts));
938
4.14k
    }
939
9.38k
    return Status::OK();
940
9.38k
}
941
942
4.38k
Status MapFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
943
4.38k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
944
0
        DLOG(INFO) << "Map column iterator column " << _column_name << " skip reading.";
945
0
        return Status::OK();
946
0
    }
947
948
4.38k
    if (read_null_map_only()) {
949
        // In NULL_MAP_ONLY mode, only seek the null iterator; skip offset/key/val iterators
950
0
        if (_map_reader->is_nullable() && _null_iterator) {
951
0
            RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
952
0
        }
953
0
        return Status::OK();
954
0
    }
955
956
4.38k
    if (_map_reader->is_nullable()) {
957
2.13k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
958
2.13k
    }
959
4.38k
    RETURN_IF_ERROR(_offsets_iterator->seek_to_ordinal(ord));
960
4.38k
    if (read_offset_only()) {
961
        // In OFFSET_ONLY mode, key/value iterators are SKIP_READING, no need to seek them
962
1
        return Status::OK();
963
1
    }
964
    // here to use offset info
965
4.38k
    ordinal_t offset = 0;
966
4.38k
    RETURN_IF_ERROR(_offsets_iterator->_peek_one_offset(&offset));
967
4.38k
    RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(offset));
968
4.38k
    RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(offset));
969
4.38k
    return Status::OK();
970
4.38k
}
971
972
979
Status MapFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
973
979
    RETURN_IF_ERROR(_offsets_iterator->init_prefetcher(params));
974
979
    if (_map_reader->is_nullable()) {
975
979
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
976
979
    }
977
979
    RETURN_IF_ERROR(_key_iterator->init_prefetcher(params));
978
979
    RETURN_IF_ERROR(_val_iterator->init_prefetcher(params));
979
979
    return Status::OK();
980
979
}
981
982
void MapFileColumnIterator::collect_prefetchers(
983
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
984
979
        PrefetcherInitMethod init_method) {
985
979
    _offsets_iterator->collect_prefetchers(prefetchers, init_method);
986
979
    if (_map_reader->is_nullable()) {
987
979
        _null_iterator->collect_prefetchers(prefetchers, init_method);
988
979
    }
989
    // the actual data pages to read of key/value column depends on the read result of offset column,
990
    // so we can't init prefetch blocks according to rowids, just prefetch all data blocks here.
991
979
    _key_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
992
979
    _val_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
993
979
}
994
995
4.38k
Status MapFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
996
4.38k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
997
0
        DLOG(INFO) << "Map column iterator column " << _column_name << " skip reading.";
998
0
        dst->insert_many_defaults(*n);
999
0
        return Status::OK();
1000
0
    }
1001
1002
4.38k
    if (read_null_map_only()) {
1003
        // NULL_MAP_ONLY mode: read null map, fill nested ColumnMap with empty defaults
1004
0
        DORIS_CHECK(dst->is_nullable());
1005
0
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
1006
0
        auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1007
0
        size_t num_read = *n;
1008
0
        if (_null_iterator) {
1009
0
            bool null_signs_has_null = false;
1010
0
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1011
0
            RETURN_IF_ERROR(
1012
0
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1013
0
        } else {
1014
            // schema-change: column became nullable but old segment has no null data
1015
0
            null_map_ptr->insert_many_vals(0, num_read);
1016
0
        }
1017
0
        DCHECK(num_read == *n);
1018
        // fill nested ColumnMap with empty (zero-element) maps
1019
0
        auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1020
0
                nullable_col.get_nested_column());
1021
0
        column_map.insert_many_defaults(num_read);
1022
0
        *has_null = true;
1023
0
        return Status::OK();
1024
0
    }
1025
1026
4.38k
    auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1027
4.38k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1028
4.38k
    auto column_offsets_ptr = IColumn::mutate(std::move(column_map.get_offsets_ptr()));
1029
4.38k
    Defer defer_offsets {[&] {
1030
4.38k
        auto typed_column_offsets_ptr = ColumnMap::COffsets::cast_to_column_mutptr(
1031
4.38k
                assert_cast<ColumnMap::COffsets*, TypeCheckOnRelease::DISABLE>(
1032
4.38k
                        column_offsets_ptr.get()));
1033
4.38k
        column_offsets_ptr = nullptr;
1034
4.38k
        column_map.get_offsets_ptr() = std::move(typed_column_offsets_ptr);
1035
4.38k
    }};
1036
4.38k
    bool offsets_has_null = false;
1037
4.38k
    ssize_t start = column_offsets_ptr->size();
1038
4.38k
    RETURN_IF_ERROR(_offsets_iterator->next_batch(n, column_offsets_ptr, &offsets_has_null));
1039
4.38k
    if (*n == 0) {
1040
0
        return Status::OK();
1041
0
    }
1042
4.38k
    auto& column_offsets = static_cast<ColumnArray::ColumnOffsets&>(*column_offsets_ptr);
1043
4.38k
    RETURN_IF_ERROR(_offsets_iterator->_calculate_offsets(start, column_offsets));
1044
4.38k
    DCHECK(column_offsets.get_data().back() >= column_offsets.get_data()[start - 1]);
1045
4.38k
    size_t num_items =
1046
4.38k
            column_offsets.get_data().back() - column_offsets.get_data()[start - 1]; // -1 is valid
1047
1048
4.38k
    if (num_items > 0) {
1049
3.76k
        auto key_ptr = IColumn::mutate(std::move(column_map.get_keys_ptr()));
1050
3.76k
        auto val_ptr = IColumn::mutate(std::move(column_map.get_values_ptr()));
1051
3.76k
        Defer defer_keys {[&] { column_map.get_keys_ptr() = std::move(key_ptr); }};
1052
3.76k
        Defer defer_values {[&] { column_map.get_values_ptr() = std::move(val_ptr); }};
1053
3.76k
        if (read_offset_only()) {
1054
            // OFFSET_ONLY mode: skip reading actual key/value data, fill with defaults
1055
1
            key_ptr->insert_many_defaults(num_items);
1056
1
            val_ptr->insert_many_defaults(num_items);
1057
3.76k
        } else {
1058
3.76k
            size_t num_read = num_items;
1059
3.76k
            bool key_has_null = false;
1060
3.76k
            bool val_has_null = false;
1061
3.76k
            RETURN_IF_ERROR(_key_iterator->next_batch(&num_read, key_ptr, &key_has_null));
1062
3.76k
            RETURN_IF_ERROR(_val_iterator->next_batch(&num_read, val_ptr, &val_has_null));
1063
3.76k
            DCHECK(num_read == num_items);
1064
3.76k
        }
1065
3.76k
    }
1066
1067
4.38k
    if (dst->is_nullable()) {
1068
2.13k
        size_t num_read = *n;
1069
2.13k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1070
        // in not-null to null linked-schemachange mode,
1071
        // actually we do not change dat data include meta in footer,
1072
        // so may dst from changed meta which is nullable but old data is not nullable,
1073
        // if so, we should set null_map to all null by default
1074
2.13k
        if (_null_iterator) {
1075
2.13k
            bool null_signs_has_null = false;
1076
2.13k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1077
2.13k
            RETURN_IF_ERROR(
1078
2.13k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1079
2.13k
        } else {
1080
0
            null_map_ptr->insert_many_vals(0, num_read);
1081
0
        }
1082
2.13k
        DCHECK(num_read == *n);
1083
2.13k
    }
1084
4.38k
    return Status::OK();
1085
4.38k
}
1086
1087
Status MapFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1088
5.35k
                                             MutableColumnPtr& dst) {
1089
5.35k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1090
1
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
1091
1
        dst->insert_many_defaults(count);
1092
1
        return Status::OK();
1093
1
    }
1094
1095
5.35k
    if (read_null_map_only()) {
1096
        // NULL_MAP_ONLY mode: read null map by rowids, fill nested ColumnMap with empty defaults
1097
0
        DORIS_CHECK(dst->is_nullable());
1098
0
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
1099
0
        if (_null_iterator) {
1100
0
            auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1101
0
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1102
0
            RETURN_IF_ERROR(_null_iterator->read_by_rowids(rowids, count, null_map_column));
1103
0
        } else {
1104
            // schema-change: column became nullable but old segment has no null data
1105
0
            auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1106
0
            null_map_ptr->insert_many_vals(0, count);
1107
0
        }
1108
        // fill nested ColumnMap with empty (zero-element) maps
1109
0
        auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1110
0
                nullable_col.get_nested_column());
1111
0
        column_map.insert_many_defaults(count);
1112
0
        return Status::OK();
1113
0
    }
1114
1115
5.35k
    if (count == 0) {
1116
0
        return Status::OK();
1117
0
    }
1118
    // resolve ColumnMap and nullable wrapper
1119
5.35k
    auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1120
5.35k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1121
5.35k
    auto offsets_ptr = IColumn::mutate(std::move(column_map.get_offsets_ptr()));
1122
5.35k
    Defer defer_offsets {[&] {
1123
5.35k
        auto typed_offsets_ptr = ColumnMap::COffsets::cast_to_column_mutptr(
1124
5.35k
                assert_cast<ColumnMap::COffsets*, TypeCheckOnRelease::DISABLE>(offsets_ptr.get()));
1125
5.35k
        offsets_ptr = nullptr;
1126
5.35k
        column_map.get_offsets_ptr() = std::move(typed_offsets_ptr);
1127
5.35k
    }};
1128
5.35k
    auto& offsets = static_cast<ColumnArray::ColumnOffsets&>(*offsets_ptr);
1129
5.35k
    size_t base = offsets.get_data().empty() ? 0 : offsets.get_data().back();
1130
1131
    // 1. bulk read null-map if nullable
1132
5.35k
    std::vector<uint8_t> null_mask; // 0: not null, 1: null
1133
5.35k
    if (_map_reader->is_nullable()) {
1134
        // For nullable map columns, the destination column must also be nullable.
1135
537
        if (UNLIKELY(!dst->is_nullable())) {
1136
0
            return Status::InternalError(
1137
0
                    "unexpected non-nullable destination column for nullable map reader");
1138
0
        }
1139
537
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1140
537
        size_t null_before = null_map_ptr->size();
1141
537
        auto* null_map_col = null_map_ptr.get();
1142
537
        MutableColumnPtr null_map_column = std::move(null_map_ptr);
1143
537
        RETURN_IF_ERROR(_null_iterator->read_by_rowids(rowids, count, null_map_column));
1144
        // extract a light-weight view to decide element reads
1145
537
        null_mask.reserve(count);
1146
48.9k
        for (size_t i = 0; i < count; ++i) {
1147
48.4k
            null_mask.push_back(null_map_col->get_element(null_before + i));
1148
48.4k
        }
1149
4.81k
    } else if (dst->is_nullable()) {
1150
        // in not-null to null linked-schemachange mode,
1151
        // actually we do not change dat data include meta in footer,
1152
        // so may dst from changed meta which is nullable but old data is not nullable,
1153
        // if so, we should set null_map to all null by default
1154
0
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1155
0
        null_map_ptr->insert_many_vals(0, count);
1156
0
    }
1157
1158
    // 2. bulk read start ordinals for requested rows
1159
5.35k
    MutableColumnPtr starts_col = ColumnOffset64::create();
1160
5.35k
    starts_col->reserve(count);
1161
5.35k
    RETURN_IF_ERROR(_offsets_iterator->read_by_rowids(rowids, count, starts_col));
1162
1163
    // 3. bulk read next-start ordinals for rowid+1 (within bounds)
1164
5.35k
    std::vector<rowid_t> next_rowids(count);
1165
4.38M
    for (size_t i = 0; i < count; ++i) {
1166
4.37M
        uint64_t nr = rowids[i] + 1;
1167
4.37M
        next_rowids[i] = nr < _map_reader->num_rows() ? static_cast<rowid_t>(nr)
1168
4.37M
                                                      : static_cast<rowid_t>(0); // placeholder
1169
4.37M
    }
1170
5.35k
    MutableColumnPtr next_starts_col = ColumnOffset64::create();
1171
5.35k
    next_starts_col->reserve(count);
1172
    // read for all; we'll fix out-of-bound cases below
1173
5.35k
    RETURN_IF_ERROR(_offsets_iterator->read_by_rowids(next_rowids.data(), count, next_starts_col));
1174
1175
    // 4. fix next_start for rows whose next_rowid is out-of-bound (rowid == num_rows-1)
1176
4.38M
    for (size_t i = 0; i < count; ++i) {
1177
4.37M
        if (rowids[i] + 1 >= _map_reader->num_rows()) {
1178
            // seek to the last row and consume one to move decoder to end-of-page,
1179
            // then peek page-tail sentinel next_array_item_ordinal as next_start
1180
2.67k
            RETURN_IF_ERROR(_offsets_iterator->seek_to_ordinal(rowids[i]));
1181
2.67k
            size_t one = 1;
1182
2.67k
            bool has_null_unused = false;
1183
2.67k
            MutableColumnPtr tmp = ColumnOffset64::create();
1184
2.67k
            RETURN_IF_ERROR(_offsets_iterator->next_batch(&one, tmp, &has_null_unused));
1185
2.67k
            ordinal_t ns = 0;
1186
2.67k
            RETURN_IF_ERROR(_offsets_iterator->_peek_one_offset(&ns));
1187
            // overwrite with sentinel
1188
2.67k
            assert_cast<ColumnOffset64&, TypeCheckOnRelease::DISABLE>(*next_starts_col)
1189
2.67k
                    .get_data()[i] = ns;
1190
2.67k
        }
1191
4.37M
    }
1192
1193
    // 5. compute sizes and append offsets prefix-sum
1194
5.35k
    auto& starts_data = assert_cast<ColumnOffset64&>(*starts_col).get_data();
1195
5.35k
    auto& next_starts_data = assert_cast<ColumnOffset64&>(*next_starts_col).get_data();
1196
5.35k
    std::vector<size_t> sizes(count, 0);
1197
5.35k
    size_t acc = base;
1198
5.35k
    const auto original_size = offsets.get_data().back();
1199
5.35k
    offsets.get_data().reserve(offsets.get_data().size() + count);
1200
4.35M
    for (size_t i = 0; i < count; ++i) {
1201
4.34M
        size_t sz = static_cast<size_t>(next_starts_data[i] - starts_data[i]);
1202
4.34M
        if (_map_reader->is_nullable() && !null_mask.empty() && null_mask[i]) {
1203
41
            sz = 0; // null rows do not consume elements
1204
41
        }
1205
4.34M
        sizes[i] = sz;
1206
4.34M
        acc += sz;
1207
4.34M
        offsets.get_data().push_back(acc);
1208
4.34M
    }
1209
1210
    // 6. read key/value elements for non-empty sizes
1211
5.35k
    auto keys_ptr = IColumn::mutate(std::move(column_map.get_keys_ptr()));
1212
5.35k
    auto vals_ptr = IColumn::mutate(std::move(column_map.get_values_ptr()));
1213
5.35k
    Defer defer_keys {[&] { column_map.get_keys_ptr() = std::move(keys_ptr); }};
1214
5.35k
    Defer defer_values {[&] { column_map.get_values_ptr() = std::move(vals_ptr); }};
1215
1216
5.35k
    size_t this_run = sizes[0];
1217
5.35k
    auto start_idx = starts_data[0];
1218
5.35k
    auto last_idx = starts_data[0] + this_run;
1219
4.36M
    for (size_t i = 1; i < count; ++i) {
1220
4.35M
        size_t sz = sizes[i];
1221
4.35M
        if (sz == 0) {
1222
24.1k
            continue;
1223
24.1k
        }
1224
4.33M
        auto start = static_cast<ordinal_t>(starts_data[i]);
1225
4.33M
        if (start != last_idx) {
1226
517k
            size_t n = this_run;
1227
517k
            bool dummy_has_null = false;
1228
1229
518k
            if (this_run != 0) {
1230
518k
                if (_key_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1231
517k
                    RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(start_idx));
1232
517k
                    RETURN_IF_ERROR(_key_iterator->next_batch(&n, keys_ptr, &dummy_has_null));
1233
517k
                    DCHECK(n == this_run);
1234
517k
                }
1235
1236
518k
                if (_val_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1237
518k
                    n = this_run;
1238
518k
                    RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(start_idx));
1239
518k
                    RETURN_IF_ERROR(_val_iterator->next_batch(&n, vals_ptr, &dummy_has_null));
1240
518k
                    DCHECK(n == this_run);
1241
518k
                }
1242
518k
            }
1243
517k
            start_idx = start;
1244
517k
            this_run = sz;
1245
517k
            last_idx = start + sz;
1246
517k
            continue;
1247
517k
        }
1248
1249
3.81M
        this_run += sz;
1250
3.81M
        last_idx += sz;
1251
3.81M
    }
1252
1253
5.35k
    size_t n = this_run;
1254
5.35k
    const size_t total_count = offsets.get_data().back() - original_size;
1255
5.35k
    bool dummy_has_null = false;
1256
5.35k
    if (_key_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1257
5.35k
        if (this_run != 0) {
1258
3.52k
            RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(start_idx));
1259
3.52k
            RETURN_IF_ERROR(_key_iterator->next_batch(&n, keys_ptr, &dummy_has_null));
1260
3.52k
            DCHECK(n == this_run);
1261
3.52k
        }
1262
5.35k
    } else {
1263
0
        keys_ptr->insert_many_defaults(total_count);
1264
0
    }
1265
1266
5.35k
    if (_val_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1267
5.34k
        if (this_run != 0) {
1268
3.51k
            n = this_run;
1269
3.51k
            RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(start_idx));
1270
3.51k
            RETURN_IF_ERROR(_val_iterator->next_batch(&n, vals_ptr, &dummy_has_null));
1271
3.51k
            DCHECK(n == this_run);
1272
3.51k
        }
1273
5.34k
    } else {
1274
10
        vals_ptr->insert_many_defaults(total_count);
1275
10
    }
1276
1277
5.35k
    return Status::OK();
1278
5.35k
}
1279
1280
2.40k
void MapFileColumnIterator::set_need_to_read() {
1281
2.40k
    set_reading_flag(ReadingFlag::NEED_TO_READ);
1282
2.40k
    _key_iterator->set_need_to_read();
1283
2.40k
    _val_iterator->set_need_to_read();
1284
2.40k
}
1285
1286
2.45k
void MapFileColumnIterator::remove_pruned_sub_iterators() {
1287
2.45k
    _key_iterator->remove_pruned_sub_iterators();
1288
2.45k
    _val_iterator->remove_pruned_sub_iterators();
1289
2.45k
}
1290
1291
Status MapFileColumnIterator::set_access_paths(const TColumnAccessPaths& all_access_paths,
1292
2.36k
                                               const TColumnAccessPaths& predicate_access_paths) {
1293
2.36k
    if (all_access_paths.empty()) {
1294
1.44k
        return Status::OK();
1295
1.44k
    }
1296
1297
916
    if (!predicate_access_paths.empty()) {
1298
15
        set_reading_flag(ReadingFlag::READING_FOR_PREDICATE);
1299
15
        DLOG(INFO) << "Map column iterator set sub-column " << _column_name
1300
15
                   << " to READING_FOR_PREDICATE";
1301
15
    }
1302
1303
916
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1304
916
    auto sub_predicate_access_paths = DORIS_TRY(_get_sub_access_paths(predicate_access_paths));
1305
1306
916
    if (sub_all_access_paths.empty()) {
1307
861
        return Status::OK();
1308
861
    }
1309
1310
    // Check for meta-only modes (OFFSET_ONLY or NULL_MAP_ONLY)
1311
55
    _check_and_set_meta_read_mode(sub_all_access_paths);
1312
55
    if (read_offset_only()) {
1313
1
        _key_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1314
1
        _val_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1315
1
        DLOG(INFO) << "Map column iterator set column " << _column_name
1316
1
                   << " to OFFSET_ONLY reading mode, key/value columns set to SKIP_READING";
1317
1
        return Status::OK();
1318
1
    }
1319
54
    if (read_null_map_only()) {
1320
0
        _key_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1321
0
        _val_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1322
0
        DLOG(INFO) << "Map column iterator set column " << _column_name
1323
0
                   << " to NULL_MAP_ONLY reading mode, key/value columns set to SKIP_READING";
1324
0
        return Status::OK();
1325
0
    }
1326
1327
54
    TColumnAccessPaths key_all_access_paths;
1328
54
    TColumnAccessPaths val_all_access_paths;
1329
54
    TColumnAccessPaths key_predicate_access_paths;
1330
54
    TColumnAccessPaths val_predicate_access_paths;
1331
1332
73
    for (auto paths : sub_all_access_paths) {
1333
73
        if (paths.data_access_path.path[0] == ACCESS_ALL) {
1334
            // ACCESS_ALL means element_at(map, key) style access: the key column must be
1335
            // fully read so that the runtime can match the requested key, while any sub-path
1336
            // qualifiers (e.g. OFFSET) apply only to the value column.
1337
            // For key: create a path with just the column name (= full data access).
1338
30
            TColumnAccessPath key_path;
1339
30
            key_path.__set_type(paths.type);
1340
30
            TDataAccessPath key_data_path;
1341
30
            key_data_path.__set_path({_key_iterator->column_name()});
1342
30
            key_path.__set_data_access_path(key_data_path);
1343
30
            key_all_access_paths.emplace_back(std::move(key_path));
1344
            // For value: pass the full sub-path so qualifiers like OFFSET propagate.
1345
30
            paths.data_access_path.path[0] = _val_iterator->column_name();
1346
30
            val_all_access_paths.emplace_back(paths);
1347
43
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_KEYS) {
1348
27
            paths.data_access_path.path[0] = _key_iterator->column_name();
1349
27
            key_all_access_paths.emplace_back(paths);
1350
27
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_VALUES) {
1351
16
            paths.data_access_path.path[0] = _val_iterator->column_name();
1352
16
            val_all_access_paths.emplace_back(paths);
1353
16
        }
1354
73
    }
1355
54
    const auto need_read_keys = !key_all_access_paths.empty();
1356
54
    const auto need_read_values = !val_all_access_paths.empty();
1357
1358
54
    for (auto paths : sub_predicate_access_paths) {
1359
15
        if (paths.data_access_path.path[0] == ACCESS_ALL) {
1360
            // Same logic as above: key needs full data, value gets the sub-path.
1361
15
            TColumnAccessPath key_path;
1362
15
            key_path.__set_type(paths.type);
1363
15
            TDataAccessPath key_data_path;
1364
15
            key_data_path.__set_path({_key_iterator->column_name()});
1365
15
            key_path.__set_data_access_path(key_data_path);
1366
15
            key_predicate_access_paths.emplace_back(std::move(key_path));
1367
15
            paths.data_access_path.path[0] = _val_iterator->column_name();
1368
15
            val_predicate_access_paths.emplace_back(paths);
1369
15
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_KEYS) {
1370
0
            paths.data_access_path.path[0] = _key_iterator->column_name();
1371
0
            key_predicate_access_paths.emplace_back(paths);
1372
0
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_VALUES) {
1373
0
            paths.data_access_path.path[0] = _val_iterator->column_name();
1374
0
            val_predicate_access_paths.emplace_back(paths);
1375
0
        }
1376
15
    }
1377
1378
56
    if (need_read_keys) {
1379
56
        _key_iterator->set_reading_flag(ReadingFlag::NEED_TO_READ);
1380
56
        RETURN_IF_ERROR(
1381
56
                _key_iterator->set_access_paths(key_all_access_paths, key_predicate_access_paths));
1382
18.4E
    } else {
1383
18.4E
        _key_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1384
18.4E
        DLOG(INFO) << "Map column iterator set key column to SKIP_READING";
1385
18.4E
    }
1386
1387
54
    if (need_read_values) {
1388
45
        _val_iterator->set_reading_flag(ReadingFlag::NEED_TO_READ);
1389
45
        RETURN_IF_ERROR(
1390
45
                _val_iterator->set_access_paths(val_all_access_paths, val_predicate_access_paths));
1391
45
    } else {
1392
9
        _val_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1393
9
        DLOG(INFO) << "Map column iterator set value column to SKIP_READING";
1394
9
    }
1395
54
    return Status::OK();
1396
54
}
1397
1398
////////////////////////////////////////////////////////////////////////////////
1399
1400
StructFileColumnIterator::StructFileColumnIterator(
1401
        std::shared_ptr<ColumnReader> reader, ColumnIteratorUPtr null_iterator,
1402
        std::vector<ColumnIteratorUPtr>&& sub_column_iterators)
1403
5.93k
        : _struct_reader(reader), _sub_column_iterators(std::move(sub_column_iterators)) {
1404
5.93k
    if (_struct_reader->is_nullable()) {
1405
5.19k
        _null_iterator = std::move(null_iterator);
1406
5.19k
    }
1407
5.93k
}
1408
1409
5.92k
Status StructFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1410
5.92k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1411
0
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1412
0
        return Status::OK();
1413
0
    }
1414
1415
21.3k
    for (auto& column_iterator : _sub_column_iterators) {
1416
21.3k
        RETURN_IF_ERROR(column_iterator->init(opts));
1417
21.3k
    }
1418
5.92k
    if (_struct_reader->is_nullable()) {
1419
5.19k
        RETURN_IF_ERROR(_null_iterator->init(opts));
1420
5.19k
    }
1421
5.92k
    return Status::OK();
1422
5.92k
}
1423
1424
2.61k
Status StructFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1425
2.61k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1426
0
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1427
0
        dst->insert_many_defaults(*n);
1428
0
        return Status::OK();
1429
0
    }
1430
1431
2.61k
    if (read_null_map_only()) {
1432
        // NULL_MAP_ONLY mode: read null map, fill nested ColumnStruct with empty defaults
1433
0
        DORIS_CHECK(dst->is_nullable());
1434
0
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
1435
0
        auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1436
0
        size_t num_read = *n;
1437
0
        if (_null_iterator) {
1438
0
            bool null_signs_has_null = false;
1439
0
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1440
0
            RETURN_IF_ERROR(
1441
0
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1442
0
        } else {
1443
            // schema-change: column became nullable but old segment has no null data
1444
0
            null_map_ptr->insert_many_vals(0, num_read);
1445
0
        }
1446
0
        DCHECK(num_read == *n);
1447
        // fill nested ColumnStruct with defaults to maintain consistent column sizes
1448
0
        auto& column_struct = assert_cast<ColumnStruct&, TypeCheckOnRelease::DISABLE>(
1449
0
                nullable_col.get_nested_column());
1450
0
        column_struct.insert_many_defaults(num_read);
1451
0
        *has_null = true;
1452
0
        return Status::OK();
1453
0
    }
1454
1455
2.61k
    auto& column_struct = assert_cast<ColumnStruct&, TypeCheckOnRelease::DISABLE>(
1456
2.61k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1457
10.9k
    for (size_t i = 0; i < column_struct.tuple_size(); i++) {
1458
8.35k
        size_t num_read = *n;
1459
8.35k
        auto sub_column_ptr = IColumn::mutate(std::move(column_struct.get_column_ptr(i)));
1460
8.35k
        Defer defer_sub_column {
1461
8.35k
                [&] { column_struct.get_column_ptr(i) = std::move(sub_column_ptr); }};
1462
8.35k
        bool column_has_null = false;
1463
8.35k
        RETURN_IF_ERROR(
1464
8.35k
                _sub_column_iterators[i]->next_batch(&num_read, sub_column_ptr, &column_has_null));
1465
8.35k
        DCHECK(num_read == *n);
1466
8.35k
    }
1467
1468
2.61k
    if (dst->is_nullable()) {
1469
2.40k
        size_t num_read = *n;
1470
2.40k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1471
        // in not-null to null linked-schemachange mode,
1472
        // actually we do not change dat data include meta in footer,
1473
        // so may dst from changed meta which is nullable but old data is not nullable,
1474
        // if so, we should set null_map to all null by default
1475
2.40k
        if (_null_iterator) {
1476
2.31k
            bool null_signs_has_null = false;
1477
2.31k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1478
2.31k
            RETURN_IF_ERROR(
1479
2.31k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1480
2.31k
        } else {
1481
88
            null_map_ptr->insert_many_vals(0, num_read);
1482
88
        }
1483
2.40k
        DCHECK(num_read == *n);
1484
2.40k
    }
1485
1486
2.61k
    return Status::OK();
1487
2.61k
}
1488
1489
2.61k
Status StructFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
1490
2.61k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1491
0
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1492
0
        return Status::OK();
1493
0
    }
1494
1495
2.61k
    if (read_null_map_only()) {
1496
        // In NULL_MAP_ONLY mode, only seek the null iterator; skip all sub-column iterators
1497
0
        if (_struct_reader->is_nullable() && _null_iterator) {
1498
0
            RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1499
0
        }
1500
0
        return Status::OK();
1501
0
    }
1502
1503
8.35k
    for (auto& column_iterator : _sub_column_iterators) {
1504
8.35k
        RETURN_IF_ERROR(column_iterator->seek_to_ordinal(ord));
1505
8.35k
    }
1506
2.61k
    if (_struct_reader->is_nullable()) {
1507
2.31k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1508
2.31k
    }
1509
2.61k
    return Status::OK();
1510
2.61k
}
1511
1512
408
Status StructFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1513
1.26k
    for (auto& column_iterator : _sub_column_iterators) {
1514
1.26k
        RETURN_IF_ERROR(column_iterator->init_prefetcher(params));
1515
1.26k
    }
1516
408
    if (_struct_reader->is_nullable()) {
1517
403
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
1518
403
    }
1519
408
    return Status::OK();
1520
408
}
1521
1522
void StructFileColumnIterator::collect_prefetchers(
1523
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1524
408
        PrefetcherInitMethod init_method) {
1525
1.26k
    for (auto& column_iterator : _sub_column_iterators) {
1526
1.26k
        column_iterator->collect_prefetchers(prefetchers, init_method);
1527
1.26k
    }
1528
408
    if (_struct_reader->is_nullable()) {
1529
403
        _null_iterator->collect_prefetchers(prefetchers, init_method);
1530
403
    }
1531
408
}
1532
1533
Status StructFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1534
1.47k
                                                MutableColumnPtr& dst) {
1535
1.47k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1536
0
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1537
0
        dst->insert_many_defaults(count);
1538
0
        return Status::OK();
1539
0
    }
1540
1541
1.47k
    if (count == 0) {
1542
0
        return Status::OK();
1543
0
    }
1544
1545
1.47k
    size_t this_run = 1;
1546
1.47k
    auto start_idx = rowids[0];
1547
1.47k
    auto last_idx = rowids[0];
1548
1.54k
    for (size_t i = 1; i < count; ++i) {
1549
69
        if (last_idx == rowids[i] - 1) {
1550
69
            last_idx = rowids[i];
1551
69
            this_run++;
1552
69
            continue;
1553
69
        }
1554
0
        RETURN_IF_ERROR(seek_to_ordinal(start_idx));
1555
0
        size_t num_read = this_run;
1556
0
        RETURN_IF_ERROR(next_batch(&num_read, dst));
1557
0
        DCHECK_EQ(num_read, this_run);
1558
1559
0
        start_idx = rowids[i];
1560
0
        last_idx = rowids[i];
1561
0
        this_run = 1;
1562
0
    }
1563
1564
1.47k
    RETURN_IF_ERROR(seek_to_ordinal(start_idx));
1565
1.47k
    size_t num_read = this_run;
1566
1.47k
    RETURN_IF_ERROR(next_batch(&num_read, dst));
1567
1.47k
    DCHECK_EQ(num_read, this_run);
1568
1.47k
    return Status::OK();
1569
1.47k
}
1570
1571
5.30k
void StructFileColumnIterator::set_need_to_read() {
1572
5.30k
    set_reading_flag(ReadingFlag::NEED_TO_READ);
1573
19.2k
    for (auto& sub_iterator : _sub_column_iterators) {
1574
19.2k
        sub_iterator->set_need_to_read();
1575
19.2k
    }
1576
5.30k
}
1577
1578
5.39k
void StructFileColumnIterator::remove_pruned_sub_iterators() {
1579
25.6k
    for (auto it = _sub_column_iterators.begin(); it != _sub_column_iterators.end();) {
1580
20.2k
        auto& sub_iterator = *it;
1581
20.2k
        if (sub_iterator->reading_flag() == ReadingFlag::SKIP_READING) {
1582
795
            DLOG(INFO) << "Struct column iterator remove pruned sub-column "
1583
795
                       << sub_iterator->column_name();
1584
795
            it = _sub_column_iterators.erase(it);
1585
19.4k
        } else {
1586
19.4k
            sub_iterator->remove_pruned_sub_iterators();
1587
19.4k
            ++it;
1588
19.4k
        }
1589
20.2k
    }
1590
5.39k
}
1591
1592
Status StructFileColumnIterator::set_access_paths(
1593
        const TColumnAccessPaths& all_access_paths,
1594
5.02k
        const TColumnAccessPaths& predicate_access_paths) {
1595
5.02k
    if (all_access_paths.empty()) {
1596
1.65k
        return Status::OK();
1597
1.65k
    }
1598
1599
3.36k
    if (!predicate_access_paths.empty()) {
1600
46
        set_reading_flag(ReadingFlag::READING_FOR_PREDICATE);
1601
46
        DLOG(INFO) << "Struct column iterator set sub-column " << _column_name
1602
46
                   << " to READING_FOR_PREDICATE";
1603
46
    }
1604
3.36k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1605
3.36k
    auto sub_predicate_access_paths = DORIS_TRY(_get_sub_access_paths(predicate_access_paths));
1606
1607
    // Check for NULL_MAP_ONLY mode: only read null map, skip all sub-columns
1608
3.36k
    _check_and_set_meta_read_mode(sub_all_access_paths);
1609
3.36k
    if (read_null_map_only()) {
1610
0
        for (auto& sub_iterator : _sub_column_iterators) {
1611
0
            sub_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1612
0
        }
1613
0
        DLOG(INFO) << "Struct column iterator set column " << _column_name
1614
0
                   << " to NULL_MAP_ONLY reading mode, all sub-columns set to SKIP_READING";
1615
0
        return Status::OK();
1616
0
    }
1617
1618
3.36k
    const auto no_sub_column_to_skip = sub_all_access_paths.empty();
1619
3.36k
    const auto no_predicate_sub_column = sub_predicate_access_paths.empty();
1620
1621
16.0k
    for (auto& sub_iterator : _sub_column_iterators) {
1622
16.0k
        const auto name = sub_iterator->column_name();
1623
16.0k
        bool need_to_read = no_sub_column_to_skip;
1624
16.0k
        TColumnAccessPaths sub_all_access_paths_of_this;
1625
16.0k
        if (!need_to_read) {
1626
1.26k
            for (const auto& paths : sub_all_access_paths) {
1627
1.26k
                if (paths.data_access_path.path[0] == name) {
1628
178
                    sub_all_access_paths_of_this.emplace_back(paths);
1629
178
                }
1630
1.26k
            }
1631
975
            need_to_read = !sub_all_access_paths_of_this.empty();
1632
975
        }
1633
1634
16.0k
        if (!need_to_read) {
1635
797
            set_reading_flag(ReadingFlag::SKIP_READING);
1636
797
            sub_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1637
797
            DLOG(INFO) << "Struct column iterator set sub-column " << name << " to SKIP_READING";
1638
797
            continue;
1639
797
        }
1640
15.2k
        set_reading_flag(ReadingFlag::NEED_TO_READ);
1641
15.2k
        sub_iterator->set_reading_flag(ReadingFlag::NEED_TO_READ);
1642
1643
15.2k
        TColumnAccessPaths sub_predicate_access_paths_of_this;
1644
1645
15.2k
        if (!no_predicate_sub_column) {
1646
45
            for (const auto& paths : sub_predicate_access_paths) {
1647
45
                if (StringCaseEqual()(paths.data_access_path.path[0], name)) {
1648
44
                    sub_predicate_access_paths_of_this.emplace_back(paths);
1649
44
                }
1650
45
            }
1651
45
        }
1652
1653
15.2k
        RETURN_IF_ERROR(sub_iterator->set_access_paths(sub_all_access_paths_of_this,
1654
15.2k
                                                       sub_predicate_access_paths_of_this));
1655
15.2k
    }
1656
3.36k
    return Status::OK();
1657
3.36k
}
1658
1659
////////////////////////////////////////////////////////////////////////////////
1660
27.5k
Status OffsetFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1661
27.5k
    RETURN_IF_ERROR(_offset_iterator->init(opts));
1662
    // allocate peek tmp column once
1663
27.5k
    _peek_tmp_col = ColumnOffset64::create();
1664
27.5k
    return Status::OK();
1665
27.5k
}
1666
1667
35.2k
Status OffsetFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1668
35.2k
    RETURN_IF_ERROR(_offset_iterator->next_batch(n, dst, has_null));
1669
35.2k
    return Status::OK();
1670
35.2k
}
1671
1672
67.7k
Status OffsetFileColumnIterator::_peek_one_offset(ordinal_t* offset) {
1673
67.7k
    if (_offset_iterator->get_current_page()->has_remaining()) {
1674
49.2k
        PageDecoder* offset_page_decoder = _offset_iterator->get_current_page()->data_decoder.get();
1675
49.2k
        size_t n = 1;
1676
49.2k
        _peek_tmp_col->clear();
1677
49.2k
        RETURN_IF_ERROR(offset_page_decoder->peek_next_batch(&n, _peek_tmp_col)); // not null
1678
49.2k
        DCHECK(_peek_tmp_col->size() == 1);
1679
49.2k
        *offset =
1680
49.2k
                assert_cast<const ColumnOffset64*, TypeCheckOnRelease::DISABLE>(_peek_tmp_col.get())
1681
49.2k
                        ->get_element(0);
1682
49.2k
    } else {
1683
18.5k
        *offset = _offset_iterator->get_current_page()->next_array_item_ordinal;
1684
18.5k
    }
1685
67.7k
    return Status::OK();
1686
67.7k
}
1687
1688
5.63k
Status OffsetFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1689
5.63k
    return _offset_iterator->init_prefetcher(params);
1690
5.63k
}
1691
1692
void OffsetFileColumnIterator::collect_prefetchers(
1693
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1694
5.63k
        PrefetcherInitMethod init_method) {
1695
5.63k
    _offset_iterator->collect_prefetchers(prefetchers, init_method);
1696
5.63k
}
1697
1698
/**
1699
 *  first_storage_offset read from page should smaller than next_storage_offset which here call _peek_one_offset from page,
1700
    and first_column_offset is keep in memory data which is different dimension with (first_storage_offset and next_storage_offset)
1701
     eg. step1. read page: first_storage_offset = 16382
1702
         step2. read page below with _peek_one_offset(&last_offset): last_offset = 16387
1703
         step3. first_offset = 126 which is calculate in column offsets
1704
         for loop column offsets element in size
1705
            we can calculate from first_storage_offset to next_storage_offset one by one to fill with offsets_data in memory column offsets
1706
 * @param start
1707
 * @param column_offsets
1708
 * @return
1709
 */
1710
Status OffsetFileColumnIterator::_calculate_offsets(ssize_t start,
1711
32.6k
                                                    ColumnArray::ColumnOffsets& column_offsets) {
1712
32.6k
    ordinal_t next_storage_offset = 0;
1713
32.6k
    RETURN_IF_ERROR(_peek_one_offset(&next_storage_offset));
1714
1715
    // calculate real offsets
1716
32.6k
    auto& offsets_data = column_offsets.get_data();
1717
32.6k
    ordinal_t first_column_offset = offsets_data[start - 1]; // -1 is valid
1718
32.6k
    ordinal_t first_storage_offset = offsets_data[start];
1719
32.6k
    DCHECK(next_storage_offset >= first_storage_offset);
1720
3.77M
    for (ssize_t i = start; i < offsets_data.size() - 1; ++i) {
1721
3.73M
        offsets_data[i] = first_column_offset + (offsets_data[i + 1] - first_storage_offset);
1722
3.73M
    }
1723
    // last offset
1724
32.6k
    offsets_data[offsets_data.size() - 1] =
1725
32.6k
            first_column_offset + (next_storage_offset - first_storage_offset);
1726
32.6k
    return Status::OK();
1727
32.6k
}
1728
1729
////////////////////////////////////////////////////////////////////////////////
1730
ArrayFileColumnIterator::ArrayFileColumnIterator(std::shared_ptr<ColumnReader> reader,
1731
                                                 OffsetFileColumnIteratorUPtr offset_reader,
1732
                                                 ColumnIteratorUPtr item_iterator,
1733
                                                 ColumnIteratorUPtr null_iterator)
1734
18.1k
        : _array_reader(reader),
1735
18.1k
          _offset_iterator(std::move(offset_reader)),
1736
18.1k
          _item_iterator(std::move(item_iterator)) {
1737
18.1k
    if (_array_reader->is_nullable()) {
1738
16.0k
        _null_iterator = std::move(null_iterator);
1739
16.0k
    }
1740
18.1k
}
1741
1742
18.1k
Status ArrayFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1743
18.1k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1744
8
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip readking.";
1745
8
        return Status::OK();
1746
8
    }
1747
1748
18.0k
    RETURN_IF_ERROR(_offset_iterator->init(opts));
1749
18.0k
    RETURN_IF_ERROR(_item_iterator->init(opts));
1750
18.0k
    if (_array_reader->is_nullable()) {
1751
15.9k
        RETURN_IF_ERROR(_null_iterator->init(opts));
1752
15.9k
    }
1753
18.0k
    return Status::OK();
1754
18.0k
}
1755
1756
28.2k
Status ArrayFileColumnIterator::_seek_by_offsets(ordinal_t ord) {
1757
28.2k
    if (read_offset_only()) {
1758
        // In OFFSET_ONLY mode, item iterator is SKIP_READING, no need to seek it
1759
72
        return Status::OK();
1760
72
    }
1761
    // using offsets info
1762
28.1k
    ordinal_t offset = 0;
1763
28.1k
    RETURN_IF_ERROR(_offset_iterator->_peek_one_offset(&offset));
1764
28.1k
    RETURN_IF_ERROR(_item_iterator->seek_to_ordinal(offset));
1765
28.1k
    return Status::OK();
1766
28.1k
}
1767
1768
28.2k
Status ArrayFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
1769
28.2k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1770
0
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip reading.";
1771
0
        return Status::OK();
1772
0
    }
1773
1774
28.2k
    if (read_null_map_only()) {
1775
        // In NULL_MAP_ONLY mode, only seek the null iterator; skip offset and item iterators
1776
0
        if (_array_reader->is_nullable() && _null_iterator) {
1777
0
            RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1778
0
        }
1779
0
        return Status::OK();
1780
0
    }
1781
1782
28.2k
    RETURN_IF_ERROR(_offset_iterator->seek_to_ordinal(ord));
1783
28.2k
    if (_array_reader->is_nullable()) {
1784
25.0k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1785
25.0k
    }
1786
28.2k
    return _seek_by_offsets(ord);
1787
28.2k
}
1788
1789
28.2k
Status ArrayFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1790
28.2k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1791
0
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip reading.";
1792
0
        dst->insert_many_defaults(*n);
1793
0
        return Status::OK();
1794
0
    }
1795
1796
28.2k
    if (read_null_map_only()) {
1797
        // NULL_MAP_ONLY mode: read null map, fill nested ColumnArray with empty defaults
1798
0
        DORIS_CHECK(dst->is_nullable());
1799
0
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
1800
0
        auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1801
0
        size_t num_read = *n;
1802
0
        if (_null_iterator) {
1803
0
            bool null_signs_has_null = false;
1804
0
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1805
0
            RETURN_IF_ERROR(
1806
0
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1807
0
        } else {
1808
            // schema-change: column became nullable but old segment has no null data
1809
0
            null_map_ptr->insert_many_vals(0, num_read);
1810
0
        }
1811
0
        DCHECK(num_read == *n);
1812
        // fill nested ColumnArray with empty (zero-length) arrays
1813
0
        auto& column_array = assert_cast<ColumnArray&, TypeCheckOnRelease::DISABLE>(
1814
0
                nullable_col.get_nested_column());
1815
0
        column_array.insert_many_defaults(num_read);
1816
0
        *has_null = true;
1817
0
        return Status::OK();
1818
0
    }
1819
1820
28.2k
    auto& column_array = assert_cast<ColumnArray&, TypeCheckOnRelease::DISABLE>(
1821
28.2k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1822
1823
28.2k
    bool offsets_has_null = false;
1824
28.2k
    auto column_offsets_ptr = std::move(*column_array.get_offsets_ptr()).mutate();
1825
28.2k
    Defer defer_offsets {[&] {
1826
28.2k
        auto typed_column_offsets_ptr = ColumnArray::ColumnOffsets::cast_to_column_mutptr(
1827
28.2k
                assert_cast<ColumnArray::ColumnOffsets*, TypeCheckOnRelease::DISABLE>(
1828
28.2k
                        column_offsets_ptr.get()));
1829
28.2k
        column_offsets_ptr = nullptr;
1830
28.2k
        column_array.get_offsets_ptr() = std::move(typed_column_offsets_ptr);
1831
28.2k
    }};
1832
28.2k
    ssize_t start = column_offsets_ptr->size();
1833
28.2k
    RETURN_IF_ERROR(_offset_iterator->next_batch(n, column_offsets_ptr, &offsets_has_null));
1834
28.2k
    if (*n == 0) {
1835
0
        return Status::OK();
1836
0
    }
1837
28.2k
    auto& column_offsets = static_cast<ColumnArray::ColumnOffsets&>(*column_offsets_ptr);
1838
28.2k
    RETURN_IF_ERROR(_offset_iterator->_calculate_offsets(start, column_offsets));
1839
28.2k
    size_t num_items =
1840
28.2k
            column_offsets.get_data().back() - column_offsets.get_data()[start - 1]; // -1 is valid
1841
28.2k
    if (num_items > 0) {
1842
24.5k
        auto column_items_ptr = IColumn::mutate(std::move(column_array.get_data_ptr()));
1843
24.5k
        Defer defer_items {[&] { column_array.get_data_ptr() = std::move(column_items_ptr); }};
1844
24.5k
        if (read_offset_only()) {
1845
            // OFFSET_ONLY mode: skip reading actual item data, fill with defaults
1846
49
            column_items_ptr->insert_many_defaults(num_items);
1847
24.5k
        } else {
1848
24.5k
            size_t num_read = num_items;
1849
24.5k
            bool items_has_null = false;
1850
24.5k
            RETURN_IF_ERROR(
1851
24.5k
                    _item_iterator->next_batch(&num_read, column_items_ptr, &items_has_null));
1852
24.5k
            DCHECK(num_read == num_items);
1853
24.5k
        }
1854
24.5k
    }
1855
1856
28.2k
    if (dst->is_nullable()) {
1857
25.0k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1858
25.0k
        size_t num_read = *n;
1859
        // in not-null to null linked-schemachange mode,
1860
        // actually we do not change dat data include meta in footer,
1861
        // so may dst from changed meta which is nullable but old data is not nullable,
1862
        // if so, we should set null_map to all null by default
1863
25.0k
        if (_null_iterator) {
1864
25.0k
            bool null_signs_has_null = false;
1865
25.0k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1866
25.0k
            RETURN_IF_ERROR(
1867
25.0k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1868
18.4E
        } else {
1869
18.4E
            null_map_ptr->insert_many_vals(0, num_read);
1870
18.4E
        }
1871
25.0k
        DCHECK(num_read == *n);
1872
25.0k
    }
1873
1874
28.2k
    return Status::OK();
1875
28.2k
}
1876
1877
4.65k
Status ArrayFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1878
4.65k
    RETURN_IF_ERROR(_offset_iterator->init_prefetcher(params));
1879
4.65k
    RETURN_IF_ERROR(_item_iterator->init_prefetcher(params));
1880
4.65k
    if (_array_reader->is_nullable()) {
1881
3.42k
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
1882
3.42k
    }
1883
4.65k
    return Status::OK();
1884
4.65k
}
1885
1886
void ArrayFileColumnIterator::collect_prefetchers(
1887
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1888
4.65k
        PrefetcherInitMethod init_method) {
1889
4.65k
    _offset_iterator->collect_prefetchers(prefetchers, init_method);
1890
    // the actual data pages to read of item column depends on the read result of offset column,
1891
    // so we can't init prefetch blocks according to rowids, just prefetch all data blocks here.
1892
4.65k
    _item_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
1893
4.65k
    if (_array_reader->is_nullable()) {
1894
3.42k
        _null_iterator->collect_prefetchers(prefetchers, init_method);
1895
3.42k
    }
1896
4.65k
}
1897
1898
Status ArrayFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1899
7.69k
                                               MutableColumnPtr& dst) {
1900
7.69k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
1901
0
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip reading.";
1902
0
        dst->insert_many_defaults(count);
1903
0
        return Status::OK();
1904
0
    }
1905
1906
29.0k
    for (size_t i = 0; i < count; ++i) {
1907
        // TODO(cambyszju): now read array one by one, need optimize later
1908
21.3k
        RETURN_IF_ERROR(seek_to_ordinal(rowids[i]));
1909
21.3k
        size_t num_read = 1;
1910
21.3k
        RETURN_IF_ERROR(next_batch(&num_read, dst));
1911
21.3k
    }
1912
7.69k
    return Status::OK();
1913
7.69k
}
1914
1915
12.5k
void ArrayFileColumnIterator::set_need_to_read() {
1916
12.5k
    set_reading_flag(ReadingFlag::NEED_TO_READ);
1917
12.5k
    _item_iterator->set_need_to_read();
1918
12.5k
}
1919
1920
12.2k
void ArrayFileColumnIterator::remove_pruned_sub_iterators() {
1921
12.2k
    _item_iterator->remove_pruned_sub_iterators();
1922
12.2k
}
1923
1924
Status ArrayFileColumnIterator::set_access_paths(const TColumnAccessPaths& all_access_paths,
1925
11.9k
                                                 const TColumnAccessPaths& predicate_access_paths) {
1926
11.9k
    if (all_access_paths.empty()) {
1927
1.69k
        return Status::OK();
1928
1.69k
    }
1929
1930
10.2k
    if (!predicate_access_paths.empty()) {
1931
584
        set_reading_flag(ReadingFlag::READING_FOR_PREDICATE);
1932
584
        DLOG(INFO) << "Array column iterator set sub-column " << _column_name
1933
584
                   << " to READING_FOR_PREDICATE";
1934
584
    }
1935
1936
10.2k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1937
10.2k
    auto sub_predicate_access_paths = DORIS_TRY(_get_sub_access_paths(predicate_access_paths));
1938
1939
    // Check for meta-only modes (OFFSET_ONLY or NULL_MAP_ONLY)
1940
10.2k
    _check_and_set_meta_read_mode(sub_all_access_paths);
1941
10.2k
    if (read_offset_only()) {
1942
69
        _item_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1943
69
        DLOG(INFO) << "Array column iterator set column " << _column_name
1944
69
                   << " to OFFSET_ONLY reading mode, item column set to SKIP_READING";
1945
69
        return Status::OK();
1946
69
    }
1947
10.1k
    if (read_null_map_only()) {
1948
10
        _item_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1949
10
        DLOG(INFO) << "Array column iterator set column " << _column_name
1950
10
                   << " to NULL_MAP_ONLY reading mode, item column set to SKIP_READING";
1951
10
        return Status::OK();
1952
10
    }
1953
1954
10.1k
    const auto no_sub_column_to_skip = sub_all_access_paths.empty();
1955
10.1k
    const auto no_predicate_sub_column = sub_predicate_access_paths.empty();
1956
1957
10.1k
    if (!no_sub_column_to_skip) {
1958
145
        for (auto& path : sub_all_access_paths) {
1959
145
            if (path.data_access_path.path[0] == ACCESS_ALL) {
1960
145
                path.data_access_path.path[0] = _item_iterator->column_name();
1961
145
            }
1962
145
        }
1963
145
    }
1964
1965
10.1k
    if (!no_predicate_sub_column) {
1966
4
        for (auto& path : sub_predicate_access_paths) {
1967
4
            if (path.data_access_path.path[0] == ACCESS_ALL) {
1968
4
                path.data_access_path.path[0] = _item_iterator->column_name();
1969
4
            }
1970
4
        }
1971
4
    }
1972
1973
10.1k
    if (!no_sub_column_to_skip || !no_predicate_sub_column) {
1974
142
        _item_iterator->set_reading_flag(ReadingFlag::NEED_TO_READ);
1975
142
        RETURN_IF_ERROR(
1976
142
                _item_iterator->set_access_paths(sub_all_access_paths, sub_predicate_access_paths));
1977
142
    }
1978
10.1k
    return Status::OK();
1979
10.1k
}
1980
1981
////////////////////////////////////////////////////////////////////////////////
1982
// StringFileColumnIterator implementation
1983
////////////////////////////////////////////////////////////////////////////////
1984
1985
StringFileColumnIterator::StringFileColumnIterator(std::shared_ptr<ColumnReader> reader)
1986
3.67M
        : FileColumnIterator(std::move(reader)) {}
1987
1988
3.67M
Status StringFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1989
3.67M
    if (read_offset_only()) {
1990
        // Propagate only_read_offsets to the FileColumnIterator's options
1991
166
        auto modified_opts = opts;
1992
166
        modified_opts.only_read_offsets = true;
1993
166
        return FileColumnIterator::init(modified_opts);
1994
166
    }
1995
3.67M
    return FileColumnIterator::init(opts);
1996
3.67M
}
1997
1998
Status StringFileColumnIterator::set_access_paths(
1999
        const TColumnAccessPaths& all_access_paths,
2000
3.07k
        const TColumnAccessPaths& predicate_access_paths) {
2001
3.07k
    if (all_access_paths.empty()) {
2002
2.75k
        return Status::OK();
2003
2.75k
    }
2004
2005
319
    if (!predicate_access_paths.empty()) {
2006
26
        set_reading_flag(ReadingFlag::READING_FOR_PREDICATE);
2007
26
    }
2008
2009
    // Strip the column name from path[0] before checking for meta-only modes.
2010
    // Raw paths look like ["col_name", "OFFSET"] or ["col_name", "NULL"].
2011
319
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
2012
319
    _check_and_set_meta_read_mode(sub_all_access_paths);
2013
    // OFFSET_ONLY mode is fundamentally incompatible with CHAR columns:
2014
    // CHAR is stored padded to its declared length (see
2015
    // OlapColumnDataConvertorChar::clone_and_padding), so the per-row length
2016
    // recorded in dict word info / page headers is always the padded length
2017
    // (e.g. 25 for CHAR(25)) — never the logical length expected by length().
2018
    // Recovering the logical length requires scanning the chars buffer with
2019
    // strnlen() (shrink_padding_chars), which OFFSET_ONLY by definition skips.
2020
    // There is no partial-benefit path: any optimization that still produces
2021
    // the correct length() result must read the chars buffer in full.
2022
    //
2023
    // FE (NestedColumnPruning) already filters CHAR slots out of the
2024
    // OFFSET-only access plan, so reaching this branch means an FE/BE
2025
    // contract violation. Fail loudly instead of silently falling back.
2026
319
    if (read_offset_only() && get_reader() != nullptr &&
2027
319
        get_reader()->get_meta_type() == FieldType::OLAP_FIELD_TYPE_CHAR) {
2028
0
        return Status::InternalError(
2029
0
                "OFFSET_ONLY access path is not supported on CHAR column '{}': CHAR is stored "
2030
0
                "padded so the per-row length information available without reading the chars "
2031
0
                "buffer is always the padded length, not the logical length. The FE planner "
2032
0
                "must not emit an OFFSET access path for CHAR columns.",
2033
0
                _column_name);
2034
0
    }
2035
319
    if (read_offset_only()) {
2036
166
        DLOG(INFO) << "String column iterator set column " << _column_name
2037
166
                   << " to OFFSET_ONLY reading mode";
2038
166
    } else if (read_null_map_only()) {
2039
25
        DLOG(INFO) << "String column iterator set column " << _column_name
2040
25
                   << " to NULL_MAP_ONLY reading mode";
2041
25
    }
2042
2043
319
    return Status::OK();
2044
319
}
2045
2046
////////////////////////////////////////////////////////////////////////////////
2047
2048
6.19M
FileColumnIterator::FileColumnIterator(std::shared_ptr<ColumnReader> reader) : _reader(reader) {}
2049
2050
14.0k
void ColumnIterator::_check_and_set_meta_read_mode(const TColumnAccessPaths& sub_all_access_paths) {
2051
14.0k
    for (const auto& path : sub_all_access_paths) {
2052
665
        if (!path.data_access_path.path.empty()) {
2053
665
            if (StringCaseEqual()(path.data_access_path.path[0], ACCESS_OFFSET)) {
2054
237
                _read_mode = ReadMode::OFFSET_ONLY;
2055
237
                return;
2056
428
            } else if (StringCaseEqual()(path.data_access_path.path[0], ACCESS_NULL)) {
2057
35
                _read_mode = ReadMode::NULL_MAP_ONLY;
2058
35
                return;
2059
35
            }
2060
665
        }
2061
664
    }
2062
13.7k
    _read_mode = ReadMode::DEFAULT;
2063
13.7k
}
2064
2065
6.18M
Status FileColumnIterator::init(const ColumnIteratorOptions& opts) {
2066
6.18M
    if (_reading_flag == ReadingFlag::SKIP_READING) {
2067
57
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2068
57
        return Status::OK();
2069
57
    }
2070
2071
6.18M
    _opts = opts;
2072
6.18M
    if (!_opts.use_page_cache) {
2073
5.82M
        _reader->disable_index_meta_cache();
2074
5.82M
    }
2075
6.18M
    RETURN_IF_ERROR(get_block_compression_codec(_reader->get_compression(), &_compress_codec));
2076
6.18M
    if (config::enable_low_cardinality_optimize &&
2077
6.19M
        opts.io_ctx.reader_type == ReaderType::READER_QUERY &&
2078
6.18M
        _reader->encoding_info()->encoding() == DICT_ENCODING) {
2079
3.62M
        auto dict_encoding_type = _reader->get_dict_encoding_type();
2080
        // Only if the column is a predicate column, then we need check the all dict encoding flag
2081
        // because we could rewrite the predciate to accelarate query speed. But if it is not a
2082
        // predicate column, then it is useless. And it has a bad impact on cold read(first time read)
2083
        // because it will load the column's ordinal index and zonemap index and maybe other indices.
2084
        // it has bad impact on primary key query. For example, select * from table where pk = 1, and
2085
        // the table has 2000 columns.
2086
3.62M
        if (dict_encoding_type == ColumnReader::UNKNOWN_DICT_ENCODING && opts.is_predicate_column) {
2087
4.95k
            RETURN_IF_ERROR(seek_to_ordinal(_reader->num_rows() - 1));
2088
4.95k
            _is_all_dict_encoding = _page.is_dict_encoding;
2089
4.95k
            _reader->set_dict_encoding_type(_is_all_dict_encoding
2090
4.95k
                                                    ? ColumnReader::ALL_DICT_ENCODING
2091
4.95k
                                                    : ColumnReader::PARTIAL_DICT_ENCODING);
2092
3.62M
        } else {
2093
3.62M
            _is_all_dict_encoding = dict_encoding_type == ColumnReader::ALL_DICT_ENCODING;
2094
3.62M
        }
2095
3.62M
    }
2096
6.18M
    return Status::OK();
2097
6.18M
}
2098
2099
6.20M
FileColumnIterator::~FileColumnIterator() = default;
2100
2101
88.8k
void FileColumnIterator::_trigger_prefetch_if_eligible(ordinal_t ord) {
2102
88.8k
    std::vector<BlockRange> ranges;
2103
88.8k
    if (_prefetcher->need_prefetch(cast_set<uint32_t>(ord), &ranges)) {
2104
87.9k
        for (const auto& range : ranges) {
2105
87.9k
            _cached_remote_file_reader->prefetch_range(range.offset, range.size, &_opts.io_ctx);
2106
87.9k
        }
2107
87.9k
    }
2108
88.8k
}
2109
2110
2.19M
Status FileColumnIterator::seek_to_ordinal(ordinal_t ord) {
2111
2.19M
    if (_reading_flag == ReadingFlag::SKIP_READING) {
2112
0
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2113
0
        return Status::OK();
2114
0
    }
2115
2116
18.4E
    LOG_IF(INFO, config::enable_segment_prefetch_verbose_log) << fmt::format(
2117
18.4E
            "[verbose] FileColumnIterator::seek_to_ordinal seek to ordinal {}, enable_prefetch={}",
2118
18.4E
            ord, _enable_prefetch);
2119
2.19M
    if (_enable_prefetch) {
2120
88.9k
        _trigger_prefetch_if_eligible(ord);
2121
88.9k
    }
2122
2123
    // if current page contains this row, we don't need to seek
2124
2.19M
    if (!_page || !_page.contains(ord) || !_page_iter.valid()) {
2125
465k
        RETURN_IF_ERROR(_reader->seek_at_or_before(ord, &_page_iter, _opts));
2126
465k
        RETURN_IF_ERROR(_read_data_page(_page_iter));
2127
465k
    }
2128
2.19M
    RETURN_IF_ERROR(_seek_to_pos_in_page(&_page, ord - _page.first_ordinal));
2129
2.19M
    _current_ordinal = ord;
2130
2.19M
    return Status::OK();
2131
2.19M
}
2132
2133
0
Status FileColumnIterator::seek_to_page_start() {
2134
0
    return seek_to_ordinal(_page.first_ordinal);
2135
0
}
2136
2137
2.22M
Status FileColumnIterator::_seek_to_pos_in_page(ParsedPage* page, ordinal_t offset_in_page) const {
2138
2.22M
    if (page->offset_in_page == offset_in_page) {
2139
        // fast path, do nothing
2140
519k
        return Status::OK();
2141
519k
    }
2142
2143
1.70M
    ordinal_t pos_in_data = offset_in_page;
2144
1.70M
    if (_page.has_null) {
2145
67.7k
        ordinal_t offset_in_data = 0;
2146
67.7k
        ordinal_t skips = offset_in_page;
2147
2148
67.7k
        if (offset_in_page > page->offset_in_page) {
2149
            // forward, reuse null bitmap
2150
48.6k
            skips = offset_in_page - page->offset_in_page;
2151
48.6k
            offset_in_data = page->data_decoder->current_index();
2152
48.6k
        } else {
2153
            // rewind null bitmap, and
2154
19.1k
            page->null_decoder = RleDecoder<bool>((const uint8_t*)page->null_bitmap.data,
2155
19.1k
                                                  cast_set<int>(page->null_bitmap.size), 1);
2156
19.1k
        }
2157
2158
67.7k
        auto skip_nulls = page->null_decoder.Skip(skips);
2159
67.7k
        pos_in_data = offset_in_data + skips - skip_nulls;
2160
67.7k
    }
2161
2162
1.70M
    RETURN_IF_ERROR(page->data_decoder->seek_to_position_in_page(pos_in_data));
2163
1.70M
    page->offset_in_page = offset_in_page;
2164
1.70M
    return Status::OK();
2165
1.70M
}
2166
2167
1.25k
Status FileColumnIterator::next_batch_of_zone_map(size_t* n, MutableColumnPtr& dst) {
2168
1.25k
    return _reader->next_batch_of_zone_map(n, dst);
2169
1.25k
}
2170
2171
1.93M
Status FileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2172
1.93M
    if (read_null_map_only()) {
2173
15
        DLOG(INFO) << "File column iterator column " << _column_name
2174
15
                   << " in NULL_MAP_ONLY mode, reading only null map.";
2175
15
        DORIS_CHECK(dst->is_nullable());
2176
15
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
2177
15
        auto& null_map_data = nullable_col.get_null_map_data();
2178
2179
15
        size_t remaining = *n;
2180
15
        *has_null = false;
2181
30
        while (remaining > 0) {
2182
15
            if (!_page.has_remaining()) {
2183
0
                bool eos = false;
2184
0
                RETURN_IF_ERROR(_load_next_page(&eos));
2185
0
                if (eos) {
2186
0
                    break;
2187
0
                }
2188
0
            }
2189
2190
15
            size_t nrows_in_page = std::min(remaining, _page.remaining());
2191
15
            size_t nrows_to_read = nrows_in_page;
2192
15
            if (_page.has_null) {
2193
50
                while (nrows_to_read > 0) {
2194
40
                    bool is_null = false;
2195
40
                    size_t this_run = _page.null_decoder.GetNextRun(&is_null, nrows_to_read);
2196
40
                    const size_t cur_size = null_map_data.size();
2197
40
                    null_map_data.resize(cur_size + this_run);
2198
40
                    memset(null_map_data.data() + cur_size, is_null ? 1 : 0, this_run);
2199
40
                    if (is_null) {
2200
17
                        *has_null = true;
2201
17
                    }
2202
40
                    nrows_to_read -= this_run;
2203
40
                    _page.offset_in_page += this_run;
2204
40
                    _current_ordinal += this_run;
2205
40
                }
2206
10
            } else {
2207
5
                const size_t cur_size = null_map_data.size();
2208
5
                null_map_data.resize(cur_size + nrows_to_read);
2209
5
                memset(null_map_data.data() + cur_size, 0, nrows_to_read);
2210
5
                _page.offset_in_page += nrows_to_read;
2211
5
                _current_ordinal += nrows_to_read;
2212
5
            }
2213
15
            remaining -= nrows_in_page;
2214
15
        }
2215
15
        *n -= remaining;
2216
15
        nullable_col.get_nested_column().insert_many_defaults(*n);
2217
15
        return Status::OK();
2218
15
    }
2219
2220
1.93M
    if (_reading_flag == ReadingFlag::SKIP_READING) {
2221
0
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2222
0
        dst->insert_many_defaults(*n);
2223
0
        return Status::OK();
2224
0
    }
2225
2226
1.93M
    size_t curr_size = dst->byte_size();
2227
1.93M
    dst->reserve(*n);
2228
1.93M
    size_t remaining = *n;
2229
1.93M
    *has_null = false;
2230
3.88M
    while (remaining > 0) {
2231
1.95M
        if (!_page.has_remaining()) {
2232
24.2k
            bool eos = false;
2233
24.2k
            RETURN_IF_ERROR(_load_next_page(&eos));
2234
24.2k
            if (eos) {
2235
0
                break;
2236
0
            }
2237
24.2k
        }
2238
2239
        // number of rows to be read from this page
2240
1.95M
        size_t nrows_in_page = std::min(remaining, _page.remaining());
2241
1.95M
        size_t nrows_to_read = nrows_in_page;
2242
1.95M
        if (_page.has_null) {
2243
225k
            while (nrows_to_read > 0) {
2244
153k
                bool is_null = false;
2245
153k
                size_t this_run = _page.null_decoder.GetNextRun(&is_null, nrows_to_read);
2246
                // we use num_rows only for CHECK
2247
153k
                size_t num_rows = this_run;
2248
153k
                if (!is_null) {
2249
99.0k
                    RETURN_IF_ERROR(_page.data_decoder->next_batch(&num_rows, dst));
2250
99.0k
                    DCHECK_EQ(this_run, num_rows);
2251
99.0k
                } else {
2252
54.8k
                    *has_null = true;
2253
54.8k
                    auto* null_col = check_and_get_column<ColumnNullable>(dst.get());
2254
54.9k
                    if (null_col != nullptr) {
2255
54.9k
                        null_col->insert_many_defaults(this_run);
2256
18.4E
                    } else {
2257
18.4E
                        return Status::InternalError("unexpected column type in column reader");
2258
18.4E
                    }
2259
54.8k
                }
2260
2261
153k
                nrows_to_read -= this_run;
2262
153k
                _page.offset_in_page += this_run;
2263
153k
                _current_ordinal += this_run;
2264
153k
            }
2265
1.88M
        } else {
2266
1.88M
            RETURN_IF_ERROR(_page.data_decoder->next_batch(&nrows_to_read, dst));
2267
1.88M
            DCHECK_EQ(nrows_to_read, nrows_in_page);
2268
2269
1.88M
            _page.offset_in_page += nrows_to_read;
2270
1.88M
            _current_ordinal += nrows_to_read;
2271
1.88M
        }
2272
1.95M
        remaining -= nrows_in_page;
2273
1.95M
    }
2274
1.93M
    *n -= remaining;
2275
1.93M
    _opts.stats->bytes_read += (dst->byte_size() - curr_size) + BitmapSize(*n);
2276
2277
#ifdef BE_TEST
2278
    _reader->check_data_by_zone_map_for_test(dst);
2279
#endif
2280
1.93M
    return Status::OK();
2281
1.93M
}
2282
2283
Status FileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
2284
242k
                                          MutableColumnPtr& dst) {
2285
242k
    if (read_null_map_only()) {
2286
8
        DLOG(INFO) << "File column iterator column " << _column_name
2287
8
                   << " in NULL_MAP_ONLY mode, reading only null map by rowids.";
2288
2289
8
        DORIS_CHECK(dst->is_nullable());
2290
8
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
2291
8
        auto& null_map_data = nullable_col.get_null_map_data();
2292
8
        const size_t base_size = null_map_data.size();
2293
8
        null_map_data.resize(base_size + count);
2294
2295
8
        size_t remaining = count;
2296
8
        size_t total_read_count = 0;
2297
8
        size_t nrows_to_read = 0;
2298
16
        while (remaining > 0) {
2299
8
            RETURN_IF_ERROR(seek_to_ordinal(rowids[total_read_count]));
2300
2301
8
            nrows_to_read = std::min(remaining, _page.remaining());
2302
2303
8
            if (_page.has_null) {
2304
0
                size_t already_read = 0;
2305
0
                while ((nrows_to_read - already_read) > 0) {
2306
0
                    bool is_null = false;
2307
0
                    size_t this_run = std::min(nrows_to_read - already_read, _page.remaining());
2308
0
                    if (UNLIKELY(this_run == 0)) {
2309
0
                        break;
2310
0
                    }
2311
0
                    this_run = _page.null_decoder.GetNextRun(&is_null, this_run);
2312
2313
0
                    size_t offset = total_read_count + already_read;
2314
0
                    size_t this_read_count = 0;
2315
0
                    rowid_t current_ordinal_in_page =
2316
0
                            cast_set<uint32_t>(_page.offset_in_page + _page.first_ordinal);
2317
0
                    for (size_t i = 0; i < this_run; ++i) {
2318
0
                        if (rowids[offset + i] - current_ordinal_in_page >= this_run) {
2319
0
                            break;
2320
0
                        }
2321
0
                        this_read_count++;
2322
0
                    }
2323
2324
0
                    if (this_read_count > 0) {
2325
0
                        memset(null_map_data.data() + base_size + offset, is_null ? 1 : 0,
2326
0
                               this_read_count);
2327
0
                    }
2328
2329
0
                    already_read += this_read_count;
2330
0
                    _page.offset_in_page += this_run;
2331
0
                }
2332
2333
0
                nrows_to_read = already_read;
2334
0
                total_read_count += nrows_to_read;
2335
0
                remaining -= nrows_to_read;
2336
8
            } else {
2337
8
                memset(null_map_data.data() + base_size + total_read_count, 0, nrows_to_read);
2338
8
                total_read_count += nrows_to_read;
2339
8
                remaining -= nrows_to_read;
2340
8
            }
2341
8
        }
2342
2343
8
        null_map_data.resize(base_size + total_read_count);
2344
8
        nullable_col.get_nested_column().insert_many_defaults(total_read_count);
2345
8
        return Status::OK();
2346
8
    }
2347
2348
242k
    if (_reading_flag == ReadingFlag::SKIP_READING) {
2349
0
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2350
0
        dst->insert_many_defaults(count);
2351
0
        return Status::OK();
2352
0
    }
2353
2354
242k
    size_t remaining = count;
2355
242k
    size_t total_read_count = 0;
2356
242k
    size_t nrows_to_read = 0;
2357
501k
    while (remaining > 0) {
2358
259k
        RETURN_IF_ERROR(seek_to_ordinal(rowids[total_read_count]));
2359
2360
        // number of rows to be read from this page
2361
259k
        nrows_to_read = std::min(remaining, _page.remaining());
2362
2363
259k
        if (_page.has_null) {
2364
34.0k
            size_t already_read = 0;
2365
4.23M
            while ((nrows_to_read - already_read) > 0) {
2366
4.20M
                bool is_null = false;
2367
4.20M
                size_t this_run = std::min(nrows_to_read - already_read, _page.remaining());
2368
4.20M
                if (UNLIKELY(this_run == 0)) {
2369
187
                    break;
2370
187
                }
2371
4.20M
                this_run = _page.null_decoder.GetNextRun(&is_null, this_run);
2372
4.20M
                size_t offset = total_read_count + already_read;
2373
4.20M
                size_t this_read_count = 0;
2374
4.20M
                rowid_t current_ordinal_in_page =
2375
4.20M
                        cast_set<uint32_t>(_page.offset_in_page + _page.first_ordinal);
2376
20.5M
                for (size_t i = 0; i < this_run; ++i) {
2377
19.3M
                    if (rowids[offset + i] - current_ordinal_in_page >= this_run) {
2378
2.99M
                        break;
2379
2.99M
                    }
2380
16.3M
                    this_read_count++;
2381
16.3M
                }
2382
2383
4.20M
                auto origin_index = _page.data_decoder->current_index();
2384
4.20M
                if (this_read_count > 0) {
2385
1.21M
                    if (is_null) {
2386
622k
                        auto* null_col = check_and_get_column<ColumnNullable>(dst.get());
2387
622k
                        if (UNLIKELY(null_col == nullptr)) {
2388
0
                            return Status::InternalError("unexpected column type in column reader");
2389
0
                        }
2390
2391
622k
                        null_col->insert_many_defaults(this_read_count);
2392
622k
                    } else {
2393
596k
                        size_t read_count = this_read_count;
2394
2395
                        // ordinal in nullable columns' data buffer maybe be not continuously(the data doesn't contain null value),
2396
                        // so we need use `page_start_off_in_decoder` to calculate the actual offset in `data_decoder`
2397
596k
                        size_t page_start_off_in_decoder =
2398
596k
                                _page.first_ordinal + _page.offset_in_page - origin_index;
2399
596k
                        RETURN_IF_ERROR(_page.data_decoder->read_by_rowids(
2400
596k
                                &rowids[offset], page_start_off_in_decoder, &read_count, dst));
2401
596k
                        DCHECK_EQ(read_count, this_read_count);
2402
596k
                    }
2403
1.21M
                }
2404
2405
4.20M
                if (!is_null) {
2406
3.55M
                    RETURN_IF_ERROR(
2407
3.55M
                            _page.data_decoder->seek_to_position_in_page(origin_index + this_run));
2408
3.55M
                }
2409
2410
4.20M
                already_read += this_read_count;
2411
4.20M
                _page.offset_in_page += this_run;
2412
4.20M
                DCHECK(_page.offset_in_page <= _page.num_rows);
2413
4.20M
            }
2414
2415
34.0k
            nrows_to_read = already_read;
2416
34.0k
            total_read_count += nrows_to_read;
2417
34.0k
            remaining -= nrows_to_read;
2418
225k
        } else {
2419
225k
            RETURN_IF_ERROR(_page.data_decoder->read_by_rowids(
2420
225k
                    &rowids[total_read_count], _page.first_ordinal, &nrows_to_read, dst));
2421
225k
            total_read_count += nrows_to_read;
2422
225k
            remaining -= nrows_to_read;
2423
225k
        }
2424
259k
    }
2425
242k
    return Status::OK();
2426
242k
}
2427
2428
24.2k
Status FileColumnIterator::_load_next_page(bool* eos) {
2429
24.2k
    _page_iter.next();
2430
24.2k
    if (!_page_iter.valid()) {
2431
0
        *eos = true;
2432
0
        return Status::OK();
2433
0
    }
2434
2435
24.2k
    RETURN_IF_ERROR(_read_data_page(_page_iter));
2436
24.2k
    RETURN_IF_ERROR(_seek_to_pos_in_page(&_page, 0));
2437
24.2k
    *eos = false;
2438
24.2k
    return Status::OK();
2439
24.2k
}
2440
2441
489k
Status FileColumnIterator::_read_data_page(const OrdinalPageIndexIterator& iter) {
2442
489k
    PageHandle handle;
2443
489k
    Slice page_body;
2444
489k
    PageFooterPB footer;
2445
489k
    _opts.type = DATA_PAGE;
2446
489k
    PageDecoderOptions decoder_opts;
2447
489k
    decoder_opts.only_read_offsets = _opts.only_read_offsets;
2448
489k
    RETURN_IF_ERROR(
2449
489k
            _reader->read_page(_opts, iter.page(), &handle, &page_body, &footer, _compress_codec));
2450
    // parse data page
2451
489k
    auto st = ParsedPage::create(std::move(handle), page_body, footer.data_page_footer(),
2452
489k
                                 _reader->encoding_info(), iter.page(), iter.page_index(), &_page,
2453
489k
                                 decoder_opts);
2454
489k
    if (!st.ok()) {
2455
0
        LOG(WARNING) << "failed to create ParsedPage, file=" << _opts.file_reader->path().native()
2456
0
                     << ", page_offset=" << iter.page().offset << ", page_size=" << iter.page().size
2457
0
                     << ", page_index=" << iter.page_index() << ", error=" << st;
2458
0
        return st;
2459
0
    }
2460
2461
    // dictionary page is read when the first data page that uses it is read,
2462
    // this is to optimize the memory usage: when there is no query on one column, we could
2463
    // release the memory of dictionary page.
2464
    // note that concurrent iterators for the same column won't repeatedly read dictionary page
2465
    // because of page cache.
2466
489k
    if (_reader->encoding_info()->encoding() == DICT_ENCODING) {
2467
128k
        auto dict_page_decoder = reinterpret_cast<BinaryDictPageDecoder*>(_page.data_decoder.get());
2468
128k
        if (dict_page_decoder->is_dict_encoding()) {
2469
114k
            if (_dict_decoder == nullptr) {
2470
109k
                RETURN_IF_ERROR(_read_dict_data());
2471
109k
                CHECK_NOTNULL(_dict_decoder);
2472
109k
            }
2473
2474
114k
            dict_page_decoder->set_dict_decoder(cast_set<uint32_t>(_dict_decoder->count()),
2475
114k
                                                _dict_word_info.get());
2476
114k
        }
2477
128k
    }
2478
489k
    return Status::OK();
2479
489k
}
2480
2481
111k
Status FileColumnIterator::_read_dict_data() {
2482
111k
    CHECK_EQ(_reader->encoding_info()->encoding(), DICT_ENCODING);
2483
    // read dictionary page
2484
111k
    Slice dict_data;
2485
111k
    PageFooterPB dict_footer;
2486
111k
    _opts.type = INDEX_PAGE;
2487
2488
111k
    RETURN_IF_ERROR(_reader->read_page(_opts, _reader->get_dict_page_pointer(), &_dict_page_handle,
2489
111k
                                       &dict_data, &dict_footer, _compress_codec));
2490
111k
    const EncodingInfo* encoding_info;
2491
    // The dict pool stores strings of the outer column's type. Using the
2492
    // outer type (CHAR vs VARCHAR/STRING) lets the EncodingInfo pick a
2493
    // CHAR-strip pre-decoder so the cached dict page is already unpadded.
2494
111k
    RETURN_IF_ERROR(EncodingInfo::get(_reader->get_meta_type(),
2495
111k
                                      dict_footer.dict_page_footer().encoding(), &encoding_info));
2496
111k
    RETURN_IF_ERROR(encoding_info->create_page_decoder(dict_data, {}, _dict_decoder));
2497
111k
    RETURN_IF_ERROR(_dict_decoder->init());
2498
2499
111k
    _dict_word_info.reset(new StringRef[_dict_decoder->count()]);
2500
111k
    RETURN_IF_ERROR(_dict_decoder->get_dict_word_info(_dict_word_info.get()));
2501
111k
    return Status::OK();
2502
111k
}
2503
2504
Status FileColumnIterator::get_row_ranges_by_zone_map(
2505
        const AndBlockColumnPredicate* col_predicates,
2506
        const std::vector<std::shared_ptr<const ColumnPredicate>>* delete_predicates,
2507
44.8k
        RowRanges* row_ranges) {
2508
44.8k
    if (_reader->has_zone_map()) {
2509
44.8k
        RETURN_IF_ERROR(_reader->get_row_ranges_by_zone_map(col_predicates, delete_predicates,
2510
44.8k
                                                            row_ranges, _opts));
2511
44.8k
    }
2512
44.8k
    return Status::OK();
2513
44.8k
}
2514
2515
Status FileColumnIterator::get_row_ranges_by_bloom_filter(
2516
44.9k
        const AndBlockColumnPredicate* col_predicates, RowRanges* row_ranges) {
2517
44.9k
    if ((col_predicates->can_do_bloom_filter(false) && _reader->has_bloom_filter_index(false)) ||
2518
44.9k
        (col_predicates->can_do_bloom_filter(true) && _reader->has_bloom_filter_index(true))) {
2519
5
        RETURN_IF_ERROR(_reader->get_row_ranges_by_bloom_filter(col_predicates, row_ranges, _opts));
2520
5
    }
2521
44.9k
    return Status::OK();
2522
44.9k
}
2523
2524
Status FileColumnIterator::get_row_ranges_by_dict(const AndBlockColumnPredicate* col_predicates,
2525
45.9k
                                                  RowRanges* row_ranges) {
2526
45.9k
    if (!_is_all_dict_encoding) {
2527
39.6k
        return Status::OK();
2528
39.6k
    }
2529
2530
6.31k
    if (!_dict_decoder) {
2531
1.95k
        RETURN_IF_ERROR(_read_dict_data());
2532
1.95k
        CHECK_NOTNULL(_dict_decoder);
2533
1.95k
    }
2534
2535
6.31k
    if (!col_predicates->evaluate_and(_dict_word_info.get(), _dict_decoder->count())) {
2536
690
        row_ranges->clear();
2537
690
    }
2538
6.31k
    return Status::OK();
2539
6.31k
}
2540
2541
87.9k
Status FileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
2542
87.9k
    if (_cached_remote_file_reader =
2543
87.9k
                std::dynamic_pointer_cast<io::CachedRemoteFileReader>(_reader->_file_reader);
2544
87.9k
        !_cached_remote_file_reader) {
2545
0
        return Status::OK();
2546
0
    }
2547
87.9k
    _enable_prefetch = true;
2548
87.9k
    _prefetcher = std::make_unique<SegmentPrefetcher>(params.config);
2549
87.9k
    RETURN_IF_ERROR(_prefetcher->init(_reader, params.read_options));
2550
87.9k
    return Status::OK();
2551
87.9k
}
2552
2553
void FileColumnIterator::collect_prefetchers(
2554
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
2555
87.9k
        PrefetcherInitMethod init_method) {
2556
87.9k
    if (_prefetcher) {
2557
87.9k
        prefetchers[init_method].emplace_back(_prefetcher.get());
2558
87.9k
    }
2559
87.9k
}
2560
2561
13.7k
Status DefaultValueColumnIterator::init(const ColumnIteratorOptions& opts) {
2562
13.7k
    _opts = opts;
2563
    // be consistent with segment v1
2564
    // if _has_default_value, we should create default column iterator for this column, and
2565
    // "NULL" is a special default value which means the default value is null.
2566
13.7k
    if (_has_default_value) {
2567
729
        if (_default_value == "NULL") {
2568
153
            _default_value_field = Field::create_field<TYPE_NULL>(Null {});
2569
576
        } else {
2570
576
            if (_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
2571
8
                if (_default_value != "[]") {
2572
0
                    return Status::NotSupported("Array default {} is unsupported", _default_value);
2573
8
                } else {
2574
8
                    _default_value_field = Field::create_field<TYPE_ARRAY>(Array {});
2575
8
                    return Status::OK();
2576
8
                }
2577
568
            } else if (_type == FieldType::OLAP_FIELD_TYPE_STRUCT) {
2578
0
                return Status::NotSupported("STRUCT default type is unsupported");
2579
568
            } else if (_type == FieldType::OLAP_FIELD_TYPE_MAP) {
2580
0
                return Status::NotSupported("MAP default type is unsupported");
2581
0
            }
2582
568
            const auto t = _type;
2583
568
            const auto serde = DataTypeFactory::instance()
2584
568
                                       .create_data_type(t, _precision, _scale, _len)
2585
568
                                       ->get_serde();
2586
568
            RETURN_IF_ERROR(serde->from_fe_string(_default_value, _default_value_field));
2587
568
        }
2588
13.0k
    } else if (_is_nullable) {
2589
13.0k
        _default_value_field = Field::create_field<TYPE_NULL>(Null {});
2590
18.4E
    } else {
2591
18.4E
        return Status::InternalError(
2592
18.4E
                "invalid default value column for no default value and not nullable");
2593
18.4E
    }
2594
13.7k
    return Status::OK();
2595
13.7k
}
2596
2597
1.53k
Status DefaultValueColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2598
1.53k
    *has_null = _default_value_field.is_null();
2599
1.53k
    _insert_many_default(dst, *n);
2600
1.53k
    return Status::OK();
2601
1.53k
}
2602
2603
Status DefaultValueColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
2604
3.05k
                                                  MutableColumnPtr& dst) {
2605
3.05k
    _insert_many_default(dst, count);
2606
3.05k
    return Status::OK();
2607
3.05k
}
2608
2609
4.59k
void DefaultValueColumnIterator::_insert_many_default(MutableColumnPtr& dst, size_t n) {
2610
4.59k
    if (_default_value_field.is_null()) {
2611
4.34k
        dst->insert_many_defaults(n);
2612
4.34k
    } else {
2613
251
        dst = dst->convert_to_predicate_column_if_dictionary();
2614
251
        dst->insert_duplicate_fields(_default_value_field, n);
2615
251
    }
2616
4.59k
}
2617
2618
3.05k
Status RowIdColumnIteratorV2::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2619
3.05k
    auto* string_column = assert_cast<ColumnString*, TypeCheckOnRelease::DISABLE>(dst.get());
2620
2621
10.8M
    for (uint32_t i = 0; i < *n; ++i) {
2622
10.8M
        uint32_t row_id = _current_rowid + i;
2623
10.8M
        GlobalRowLoacationV2 location(_version, _backend_id, _file_id, row_id);
2624
10.8M
        string_column->insert_data(reinterpret_cast<const char*>(&location),
2625
10.8M
                                   sizeof(GlobalRowLoacationV2));
2626
10.8M
    }
2627
3.05k
    _current_rowid += *n;
2628
3.05k
    return Status::OK();
2629
3.05k
}
2630
2631
Status RowIdColumnIteratorV2::read_by_rowids(const rowid_t* rowids, const size_t count,
2632
5.83k
                                             MutableColumnPtr& dst) {
2633
5.83k
    auto* string_column = assert_cast<ColumnString*>(dst.get());
2634
2635
12.9M
    for (size_t i = 0; i < count; ++i) {
2636
12.9M
        uint32_t row_id = rowids[i];
2637
12.9M
        GlobalRowLoacationV2 location(_version, _backend_id, _file_id, row_id);
2638
12.9M
        string_column->insert_data(reinterpret_cast<const char*>(&location),
2639
12.9M
                                   sizeof(GlobalRowLoacationV2));
2640
12.9M
    }
2641
5.83k
    return Status::OK();
2642
5.83k
}
2643
2644
} // namespace doris::segment_v2