Coverage Report

Created: 2026-06-03 04:12

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