Coverage Report

Created: 2026-06-04 06:55

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
903
inline bool read_as_string(PrimitiveType type) {
89
903
    return type == PrimitiveType::TYPE_STRING || type == PrimitiveType::INVALID_TYPE ||
90
903
           type == PrimitiveType::TYPE_BITMAP || type == PrimitiveType::TYPE_FIXED_LENGTH_OBJECT;
91
903
}
92
93
Status ColumnReader::create_array(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
94
                                  const io::FileReaderSPtr& file_reader,
95
62.4k
                                  std::shared_ptr<ColumnReader>* reader) {
96
62.4k
    DCHECK(meta.children_columns_size() == 2 || meta.children_columns_size() == 3);
97
98
62.4k
    std::shared_ptr<ColumnReader> item_reader;
99
62.4k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(0),
100
62.4k
                                         meta.children_columns(0).num_rows(), file_reader,
101
62.4k
                                         &item_reader));
102
103
62.4k
    std::shared_ptr<ColumnReader> offset_reader;
104
62.4k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(1),
105
62.4k
                                         meta.children_columns(1).num_rows(), file_reader,
106
62.4k
                                         &offset_reader));
107
108
62.4k
    std::shared_ptr<ColumnReader> null_reader;
109
62.4k
    if (meta.is_nullable()) {
110
44.6k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(2),
111
44.6k
                                             meta.children_columns(2).num_rows(), file_reader,
112
44.6k
                                             &null_reader));
113
44.6k
    }
114
115
    // The num rows of the array reader equals to the num rows of the length reader.
116
62.4k
    uint64_t array_num_rows = meta.children_columns(1).num_rows();
117
62.4k
    std::shared_ptr<ColumnReader> array_reader(
118
62.4k
            new ColumnReader(opts, meta, array_num_rows, file_reader));
119
    //  array reader do not need to init
120
62.4k
    array_reader->_sub_readers.resize(meta.children_columns_size());
121
62.4k
    array_reader->_sub_readers[0] = std::move(item_reader);
122
62.4k
    array_reader->_sub_readers[1] = std::move(offset_reader);
123
62.4k
    if (meta.is_nullable()) {
124
44.4k
        array_reader->_sub_readers[2] = std::move(null_reader);
125
44.4k
    }
126
62.4k
    array_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_ARRAY;
127
62.4k
    *reader = std::move(array_reader);
128
62.4k
    return Status::OK();
129
62.4k
}
130
131
Status ColumnReader::create_map(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
132
                                const io::FileReaderSPtr& file_reader,
133
75.0k
                                std::shared_ptr<ColumnReader>* reader) {
134
    // map reader now has 3 sub readers for key, value, offsets(scalar), null(scala)
135
75.0k
    DCHECK(meta.children_columns_size() == 3 || meta.children_columns_size() == 4);
136
75.0k
    std::shared_ptr<ColumnReader> key_reader;
137
75.0k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(0),
138
75.0k
                                         meta.children_columns(0).num_rows(), file_reader,
139
75.0k
                                         &key_reader));
140
75.0k
    std::shared_ptr<ColumnReader> val_reader;
141
75.0k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(1),
142
75.0k
                                         meta.children_columns(1).num_rows(), file_reader,
143
75.0k
                                         &val_reader));
144
75.0k
    std::shared_ptr<ColumnReader> offset_reader;
145
75.0k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(2),
146
75.0k
                                         meta.children_columns(2).num_rows(), file_reader,
147
75.0k
                                         &offset_reader));
148
75.0k
    std::shared_ptr<ColumnReader> null_reader;
149
75.0k
    if (meta.is_nullable()) {
150
14.9k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(3),
151
14.9k
                                             meta.children_columns(3).num_rows(), file_reader,
152
14.9k
                                             &null_reader));
153
14.9k
    }
154
155
    // The num rows of the map reader equals to the num rows of the length reader.
156
75.0k
    uint64_t map_num_rows = meta.children_columns(2).num_rows();
157
75.0k
    std::shared_ptr<ColumnReader> map_reader(
158
75.0k
            new ColumnReader(opts, meta, map_num_rows, file_reader));
159
75.0k
    map_reader->_sub_readers.resize(meta.children_columns_size());
160
161
75.0k
    map_reader->_sub_readers[0] = std::move(key_reader);
162
75.0k
    map_reader->_sub_readers[1] = std::move(val_reader);
163
75.0k
    map_reader->_sub_readers[2] = std::move(offset_reader);
164
75.0k
    if (meta.is_nullable()) {
165
14.8k
        map_reader->_sub_readers[3] = std::move(null_reader);
166
14.8k
    }
167
75.0k
    map_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_MAP;
168
75.0k
    *reader = std::move(map_reader);
169
75.0k
    return Status::OK();
170
75.0k
}
171
172
Status ColumnReader::create_struct(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
173
                                   uint64_t num_rows, const io::FileReaderSPtr& file_reader,
174
7.74k
                                   std::shared_ptr<ColumnReader>* reader) {
175
    // not support empty struct
176
7.74k
    DCHECK(meta.children_columns_size() >= 1);
177
    // create struct column reader
178
7.74k
    std::shared_ptr<ColumnReader> struct_reader(
179
7.74k
            new ColumnReader(opts, meta, num_rows, file_reader));
180
7.74k
    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.74k
    struct_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_STRUCT;
190
7.74k
    *reader = std::move(struct_reader);
191
7.74k
    return Status::OK();
192
7.74k
}
193
194
Status ColumnReader::create_agg_state(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
195
                                      uint64_t num_rows, const io::FileReaderSPtr& file_reader,
196
904
                                      std::shared_ptr<ColumnReader>* reader) {
197
904
    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
904
    auto data_type = DataTypeFactory::instance().create_data_type(meta);
206
904
    const auto* agg_state_type = assert_cast<const DataTypeAggState*>(data_type.get());
207
904
    agg_state_type->check_function_compatibility(opts.be_exec_version);
208
904
    auto type = agg_state_type->get_serialized_type()->get_primitive_type();
209
210
904
    if (read_as_string(type)) {
211
845
        std::shared_ptr<ColumnReader> reader_local(
212
845
                new ColumnReader(opts, meta, num_rows, file_reader));
213
845
        RETURN_IF_ERROR(reader_local->init(&meta));
214
845
        *reader = std::move(reader_local);
215
845
        return Status::OK();
216
845
    } else if (type == PrimitiveType::TYPE_MAP) {
217
42
        return create_map(opts, meta, file_reader, reader);
218
42
    } 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
4
    return Status::InternalError("Not supported type: {}, serialized type: {}",
225
4
                                 agg_state_type->get_name(), int(type));
226
904
}
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
24.2M
                            std::shared_ptr<ColumnReader>* reader) {
239
24.2M
    if (is_scalar_type((FieldType)meta.type())) {
240
24.0M
        std::shared_ptr<ColumnReader> reader_local(
241
24.0M
                new ColumnReader(opts, meta, num_rows, file_reader));
242
24.0M
        RETURN_IF_ERROR(reader_local->init(&meta));
243
24.0M
        *reader = std::move(reader_local);
244
24.0M
        return Status::OK();
245
24.0M
    } else {
246
168k
        auto type = (FieldType)meta.type();
247
168k
        switch (type) {
248
905
        case FieldType::OLAP_FIELD_TYPE_AGG_STATE: {
249
905
            return create_agg_state(opts, meta, num_rows, file_reader, reader);
250
0
        }
251
7.74k
        case FieldType::OLAP_FIELD_TYPE_STRUCT: {
252
7.74k
            return create_struct(opts, meta, num_rows, file_reader, reader);
253
0
        }
254
62.4k
        case FieldType::OLAP_FIELD_TYPE_ARRAY: {
255
62.4k
            return create_array(opts, meta, file_reader, reader);
256
0
        }
257
75.0k
        case FieldType::OLAP_FIELD_TYPE_MAP: {
258
75.0k
            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
168k
        }
272
168k
    }
273
24.2M
}
274
275
19.7k
ColumnReader::ColumnReader() = default;
276
277
ColumnReader::ColumnReader(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
278
                           uint64_t num_rows, io::FileReaderSPtr file_reader)
279
24.2M
        : _use_index_page_cache(!config::disable_storage_page_cache),
280
24.2M
          _opts(opts),
281
24.2M
          _num_rows(num_rows),
282
24.2M
          _file_reader(std::move(file_reader)),
283
24.2M
          _dict_encoding_type(UNKNOWN_DICT_ENCODING) {
284
24.2M
    _meta_length = meta.length();
285
24.2M
    _meta_type = (FieldType)meta.type();
286
24.2M
    if (_meta_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
287
62.4k
        _meta_children_column_type = (FieldType)meta.children_columns(0).type();
288
62.4k
    }
289
24.2M
    _data_type = DataTypeFactory::instance().create_data_type(meta);
290
24.2M
    _meta_is_nullable = meta.is_nullable();
291
24.2M
    _meta_dict_page = meta.dict_page();
292
24.2M
    _meta_compression = meta.compression();
293
24.2M
}
294
295
24.3M
ColumnReader::~ColumnReader() = default;
296
297
24.1M
int64_t ColumnReader::get_metadata_size() const {
298
24.1M
    return sizeof(ColumnReader) + (_segment_zone_map ? _segment_zone_map->ByteSizeLong() : 0);
299
24.1M
}
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
24.0M
Status ColumnReader::init(const ColumnMetaPB* meta) {
351
24.0M
    _type = (FieldType)meta->type();
352
353
24.0M
    if (meta->has_be_exec_version()) {
354
23.7M
        _be_exec_version = meta->be_exec_version();
355
23.7M
    }
356
357
24.1M
    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
24.0M
    RETURN_IF_ERROR(EncodingInfo::get(_type, meta->encoding(), &_encoding_info));
361
362
71.6M
    for (int i = 0; i < meta->indexes_size(); i++) {
363
47.5M
        const auto& index_meta = meta->indexes(i);
364
47.5M
        switch (index_meta.type()) {
365
0
        case BITMAP_INDEX:
366
0
            break;
367
24.0M
        case ORDINAL_INDEX:
368
24.0M
            _ordinal_index.reset(
369
24.0M
                    new OrdinalIndexReader(_file_reader, _num_rows, index_meta.ordinal_index()));
370
24.0M
            break;
371
23.5M
        case ZONE_MAP_INDEX:
372
23.5M
            _segment_zone_map =
373
23.5M
                    std::make_unique<ZoneMapPB>(index_meta.zone_map_index().segment_zone_map());
374
23.5M
            _zone_map_index.reset(new ZoneMapIndexReader(
375
23.5M
                    _file_reader, index_meta.zone_map_index().page_zone_maps()));
376
23.5M
            break;
377
5.43k
        case BLOOM_FILTER_INDEX:
378
5.43k
            _bloom_filter_index.reset(
379
5.43k
                    new BloomFilterIndexReader(_file_reader, index_meta.bloom_filter_index()));
380
5.43k
            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
47.5M
        }
387
47.5M
    }
388
24.0M
    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
24.0M
    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
24.0M
    return Status::OK();
398
24.0M
}
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
77.6k
                                        std::unique_ptr<IndexIterator>* iterator) {
404
77.6k
    RETURN_IF_ERROR(
405
77.6k
            _load_index(index_file_reader, index_meta, rowset_id, segment_id, rows_of_segment));
406
77.6k
    {
407
77.6k
        std::shared_lock<std::shared_mutex> rlock(_load_index_lock);
408
77.6k
        auto iter = _index_readers.find(index_meta->index_id());
409
77.8k
        if (iter != _index_readers.end()) {
410
77.8k
            if (iter->second != nullptr) {
411
77.8k
                RETURN_IF_ERROR(iter->second->new_iterator(iterator));
412
77.8k
            }
413
77.8k
        }
414
77.6k
    }
415
77.6k
    return Status::OK();
416
77.6k
}
417
418
Status ColumnReader::read_page(const ColumnIteratorOptions& iter_opts, const PagePointer& pp,
419
                               PageHandle* handle, Slice* page_body, PageFooterPB* footer,
420
1.86M
                               BlockCompressionCodec* codec) const {
421
1.86M
    SCOPED_CONCURRENCY_COUNT(ConcurrencyStatsManager::instance().column_reader_read_page);
422
1.86M
    iter_opts.sanity_check();
423
1.86M
    PageReadOptions opts(iter_opts.io_ctx);
424
1.86M
    opts.verify_checksum = _opts.verify_checksum;
425
1.86M
    opts.use_page_cache = iter_opts.use_page_cache;
426
1.86M
    opts.kept_in_memory = _opts.kept_in_memory;
427
1.86M
    opts.type = iter_opts.type;
428
1.86M
    opts.file_reader = iter_opts.file_reader;
429
1.86M
    opts.page_pointer = pp;
430
1.86M
    opts.codec = codec;
431
1.86M
    opts.stats = iter_opts.stats;
432
1.86M
    opts.encoding_info = _encoding_info;
433
434
1.86M
    return PageIO::read_and_decompress_page(opts, handle, page_body, footer);
435
1.86M
}
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
101k
        RowRanges* row_ranges, const ColumnIteratorOptions& iter_opts) {
441
101k
    std::vector<uint32_t> page_indexes;
442
101k
    RETURN_IF_ERROR(
443
101k
            _get_filtered_pages(col_predicates, delete_predicates, &page_indexes, iter_opts));
444
101k
    RETURN_IF_ERROR(_calculate_row_ranges(page_indexes, row_ranges, iter_opts));
445
101k
    return Status::OK();
446
101k
}
447
448
9.12k
Status ColumnReader::next_batch_of_zone_map(size_t* n, MutableColumnPtr& dst) const {
449
9.12k
    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
9.12k
    ZoneMap zone_map;
454
9.12k
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
455
456
9.12k
    dst->reserve(*n);
457
9.12k
    if (!zone_map.has_not_null) {
458
567
        assert_cast<ColumnNullable&>(*dst).insert_many_defaults(*n);
459
567
        return Status::OK();
460
567
    }
461
8.56k
    dst->insert(zone_map.max_value);
462
17.1k
    for (int i = 1; i < *n; ++i) {
463
8.58k
        dst->insert(zone_map.min_value);
464
8.58k
    }
465
8.56k
    return Status::OK();
466
9.12k
}
467
468
Status ColumnReader::match_condition(const AndBlockColumnPredicate* col_predicates,
469
1.53M
                                     bool* matched) const {
470
1.53M
    *matched = true;
471
1.53M
    if (_zone_map_index == nullptr) {
472
0
        return Status::OK();
473
0
    }
474
1.53M
    ZoneMap zone_map;
475
1.53M
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
476
477
1.53M
    *matched = _zone_map_match_condition(zone_map, col_predicates);
478
1.53M
    return Status::OK();
479
1.53M
}
480
481
Status ColumnReader::prune_predicates_by_zone_map(
482
        std::vector<std::shared_ptr<ColumnPredicate>>& predicates, const int column_id,
483
1.48M
        bool* pruned) const {
484
1.48M
    *pruned = false;
485
1.48M
    if (_zone_map_index == nullptr) {
486
105
        return Status::OK();
487
105
    }
488
489
1.48M
    ZoneMap zone_map;
490
1.48M
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
491
1.48M
    if (zone_map.pass_all) {
492
0
        return Status::OK();
493
0
    }
494
495
3.11M
    for (auto it = predicates.begin(); it != predicates.end();) {
496
1.62M
        auto predicate = *it;
497
1.62M
        if (predicate->column_id() == column_id && predicate->is_always_true(zone_map)) {
498
12.4k
            *pruned = true;
499
12.4k
            it = predicates.erase(it);
500
1.61M
        } else {
501
1.61M
            ++it;
502
1.61M
        }
503
1.62M
    }
504
1.48M
    return Status::OK();
505
1.48M
}
506
507
bool ColumnReader::_zone_map_match_condition(const ZoneMap& zone_map,
508
1.61M
                                             const AndBlockColumnPredicate* col_predicates) const {
509
1.61M
    if (zone_map.pass_all) {
510
0
        return true;
511
0
    }
512
513
1.61M
    return col_predicates->evaluate_and(zone_map);
514
1.61M
}
515
516
Status ColumnReader::_get_filtered_pages(
517
        const AndBlockColumnPredicate* col_predicates,
518
        const std::vector<std::shared_ptr<const ColumnPredicate>>* delete_predicates,
519
101k
        std::vector<uint32_t>* page_indexes, const ColumnIteratorOptions& iter_opts) {
520
101k
    RETURN_IF_ERROR(_load_zone_map_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
521
522
101k
    const std::vector<ZoneMapPB>& zone_maps = _zone_map_index->page_zone_maps();
523
101k
    size_t page_size = _zone_map_index->num_pages();
524
248k
    for (size_t i = 0; i < page_size; ++i) {
525
147k
        if (zone_maps[i].pass_all()) {
526
62.7k
            page_indexes->push_back(cast_set<uint32_t>(i));
527
84.7k
        } else {
528
84.7k
            segment_v2::ZoneMap zone_map;
529
84.7k
            RETURN_IF_ERROR(ZoneMap::from_proto(zone_maps[i], _data_type, zone_map));
530
84.7k
            if (_zone_map_match_condition(zone_map, col_predicates)) {
531
84.6k
                bool should_read = true;
532
84.6k
                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
84.6k
                if (should_read) {
543
84.6k
                    page_indexes->push_back(cast_set<uint32_t>(i));
544
84.6k
                }
545
84.6k
            }
546
84.7k
        }
547
147k
    }
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
101k
    return Status::OK();
553
101k
}
554
555
Status ColumnReader::_calculate_row_ranges(const std::vector<uint32_t>& page_indexes,
556
                                           RowRanges* row_ranges,
557
102k
                                           const ColumnIteratorOptions& iter_opts) {
558
102k
    row_ranges->clear();
559
102k
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
560
147k
    for (auto i : page_indexes) {
561
147k
        ordinal_t page_first_id = _ordinal_index->get_first_ordinal(i);
562
147k
        ordinal_t page_last_id = _ordinal_index->get_last_ordinal(i);
563
147k
        RowRanges page_row_ranges(RowRanges::create_single(page_first_id, page_last_id + 1));
564
147k
        RowRanges::ranges_union(*row_ranges, page_row_ranges, row_ranges);
565
147k
    }
566
102k
    return Status::OK();
567
102k
}
568
569
Status ColumnReader::get_row_ranges_by_bloom_filter(const AndBlockColumnPredicate* col_predicates,
570
                                                    RowRanges* row_ranges,
571
112
                                                    const ColumnIteratorOptions& iter_opts) {
572
112
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
573
112
    RETURN_IF_ERROR(
574
112
            _load_bloom_filter_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
575
112
    RowRanges bf_row_ranges;
576
112
    std::unique_ptr<BloomFilterIndexIterator> bf_iter;
577
112
    RETURN_IF_ERROR(_bloom_filter_index->new_iterator(&bf_iter, iter_opts.stats));
578
112
    size_t range_size = row_ranges->range_size();
579
    // get covered page ids
580
112
    std::set<uint32_t> page_ids;
581
224
    for (int i = 0; i < range_size; ++i) {
582
112
        int64_t from = row_ranges->get_range_from(i);
583
112
        int64_t idx = from;
584
112
        int64_t to = row_ranges->get_range_to(i);
585
112
        auto iter = _ordinal_index->seek_at_or_before(from);
586
448
        while (idx < to && iter.valid()) {
587
336
            page_ids.insert(iter.page_index());
588
336
            idx = iter.last_ordinal() + 1;
589
336
            iter.next();
590
336
        }
591
112
    }
592
336
    for (auto& pid : page_ids) {
593
336
        std::unique_ptr<BloomFilter> bf;
594
336
        RETURN_IF_ERROR(bf_iter->read_bloom_filter(pid, &bf));
595
336
        if (col_predicates->evaluate_and(bf.get())) {
596
21
            bf_row_ranges.add(RowRange(_ordinal_index->get_first_ordinal(pid),
597
21
                                       _ordinal_index->get_last_ordinal(pid) + 1));
598
21
        }
599
336
    }
600
112
    RowRanges::ranges_intersection(*row_ranges, bf_row_ranges, row_ranges);
601
112
    return Status::OK();
602
112
}
603
604
Status ColumnReader::_load_ordinal_index(bool use_page_cache, bool kept_in_memory,
605
1.55M
                                         const ColumnIteratorOptions& iter_opts) {
606
1.55M
    if (!_ordinal_index) {
607
0
        return Status::InternalError("ordinal_index not inited");
608
0
    }
609
1.55M
    return _ordinal_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
610
1.55M
}
611
612
Status ColumnReader::_load_zone_map_index(bool use_page_cache, bool kept_in_memory,
613
101k
                                          const ColumnIteratorOptions& iter_opts) {
614
101k
    if (_zone_map_index != nullptr) {
615
101k
        return _zone_map_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
616
101k
    }
617
18.4E
    return Status::OK();
618
101k
}
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
77.5k
                                 uint32_t segment_id, size_t rows_of_segment) {
623
77.5k
    std::unique_lock<std::shared_mutex> wlock(_load_index_lock);
624
625
77.5k
    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
77.5k
    auto it = _index_readers.find(index_meta->index_id());
631
77.5k
    if (it != _index_readers.end()) {
632
0
        return Status::OK();
633
0
    }
634
635
77.5k
    bool should_analyzer =
636
77.5k
            inverted_index::InvertedIndexAnalyzer::should_analyzer(index_meta->properties());
637
638
77.5k
    FieldType type;
639
77.5k
    if (_meta_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
640
6.49k
        type = _meta_children_column_type;
641
71.0k
    } else {
642
71.0k
        type = _type;
643
71.0k
    }
644
645
77.5k
    if (index_meta->index_type() == IndexType::ANN) {
646
154
        _index_readers[index_meta->index_id()] = std::make_shared<AnnIndexReader>(
647
154
                index_meta, index_file_reader, rowset_id, segment_id, rows_of_segment);
648
154
        return Status::OK();
649
154
    }
650
651
77.4k
    IndexReaderPtr index_reader;
652
653
77.4k
    if (is_string_type(type)) {
654
41.8k
        if (should_analyzer) {
655
24.5k
            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.5k
                if (index_file_reader->get_storage_format() == InvertedIndexStorageFormatPB::V4) {
661
503
                    index_reader =
662
503
                            SpimiFulltextIndexReader::create_shared(index_meta, index_file_reader);
663
24.0k
                } else {
664
24.0k
                    index_reader =
665
24.0k
                            FullTextIndexReader::create_shared(index_meta, index_file_reader);
666
24.0k
                }
667
24.5k
            } 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.5k
        } 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.2k
            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.2k
            try {
684
17.2k
                index_reader =
685
17.2k
                        StringTypeInvertedIndexReader::create_shared(index_meta, index_file_reader);
686
17.2k
            } 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.2k
        }
691
41.8k
    } else if (is_numeric_type(type)) {
692
35.7k
        try {
693
35.7k
            index_reader = BkdIndexReader::create_shared(index_meta, index_file_reader);
694
35.7k
        } 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
77.5k
    _index_readers[index_meta->index_id()] = index_reader;
703
77.5k
    return Status::OK();
704
77.4k
}
705
706
78.2k
bool ColumnReader::has_bloom_filter_index(bool ngram) const {
707
78.4k
    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
112
                                              const ColumnIteratorOptions& iter_opts) {
718
112
    if (_bloom_filter_index != nullptr) {
719
112
        return _bloom_filter_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
720
112
    }
721
0
    return Status::OK();
722
112
}
723
724
Status ColumnReader::seek_at_or_before(ordinal_t ordinal, OrdinalPageIndexIterator* iter,
725
1.44M
                                       const ColumnIteratorOptions& iter_opts) {
726
1.44M
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
727
1.44M
    *iter = _ordinal_index->seek_at_or_before(ordinal);
728
1.44M
    if (!iter->valid()) {
729
0
        return Status::NotFound("Failed to seek to ordinal {}, ", ordinal);
730
0
    }
731
1.44M
    return Status::OK();
732
1.44M
}
733
734
Status ColumnReader::get_ordinal_index_reader(OrdinalIndexReader*& reader,
735
297k
                                              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
297k
    RETURN_IF_ERROR(
739
297k
            _ordinal_index->load(_use_index_page_cache, _opts.kept_in_memory, index_load_stats));
740
297k
    reader = _ordinal_index.get();
741
297k
    return Status::OK();
742
297k
}
743
744
378k
Status ColumnReader::new_iterator(ColumnIteratorUPtr* iterator, const TabletColumn* tablet_column) {
745
378k
    return new_iterator(iterator, tablet_column, nullptr);
746
378k
}
747
748
Status ColumnReader::new_iterator(ColumnIteratorUPtr* iterator, const TabletColumn* tablet_column,
749
22.6M
                                  const StorageReadOptions* opt) {
750
22.6M
    if (is_empty()) {
751
44.2k
        *iterator = std::make_unique<EmptyFileColumnIterator>();
752
44.2k
        return Status::OK();
753
44.2k
    }
754
22.6M
    if (is_scalar_type(_meta_type)) {
755
22.5M
        if (is_string_type(_meta_type)) {
756
13.4M
            *iterator = std::make_unique<StringFileColumnIterator>(shared_from_this());
757
13.4M
        } else {
758
9.03M
            *iterator = std::make_unique<FileColumnIterator>(shared_from_this());
759
9.03M
        }
760
22.5M
        (*iterator)->set_column_name(tablet_column ? tablet_column->name() : "");
761
22.5M
        return Status::OK();
762
22.5M
    } else {
763
91.7k
        auto type = _meta_type;
764
91.7k
        switch (type) {
765
850
        case FieldType::OLAP_FIELD_TYPE_AGG_STATE: {
766
850
            return new_agg_state_iterator(iterator);
767
0
        }
768
7.67k
        case FieldType::OLAP_FIELD_TYPE_STRUCT: {
769
7.67k
            return new_struct_iterator(iterator, tablet_column);
770
0
        }
771
61.7k
        case FieldType::OLAP_FIELD_TYPE_ARRAY: {
772
61.7k
            return new_array_iterator(iterator, tablet_column);
773
0
        }
774
35.7k
        case FieldType::OLAP_FIELD_TYPE_MAP: {
775
35.7k
            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
91.7k
        }
781
91.7k
    }
782
22.6M
}
783
784
850
Status ColumnReader::new_agg_state_iterator(ColumnIteratorUPtr* iterator) {
785
850
    *iterator = std::make_unique<FileColumnIterator>(shared_from_this());
786
850
    return Status::OK();
787
850
}
788
789
Status ColumnReader::new_array_iterator(ColumnIteratorUPtr* iterator,
790
61.7k
                                        const TabletColumn* tablet_column) {
791
61.7k
    ColumnIteratorUPtr item_iterator;
792
61.7k
    RETURN_IF_ERROR(_sub_readers[0]->new_iterator(
793
61.7k
            &item_iterator, tablet_column && tablet_column->get_subtype_count() > 0
794
61.7k
                                    ? &tablet_column->get_sub_column(0)
795
61.7k
                                    : nullptr));
796
797
61.7k
    item_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(0).name() : "");
798
799
61.7k
    ColumnIteratorUPtr offset_iterator;
800
61.7k
    RETURN_IF_ERROR(_sub_readers[1]->new_iterator(&offset_iterator, nullptr));
801
61.7k
    auto* file_iter = static_cast<FileColumnIterator*>(offset_iterator.release());
802
61.7k
    OffsetFileColumnIteratorUPtr ofcIter = std::make_unique<OffsetFileColumnIterator>(
803
61.7k
            std::unique_ptr<FileColumnIterator>(file_iter));
804
805
61.7k
    ColumnIteratorUPtr null_iterator;
806
61.7k
    if (is_nullable()) {
807
43.8k
        RETURN_IF_ERROR(_sub_readers[2]->new_iterator(&null_iterator, nullptr));
808
43.8k
    }
809
61.7k
    *iterator = std::make_unique<ArrayFileColumnIterator>(shared_from_this(), std::move(ofcIter),
810
61.7k
                                                          std::move(item_iterator),
811
61.7k
                                                          std::move(null_iterator));
812
61.7k
    return Status::OK();
813
61.7k
}
814
815
Status ColumnReader::new_map_iterator(ColumnIteratorUPtr* iterator,
816
35.6k
                                      const TabletColumn* tablet_column) {
817
35.6k
    ColumnIteratorUPtr key_iterator;
818
35.6k
    RETURN_IF_ERROR(_sub_readers[0]->new_iterator(
819
35.6k
            &key_iterator, tablet_column && tablet_column->get_subtype_count() > 1
820
35.6k
                                   ? &tablet_column->get_sub_column(0)
821
35.6k
                                   : nullptr));
822
35.6k
    key_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(0).name() : "");
823
35.6k
    ColumnIteratorUPtr val_iterator;
824
35.6k
    RETURN_IF_ERROR(_sub_readers[1]->new_iterator(
825
35.6k
            &val_iterator, tablet_column && tablet_column->get_subtype_count() > 1
826
35.6k
                                   ? &tablet_column->get_sub_column(1)
827
35.6k
                                   : nullptr));
828
35.6k
    val_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(1).name() : "");
829
35.6k
    ColumnIteratorUPtr offsets_iterator;
830
35.6k
    RETURN_IF_ERROR(_sub_readers[2]->new_iterator(&offsets_iterator, nullptr));
831
35.6k
    auto* file_iter = static_cast<FileColumnIterator*>(offsets_iterator.release());
832
35.6k
    OffsetFileColumnIteratorUPtr ofcIter = std::make_unique<OffsetFileColumnIterator>(
833
35.6k
            std::unique_ptr<FileColumnIterator>(file_iter));
834
835
35.6k
    ColumnIteratorUPtr null_iterator;
836
35.6k
    if (is_nullable()) {
837
14.8k
        RETURN_IF_ERROR(_sub_readers[3]->new_iterator(&null_iterator, nullptr));
838
14.8k
    }
839
35.6k
    *iterator = std::make_unique<MapFileColumnIterator>(
840
35.6k
            shared_from_this(), std::move(null_iterator), std::move(ofcIter),
841
35.6k
            std::move(key_iterator), std::move(val_iterator));
842
35.6k
    return Status::OK();
843
35.6k
}
844
845
Status ColumnReader::new_struct_iterator(ColumnIteratorUPtr* iterator,
846
7.67k
                                         const TabletColumn* tablet_column) {
847
7.67k
    std::vector<ColumnIteratorUPtr> sub_column_iterators;
848
7.67k
    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.67k
    sub_column_iterators.reserve(child_size);
851
852
33.5k
    for (uint64_t i = 0; i < child_size; i++) {
853
25.8k
        ColumnIteratorUPtr sub_column_iterator;
854
25.8k
        RETURN_IF_ERROR(_sub_readers[i]->new_iterator(
855
25.8k
                &sub_column_iterator, tablet_column ? &tablet_column->get_sub_column(i) : nullptr));
856
25.8k
        sub_column_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(i).name()
857
25.8k
                                                           : "");
858
25.8k
        sub_column_iterators.emplace_back(std::move(sub_column_iterator));
859
25.8k
    }
860
861
    // create default_iterator for schema-change behavior which increase column
862
8.97k
    for (size_t i = child_size; i < tablet_column_size; i++) {
863
1.30k
        TabletColumn column = tablet_column->get_sub_column(i);
864
1.30k
        ColumnIteratorUPtr it;
865
1.30k
        RETURN_IF_ERROR(Segment::new_default_iterator(column, &it));
866
1.30k
        it->set_column_name(column.name());
867
1.30k
        sub_column_iterators.emplace_back(std::move(it));
868
1.30k
    }
869
870
7.67k
    ColumnIteratorUPtr null_iterator;
871
7.67k
    if (is_nullable()) {
872
6.83k
        RETURN_IF_ERROR(_sub_readers[child_size]->new_iterator(&null_iterator, nullptr));
873
6.83k
    }
874
7.67k
    *iterator = std::make_unique<StructFileColumnIterator>(
875
7.67k
            shared_from_this(), std::move(null_iterator), std::move(sub_column_iterators));
876
7.67k
    return Status::OK();
877
7.67k
}
878
879
Result<TColumnAccessPaths> ColumnIterator::_get_sub_access_paths(
880
114k
        const TColumnAccessPaths& access_paths) {
881
114k
    TColumnAccessPaths sub_access_paths = access_paths;
882
176k
    for (auto it = sub_access_paths.begin(); it != sub_access_paths.end();) {
883
61.5k
        TColumnAccessPath& name_path = *it;
884
61.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
61.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
61.5k
        name_path.data_access_path.path.erase(name_path.data_access_path.path.begin());
896
61.5k
        if (!name_path.data_access_path.path.empty()) {
897
6.96k
            ++it;
898
54.5k
        } else {
899
54.5k
            set_need_to_read();
900
54.5k
            it = sub_access_paths.erase(it);
901
54.5k
        }
902
61.5k
    }
903
114k
    return sub_access_paths;
904
114k
}
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
35.7k
        : _map_reader(reader),
913
35.7k
          _offsets_iterator(std::move(offsets_iterator)),
914
35.7k
          _key_iterator(std::move(key_iterator)),
915
35.7k
          _val_iterator(std::move(val_iterator)) {
916
35.7k
    if (_map_reader->is_nullable()) {
917
14.8k
        _null_iterator = std::move(null_iterator);
918
14.8k
    }
919
35.7k
}
920
921
35.5k
Status MapFileColumnIterator::init(const ColumnIteratorOptions& opts) {
922
35.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
35.5k
    RETURN_IF_ERROR(_key_iterator->init(opts));
927
35.5k
    RETURN_IF_ERROR(_val_iterator->init(opts));
928
35.5k
    RETURN_IF_ERROR(_offsets_iterator->init(opts));
929
35.5k
    if (_map_reader->is_nullable()) {
930
14.7k
        RETURN_IF_ERROR(_null_iterator->init(opts));
931
14.7k
    }
932
35.5k
    return Status::OK();
933
35.5k
}
934
935
17.3k
Status MapFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
936
17.3k
    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.3k
    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.3k
    if (_map_reader->is_nullable()) {
950
10.4k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
951
10.4k
    }
952
17.3k
    RETURN_IF_ERROR(_offsets_iterator->seek_to_ordinal(ord));
953
17.3k
    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
16.8k
    ordinal_t offset = 0;
959
16.8k
    RETURN_IF_ERROR(_offsets_iterator->_peek_one_offset(&offset));
960
16.8k
    RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(offset));
961
16.8k
    RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(offset));
962
16.8k
    return Status::OK();
963
16.8k
}
964
965
1.34k
Status MapFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
966
1.34k
    RETURN_IF_ERROR(_offsets_iterator->init_prefetcher(params));
967
1.34k
    if (_map_reader->is_nullable()) {
968
1.32k
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
969
1.32k
    }
970
1.34k
    RETURN_IF_ERROR(_key_iterator->init_prefetcher(params));
971
1.34k
    RETURN_IF_ERROR(_val_iterator->init_prefetcher(params));
972
1.34k
    return Status::OK();
973
1.34k
}
974
975
void MapFileColumnIterator::collect_prefetchers(
976
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
977
1.34k
        PrefetcherInitMethod init_method) {
978
1.34k
    _offsets_iterator->collect_prefetchers(prefetchers, init_method);
979
1.34k
    if (_map_reader->is_nullable()) {
980
1.32k
        _null_iterator->collect_prefetchers(prefetchers, init_method);
981
1.32k
    }
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
1.34k
    _key_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
985
1.34k
    _val_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
986
1.34k
}
987
988
17.3k
Status MapFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
989
17.3k
    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.3k
    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.3k
    auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1020
17.3k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1021
17.3k
    auto column_offsets_ptr = IColumn::mutate(std::move(column_map.get_offsets_ptr()));
1022
17.3k
    Defer defer_offsets {[&] {
1023
17.3k
        auto typed_column_offsets_ptr = ColumnMap::COffsets::cast_to_column_mutptr(
1024
17.3k
                assert_cast<ColumnMap::COffsets*, TypeCheckOnRelease::DISABLE>(
1025
17.3k
                        column_offsets_ptr.get()));
1026
17.3k
        column_offsets_ptr = nullptr;
1027
17.3k
        column_map.get_offsets_ptr() = std::move(typed_column_offsets_ptr);
1028
17.3k
    }};
1029
17.3k
    bool offsets_has_null = false;
1030
17.3k
    ssize_t start = column_offsets_ptr->size();
1031
17.3k
    RETURN_IF_ERROR(_offsets_iterator->next_batch(n, column_offsets_ptr, &offsets_has_null));
1032
17.3k
    if (*n == 0) {
1033
0
        return Status::OK();
1034
0
    }
1035
17.3k
    auto& column_offsets = static_cast<ColumnArray::ColumnOffsets&>(*column_offsets_ptr);
1036
17.3k
    RETURN_IF_ERROR(_offsets_iterator->_calculate_offsets(start, column_offsets));
1037
17.3k
    DCHECK(column_offsets.get_data().back() >= column_offsets.get_data()[start - 1]);
1038
17.3k
    size_t num_items =
1039
17.3k
            column_offsets.get_data().back() - column_offsets.get_data()[start - 1]; // -1 is valid
1040
1041
17.3k
    if (num_items > 0) {
1042
14.2k
        auto key_ptr = IColumn::mutate(std::move(column_map.get_keys_ptr()));
1043
14.2k
        auto val_ptr = IColumn::mutate(std::move(column_map.get_values_ptr()));
1044
14.2k
        Defer defer_keys {[&] { column_map.get_keys_ptr() = std::move(key_ptr); }};
1045
14.2k
        Defer defer_values {[&] { column_map.get_values_ptr() = std::move(val_ptr); }};
1046
14.2k
        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
13.7k
        } else {
1051
13.7k
            size_t num_read = num_items;
1052
13.7k
            bool key_has_null = false;
1053
13.7k
            bool val_has_null = false;
1054
13.7k
            RETURN_IF_ERROR(_key_iterator->next_batch(&num_read, key_ptr, &key_has_null));
1055
13.7k
            RETURN_IF_ERROR(_val_iterator->next_batch(&num_read, val_ptr, &val_has_null));
1056
13.7k
            DCHECK(num_read == num_items);
1057
13.7k
        }
1058
14.2k
    }
1059
1060
17.3k
    if (dst->is_nullable()) {
1061
10.4k
        size_t num_read = *n;
1062
10.4k
        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.4k
        if (_null_iterator) {
1068
10.4k
            bool null_signs_has_null = false;
1069
10.4k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1070
10.4k
            RETURN_IF_ERROR(
1071
10.4k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1072
10.4k
        } else {
1073
0
            null_map_ptr->insert_many_vals(0, num_read);
1074
0
        }
1075
10.4k
        DCHECK(num_read == *n);
1076
10.4k
    }
1077
17.3k
    return Status::OK();
1078
17.3k
}
1079
1080
Status MapFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1081
15.8k
                                             MutableColumnPtr& dst) {
1082
15.8k
    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.8k
    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.8k
    if (count == 0) {
1109
0
        return Status::OK();
1110
0
    }
1111
    // resolve ColumnMap and nullable wrapper
1112
15.8k
    auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1113
15.8k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1114
15.8k
    auto offsets_ptr = IColumn::mutate(std::move(column_map.get_offsets_ptr()));
1115
15.8k
    Defer defer_offsets {[&] {
1116
15.8k
        auto typed_offsets_ptr = ColumnMap::COffsets::cast_to_column_mutptr(
1117
15.8k
                assert_cast<ColumnMap::COffsets*, TypeCheckOnRelease::DISABLE>(offsets_ptr.get()));
1118
15.8k
        offsets_ptr = nullptr;
1119
15.8k
        column_map.get_offsets_ptr() = std::move(typed_offsets_ptr);
1120
15.8k
    }};
1121
15.8k
    auto& offsets = static_cast<ColumnArray::ColumnOffsets&>(*offsets_ptr);
1122
15.8k
    size_t base = offsets.get_data().empty() ? 0 : offsets.get_data().back();
1123
1124
    // 1. bulk read null-map if nullable
1125
15.8k
    std::vector<uint8_t> null_mask; // 0: not null, 1: null
1126
15.8k
    if (_map_reader->is_nullable()) {
1127
        // For nullable map columns, the destination column must also be nullable.
1128
3.00k
        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.00k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1133
3.00k
        size_t null_before = null_map_ptr->size();
1134
3.00k
        auto* null_map_col = null_map_ptr.get();
1135
3.00k
        MutableColumnPtr null_map_column = std::move(null_map_ptr);
1136
3.00k
        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.00k
        null_mask.reserve(count);
1139
48.6k
        for (size_t i = 0; i < count; ++i) {
1140
45.6k
            null_mask.push_back(null_map_col->get_element(null_before + i));
1141
45.6k
        }
1142
12.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.8k
    MutableColumnPtr starts_col = ColumnOffset64::create();
1153
15.8k
    starts_col->reserve(count);
1154
15.8k
    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.8k
    std::vector<rowid_t> next_rowids(count);
1158
329k
    for (size_t i = 0; i < count; ++i) {
1159
314k
        uint64_t nr = rowids[i] + 1;
1160
314k
        next_rowids[i] = nr < _map_reader->num_rows() ? static_cast<rowid_t>(nr)
1161
314k
                                                      : static_cast<rowid_t>(0); // placeholder
1162
314k
    }
1163
15.8k
    MutableColumnPtr next_starts_col = ColumnOffset64::create();
1164
15.8k
    next_starts_col->reserve(count);
1165
    // read for all; we'll fix out-of-bound cases below
1166
15.8k
    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
329k
    for (size_t i = 0; i < count; ++i) {
1170
313k
        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
14.9k
            RETURN_IF_ERROR(_offsets_iterator->seek_to_ordinal(rowids[i]));
1174
14.9k
            size_t one = 1;
1175
14.9k
            bool has_null_unused = false;
1176
14.9k
            MutableColumnPtr tmp = ColumnOffset64::create();
1177
14.9k
            RETURN_IF_ERROR(_offsets_iterator->next_batch(&one, tmp, &has_null_unused));
1178
14.9k
            ordinal_t ns = 0;
1179
14.9k
            RETURN_IF_ERROR(_offsets_iterator->_peek_one_offset(&ns));
1180
            // overwrite with sentinel
1181
14.9k
            assert_cast<ColumnOffset64&, TypeCheckOnRelease::DISABLE>(*next_starts_col)
1182
14.9k
                    .get_data()[i] = ns;
1183
14.9k
        }
1184
313k
    }
1185
1186
    // 5. compute sizes and append offsets prefix-sum
1187
15.8k
    auto& starts_data = assert_cast<ColumnOffset64&>(*starts_col).get_data();
1188
15.8k
    auto& next_starts_data = assert_cast<ColumnOffset64&>(*next_starts_col).get_data();
1189
15.8k
    std::vector<size_t> sizes(count, 0);
1190
15.8k
    size_t acc = base;
1191
15.8k
    const auto original_size = offsets.get_data().back();
1192
15.8k
    offsets.get_data().reserve(offsets.get_data().size() + count);
1193
324k
    for (size_t i = 0; i < count; ++i) {
1194
308k
        size_t sz = static_cast<size_t>(next_starts_data[i] - starts_data[i]);
1195
308k
        if (_map_reader->is_nullable() && !null_mask.empty() && null_mask[i]) {
1196
679
            sz = 0; // null rows do not consume elements
1197
679
        }
1198
308k
        sizes[i] = sz;
1199
308k
        acc += sz;
1200
308k
        offsets.get_data().push_back(acc);
1201
308k
    }
1202
1203
    // 6. read key/value elements for non-empty sizes
1204
15.8k
    auto keys_ptr = IColumn::mutate(std::move(column_map.get_keys_ptr()));
1205
15.8k
    auto vals_ptr = IColumn::mutate(std::move(column_map.get_values_ptr()));
1206
15.8k
    Defer defer_keys {[&] { column_map.get_keys_ptr() = std::move(keys_ptr); }};
1207
15.8k
    Defer defer_values {[&] { column_map.get_values_ptr() = std::move(vals_ptr); }};
1208
1209
15.8k
    size_t this_run = sizes[0];
1210
15.8k
    auto start_idx = starts_data[0];
1211
15.8k
    auto last_idx = starts_data[0] + this_run;
1212
311k
    for (size_t i = 1; i < count; ++i) {
1213
295k
        size_t sz = sizes[i];
1214
295k
        if (sz == 0) {
1215
46.8k
            continue;
1216
46.8k
        }
1217
248k
        auto start = static_cast<ordinal_t>(starts_data[i]);
1218
248k
        if (start != last_idx) {
1219
1.13k
            size_t n = this_run;
1220
1.13k
            bool dummy_has_null = false;
1221
1222
1.13k
            if (this_run != 0) {
1223
1.13k
                if (_key_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1224
1.13k
                    RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(start_idx));
1225
1.13k
                    RETURN_IF_ERROR(_key_iterator->next_batch(&n, keys_ptr, &dummy_has_null));
1226
1.13k
                    DCHECK(n == this_run);
1227
1.13k
                }
1228
1229
1.13k
                if (_val_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1230
1.13k
                    n = this_run;
1231
1.13k
                    RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(start_idx));
1232
1.13k
                    RETURN_IF_ERROR(_val_iterator->next_batch(&n, vals_ptr, &dummy_has_null));
1233
1.13k
                    DCHECK(n == this_run);
1234
1.13k
                }
1235
1.13k
            }
1236
1.13k
            start_idx = start;
1237
1.13k
            this_run = sz;
1238
1.13k
            last_idx = start + sz;
1239
1.13k
            continue;
1240
1.13k
        }
1241
1242
247k
        this_run += sz;
1243
247k
        last_idx += sz;
1244
247k
    }
1245
1246
15.8k
    size_t n = this_run;
1247
15.8k
    const size_t total_count = offsets.get_data().back() - original_size;
1248
15.8k
    bool dummy_has_null = false;
1249
15.8k
    if (_key_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1250
15.8k
        if (this_run != 0) {
1251
5.92k
            RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(start_idx));
1252
5.92k
            RETURN_IF_ERROR(_key_iterator->next_batch(&n, keys_ptr, &dummy_has_null));
1253
5.92k
            DCHECK(n == this_run);
1254
5.92k
        }
1255
15.8k
    } else {
1256
10
        keys_ptr->insert_many_defaults(total_count);
1257
10
    }
1258
1259
15.8k
    if (_val_iterator->reading_flag() != ReadingFlag::SKIP_READING) {
1260
15.8k
        if (this_run != 0) {
1261
5.91k
            n = this_run;
1262
5.91k
            RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(start_idx));
1263
5.91k
            RETURN_IF_ERROR(_val_iterator->next_batch(&n, vals_ptr, &dummy_has_null));
1264
5.91k
            DCHECK(n == this_run);
1265
5.91k
        }
1266
15.8k
    } else {
1267
19
        vals_ptr->insert_many_defaults(total_count);
1268
19
    }
1269
1270
15.8k
    return Status::OK();
1271
15.8k
}
1272
1273
5.63k
void MapFileColumnIterator::set_need_to_read() {
1274
5.63k
    set_reading_flag(ReadingFlag::NEED_TO_READ);
1275
5.63k
    _key_iterator->set_need_to_read();
1276
5.63k
    _val_iterator->set_need_to_read();
1277
5.63k
}
1278
1279
6.84k
void MapFileColumnIterator::remove_pruned_sub_iterators() {
1280
6.84k
    _key_iterator->remove_pruned_sub_iterators();
1281
6.84k
    _val_iterator->remove_pruned_sub_iterators();
1282
6.84k
}
1283
1284
Status MapFileColumnIterator::set_access_paths(const TColumnAccessPaths& all_access_paths,
1285
6.61k
                                               const TColumnAccessPaths& predicate_access_paths) {
1286
6.61k
    if (all_access_paths.empty()) {
1287
1.51k
        return Status::OK();
1288
1.51k
    }
1289
1290
5.10k
    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.10k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1297
5.10k
    auto sub_predicate_access_paths = DORIS_TRY(_get_sub_access_paths(predicate_access_paths));
1298
1299
5.10k
    if (sub_all_access_paths.empty()) {
1300
3.89k
        return Status::OK();
1301
3.89k
    }
1302
1303
    // Check for meta-only modes (OFFSET_ONLY or NULL_MAP_ONLY)
1304
1.20k
    _check_and_set_meta_read_mode(sub_all_access_paths);
1305
1.20k
    if (read_offset_only()) {
1306
475
        _key_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1307
475
        _val_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1308
475
        DLOG(INFO) << "Map column iterator set column " << _column_name
1309
475
                   << " to OFFSET_ONLY reading mode, key/value columns set to SKIP_READING";
1310
475
        return Status::OK();
1311
475
    }
1312
729
    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
717
    TColumnAccessPaths key_all_access_paths;
1321
717
    TColumnAccessPaths val_all_access_paths;
1322
717
    TColumnAccessPaths key_predicate_access_paths;
1323
717
    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
717
    const auto need_read_keys = !key_all_access_paths.empty();
1349
717
    const auto need_read_values = !val_all_access_paths.empty();
1350
1351
717
    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
717
    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
229
        _key_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1377
229
        DLOG(INFO) << "Map column iterator set key column to SKIP_READING";
1378
229
    }
1379
1380
717
    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
239
        _val_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1386
239
        DLOG(INFO) << "Map column iterator set value column to SKIP_READING";
1387
239
    }
1388
717
    return Status::OK();
1389
717
}
1390
1391
////////////////////////////////////////////////////////////////////////////////
1392
1393
StructFileColumnIterator::StructFileColumnIterator(
1394
        std::shared_ptr<ColumnReader> reader, ColumnIteratorUPtr null_iterator,
1395
        std::vector<ColumnIteratorUPtr>&& sub_column_iterators)
1396
7.67k
        : _struct_reader(reader), _sub_column_iterators(std::move(sub_column_iterators)) {
1397
7.67k
    if (_struct_reader->is_nullable()) {
1398
6.83k
        _null_iterator = std::move(null_iterator);
1399
6.83k
    }
1400
7.67k
}
1401
1402
7.63k
Status StructFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1403
7.63k
    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
26.2k
    for (auto& column_iterator : _sub_column_iterators) {
1409
26.2k
        RETURN_IF_ERROR(column_iterator->init(opts));
1410
26.2k
    }
1411
7.63k
    if (_struct_reader->is_nullable()) {
1412
6.82k
        RETURN_IF_ERROR(_null_iterator->init(opts));
1413
6.82k
    }
1414
7.63k
    return Status::OK();
1415
7.63k
}
1416
1417
4.35k
Status StructFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1418
4.35k
    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.35k
    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.35k
    auto& column_struct = assert_cast<ColumnStruct&, TypeCheckOnRelease::DISABLE>(
1449
4.35k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1450
17.6k
    for (size_t i = 0; i < column_struct.tuple_size(); i++) {
1451
13.2k
        size_t num_read = *n;
1452
13.2k
        auto sub_column_ptr = IColumn::mutate(std::move(column_struct.get_column_ptr(i)));
1453
13.2k
        Defer defer_sub_column {
1454
13.2k
                [&] { column_struct.get_column_ptr(i) = std::move(sub_column_ptr); }};
1455
13.2k
        bool column_has_null = false;
1456
13.2k
        RETURN_IF_ERROR(
1457
13.2k
                _sub_column_iterators[i]->next_batch(&num_read, sub_column_ptr, &column_has_null));
1458
13.2k
        DCHECK(num_read == *n);
1459
13.2k
    }
1460
1461
4.35k
    if (dst->is_nullable()) {
1462
4.04k
        size_t num_read = *n;
1463
4.04k
        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.04k
        if (_null_iterator) {
1469
3.95k
            bool null_signs_has_null = false;
1470
3.95k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1471
3.95k
            RETURN_IF_ERROR(
1472
3.95k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1473
3.95k
        } else {
1474
88
            null_map_ptr->insert_many_vals(0, num_read);
1475
88
        }
1476
4.04k
        DCHECK(num_read == *n);
1477
4.04k
    }
1478
1479
4.35k
    return Status::OK();
1480
4.35k
}
1481
1482
4.35k
Status StructFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
1483
4.35k
    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.35k
    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
13.2k
    for (auto& column_iterator : _sub_column_iterators) {
1497
13.2k
        RETURN_IF_ERROR(column_iterator->seek_to_ordinal(ord));
1498
13.2k
    }
1499
4.35k
    if (_struct_reader->is_nullable()) {
1500
3.95k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1501
3.95k
    }
1502
4.35k
    return Status::OK();
1503
4.35k
}
1504
1505
410
Status StructFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1506
1.27k
    for (auto& column_iterator : _sub_column_iterators) {
1507
1.27k
        RETURN_IF_ERROR(column_iterator->init_prefetcher(params));
1508
1.27k
    }
1509
410
    if (_struct_reader->is_nullable()) {
1510
404
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
1511
404
    }
1512
410
    return Status::OK();
1513
410
}
1514
1515
void StructFileColumnIterator::collect_prefetchers(
1516
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1517
410
        PrefetcherInitMethod init_method) {
1518
1.27k
    for (auto& column_iterator : _sub_column_iterators) {
1519
1.27k
        column_iterator->collect_prefetchers(prefetchers, init_method);
1520
1.27k
    }
1521
410
    if (_struct_reader->is_nullable()) {
1522
404
        _null_iterator->collect_prefetchers(prefetchers, init_method);
1523
404
    }
1524
410
}
1525
1526
Status StructFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1527
2.49k
                                                MutableColumnPtr& dst) {
1528
2.49k
    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.49k
    if (count == 0) {
1535
0
        return Status::OK();
1536
0
    }
1537
1538
2.49k
    size_t this_run = 1;
1539
2.49k
    auto start_idx = rowids[0];
1540
2.49k
    auto last_idx = rowids[0];
1541
2.59k
    for (size_t i = 1; i < count; ++i) {
1542
93
        if (last_idx == rowids[i] - 1) {
1543
89
            last_idx = rowids[i];
1544
89
            this_run++;
1545
89
            continue;
1546
89
        }
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.49k
    RETURN_IF_ERROR(seek_to_ordinal(start_idx));
1558
2.49k
    size_t num_read = this_run;
1559
2.49k
    RETURN_IF_ERROR(next_batch(&num_read, dst));
1560
2.49k
    DCHECK_EQ(num_read, this_run);
1561
2.49k
    return Status::OK();
1562
2.49k
}
1563
1564
6.74k
void StructFileColumnIterator::set_need_to_read() {
1565
6.74k
    set_reading_flag(ReadingFlag::NEED_TO_READ);
1566
23.7k
    for (auto& sub_iterator : _sub_column_iterators) {
1567
23.7k
        sub_iterator->set_need_to_read();
1568
23.7k
    }
1569
6.74k
}
1570
1571
6.86k
void StructFileColumnIterator::remove_pruned_sub_iterators() {
1572
31.7k
    for (auto it = _sub_column_iterators.begin(); it != _sub_column_iterators.end();) {
1573
24.8k
        auto& sub_iterator = *it;
1574
24.8k
        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
23.9k
        } else {
1579
23.9k
            sub_iterator->remove_pruned_sub_iterators();
1580
23.9k
            ++it;
1581
23.9k
        }
1582
24.8k
    }
1583
6.86k
}
1584
1585
Status StructFileColumnIterator::set_access_paths(
1586
        const TColumnAccessPaths& all_access_paths,
1587
6.31k
        const TColumnAccessPaths& predicate_access_paths) {
1588
6.31k
    if (all_access_paths.empty()) {
1589
1.87k
        return Status::OK();
1590
1.87k
    }
1591
1592
4.44k
    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.44k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1598
4.44k
    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.44k
    _check_and_set_meta_read_mode(sub_all_access_paths);
1602
4.44k
    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.44k
    const auto no_sub_column_to_skip = sub_all_access_paths.empty();
1612
4.44k
    const auto no_predicate_sub_column = sub_predicate_access_paths.empty();
1613
1614
19.3k
    for (auto& sub_iterator : _sub_column_iterators) {
1615
19.3k
        const auto name = sub_iterator->column_name();
1616
19.3k
        bool need_to_read = no_sub_column_to_skip;
1617
19.3k
        TColumnAccessPaths sub_all_access_paths_of_this;
1618
19.3k
        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
19.3k
        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
18.5k
        set_reading_flag(ReadingFlag::NEED_TO_READ);
1634
18.5k
        sub_iterator->set_reading_flag(ReadingFlag::NEED_TO_READ);
1635
1636
18.5k
        TColumnAccessPaths sub_predicate_access_paths_of_this;
1637
1638
18.5k
        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
18.5k
        RETURN_IF_ERROR(sub_iterator->set_access_paths(sub_all_access_paths_of_this,
1647
18.5k
                                                       sub_predicate_access_paths_of_this));
1648
18.5k
    }
1649
4.44k
    return Status::OK();
1650
4.44k
}
1651
1652
////////////////////////////////////////////////////////////////////////////////
1653
97.2k
Status OffsetFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1654
97.2k
    RETURN_IF_ERROR(_offset_iterator->init(opts));
1655
    // allocate peek tmp column once
1656
97.2k
    _peek_tmp_col = ColumnOffset64::create();
1657
97.2k
    return Status::OK();
1658
97.2k
}
1659
1660
166k
Status OffsetFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1661
166k
    RETURN_IF_ERROR(_offset_iterator->next_batch(n, dst, has_null));
1662
166k
    return Status::OK();
1663
166k
}
1664
1665
316k
Status OffsetFileColumnIterator::_peek_one_offset(ordinal_t* offset) {
1666
316k
    if (_offset_iterator->get_current_page()->has_remaining()) {
1667
231k
        PageDecoder* offset_page_decoder = _offset_iterator->get_current_page()->data_decoder.get();
1668
231k
        size_t n = 1;
1669
231k
        _peek_tmp_col->clear();
1670
231k
        RETURN_IF_ERROR(offset_page_decoder->peek_next_batch(&n, _peek_tmp_col)); // not null
1671
231k
        DCHECK(_peek_tmp_col->size() == 1);
1672
231k
        *offset =
1673
231k
                assert_cast<const ColumnOffset64*, TypeCheckOnRelease::DISABLE>(_peek_tmp_col.get())
1674
231k
                        ->get_element(0);
1675
231k
    } else {
1676
84.9k
        *offset = _offset_iterator->get_current_page()->next_array_item_ordinal;
1677
84.9k
    }
1678
316k
    return Status::OK();
1679
316k
}
1680
1681
7.07k
Status OffsetFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1682
7.07k
    return _offset_iterator->init_prefetcher(params);
1683
7.07k
}
1684
1685
void OffsetFileColumnIterator::collect_prefetchers(
1686
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1687
7.07k
        PrefetcherInitMethod init_method) {
1688
7.07k
    _offset_iterator->collect_prefetchers(prefetchers, init_method);
1689
7.07k
}
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
151k
                                                    ColumnArray::ColumnOffsets& column_offsets) {
1705
151k
    ordinal_t next_storage_offset = 0;
1706
151k
    RETURN_IF_ERROR(_peek_one_offset(&next_storage_offset));
1707
1708
    // calculate real offsets
1709
151k
    auto& offsets_data = column_offsets.get_data();
1710
151k
    ordinal_t first_column_offset = offsets_data[start - 1]; // -1 is valid
1711
151k
    ordinal_t first_storage_offset = offsets_data[start];
1712
151k
    DCHECK(next_storage_offset >= first_storage_offset);
1713
3.85M
    for (ssize_t i = start; i < offsets_data.size() - 1; ++i) {
1714
3.70M
        offsets_data[i] = first_column_offset + (offsets_data[i + 1] - first_storage_offset);
1715
3.70M
    }
1716
    // last offset
1717
151k
    offsets_data[offsets_data.size() - 1] =
1718
151k
            first_column_offset + (next_storage_offset - first_storage_offset);
1719
151k
    return Status::OK();
1720
151k
}
1721
1722
////////////////////////////////////////////////////////////////////////////////
1723
ArrayFileColumnIterator::ArrayFileColumnIterator(std::shared_ptr<ColumnReader> reader,
1724
                                                 OffsetFileColumnIteratorUPtr offset_reader,
1725
                                                 ColumnIteratorUPtr item_iterator,
1726
                                                 ColumnIteratorUPtr null_iterator)
1727
61.7k
        : _array_reader(reader),
1728
61.7k
          _offset_iterator(std::move(offset_reader)),
1729
61.7k
          _item_iterator(std::move(item_iterator)) {
1730
61.7k
    if (_array_reader->is_nullable()) {
1731
43.8k
        _null_iterator = std::move(null_iterator);
1732
43.8k
    }
1733
61.7k
}
1734
1735
61.6k
Status ArrayFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1736
61.6k
    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
61.5k
    RETURN_IF_ERROR(_offset_iterator->init(opts));
1742
61.5k
    RETURN_IF_ERROR(_item_iterator->init(opts));
1743
61.5k
    if (_array_reader->is_nullable()) {
1744
43.7k
        RETURN_IF_ERROR(_null_iterator->init(opts));
1745
43.7k
    }
1746
61.5k
    return Status::OK();
1747
61.5k
}
1748
1749
134k
Status ArrayFileColumnIterator::_seek_by_offsets(ordinal_t ord) {
1750
134k
    if (read_offset_only()) {
1751
        // In OFFSET_ONLY mode, item iterator is SKIP_READING, no need to seek it
1752
1.19k
        return Status::OK();
1753
1.19k
    }
1754
    // using offsets info
1755
133k
    ordinal_t offset = 0;
1756
133k
    RETURN_IF_ERROR(_offset_iterator->_peek_one_offset(&offset));
1757
133k
    RETURN_IF_ERROR(_item_iterator->seek_to_ordinal(offset));
1758
133k
    return Status::OK();
1759
133k
}
1760
1761
134k
Status ArrayFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
1762
134k
    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
134k
    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
134k
    RETURN_IF_ERROR(_offset_iterator->seek_to_ordinal(ord));
1776
134k
    if (_array_reader->is_nullable()) {
1777
110k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1778
110k
    }
1779
134k
    return _seek_by_offsets(ord);
1780
134k
}
1781
1782
134k
Status ArrayFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1783
134k
    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
134k
    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
134k
    auto& column_array = assert_cast<ColumnArray&, TypeCheckOnRelease::DISABLE>(
1814
134k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1815
1816
134k
    bool offsets_has_null = false;
1817
134k
    auto column_offsets_ptr = std::move(*column_array.get_offsets_ptr()).mutate();
1818
134k
    Defer defer_offsets {[&] {
1819
134k
        auto typed_column_offsets_ptr = ColumnArray::ColumnOffsets::cast_to_column_mutptr(
1820
134k
                assert_cast<ColumnArray::ColumnOffsets*, TypeCheckOnRelease::DISABLE>(
1821
134k
                        column_offsets_ptr.get()));
1822
134k
        column_offsets_ptr = nullptr;
1823
134k
        column_array.get_offsets_ptr() = std::move(typed_column_offsets_ptr);
1824
134k
    }};
1825
134k
    ssize_t start = column_offsets_ptr->size();
1826
134k
    RETURN_IF_ERROR(_offset_iterator->next_batch(n, column_offsets_ptr, &offsets_has_null));
1827
134k
    if (*n == 0) {
1828
0
        return Status::OK();
1829
0
    }
1830
134k
    auto& column_offsets = static_cast<ColumnArray::ColumnOffsets&>(*column_offsets_ptr);
1831
134k
    RETURN_IF_ERROR(_offset_iterator->_calculate_offsets(start, column_offsets));
1832
134k
    size_t num_items =
1833
134k
            column_offsets.get_data().back() - column_offsets.get_data()[start - 1]; // -1 is valid
1834
134k
    if (num_items > 0) {
1835
97.2k
        auto column_items_ptr = IColumn::mutate(std::move(column_array.get_data_ptr()));
1836
97.2k
        Defer defer_items {[&] { column_array.get_data_ptr() = std::move(column_items_ptr); }};
1837
97.2k
        if (read_offset_only()) {
1838
            // OFFSET_ONLY mode: skip reading actual item data, fill with defaults
1839
1.02k
            column_items_ptr->insert_many_defaults(num_items);
1840
96.2k
        } else {
1841
96.2k
            size_t num_read = num_items;
1842
96.2k
            bool items_has_null = false;
1843
96.2k
            RETURN_IF_ERROR(
1844
96.2k
                    _item_iterator->next_batch(&num_read, column_items_ptr, &items_has_null));
1845
96.2k
            DCHECK(num_read == num_items);
1846
96.2k
        }
1847
97.2k
    }
1848
1849
134k
    if (dst->is_nullable()) {
1850
110k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1851
110k
        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
110k
        if (_null_iterator) {
1857
110k
            bool null_signs_has_null = false;
1858
110k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1859
110k
            RETURN_IF_ERROR(
1860
110k
                    _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
110k
        DCHECK(num_read == *n);
1865
110k
    }
1866
1867
134k
    return Status::OK();
1868
134k
}
1869
1870
5.73k
Status ArrayFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1871
5.73k
    RETURN_IF_ERROR(_offset_iterator->init_prefetcher(params));
1872
5.73k
    RETURN_IF_ERROR(_item_iterator->init_prefetcher(params));
1873
5.73k
    if (_array_reader->is_nullable()) {
1874
4.23k
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
1875
4.23k
    }
1876
5.73k
    return Status::OK();
1877
5.73k
}
1878
1879
void ArrayFileColumnIterator::collect_prefetchers(
1880
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1881
5.73k
        PrefetcherInitMethod init_method) {
1882
5.73k
    _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
5.73k
    _item_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
1886
5.73k
    if (_array_reader->is_nullable()) {
1887
4.22k
        _null_iterator->collect_prefetchers(prefetchers, init_method);
1888
4.22k
    }
1889
5.73k
}
1890
1891
Status ArrayFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1892
31.0k
                                               MutableColumnPtr& dst) {
1893
31.0k
    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
139k
    for (size_t i = 0; i < count; ++i) {
1900
        // TODO(cambyszju): now read array one by one, need optimize later
1901
108k
        RETURN_IF_ERROR(seek_to_ordinal(rowids[i]));
1902
108k
        size_t num_read = 1;
1903
108k
        RETURN_IF_ERROR(next_batch(&num_read, dst));
1904
108k
    }
1905
31.0k
    return Status::OK();
1906
31.0k
}
1907
1908
47.8k
void ArrayFileColumnIterator::set_need_to_read() {
1909
47.8k
    set_reading_flag(ReadingFlag::NEED_TO_READ);
1910
47.8k
    _item_iterator->set_need_to_read();
1911
47.8k
}
1912
1913
49.8k
void ArrayFileColumnIterator::remove_pruned_sub_iterators() {
1914
49.8k
    _item_iterator->remove_pruned_sub_iterators();
1915
49.8k
}
1916
1917
Status ArrayFileColumnIterator::set_access_paths(const TColumnAccessPaths& all_access_paths,
1918
49.0k
                                                 const TColumnAccessPaths& predicate_access_paths) {
1919
49.0k
    if (all_access_paths.empty()) {
1920
1.76k
        return Status::OK();
1921
1.76k
    }
1922
1923
47.2k
    if (!predicate_access_paths.empty()) {
1924
2.94k
        set_reading_flag(ReadingFlag::READING_FOR_PREDICATE);
1925
2.94k
        DLOG(INFO) << "Array column iterator set sub-column " << _column_name
1926
2.94k
                   << " to READING_FOR_PREDICATE";
1927
2.94k
    }
1928
1929
47.2k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1930
47.2k
    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
47.2k
    _check_and_set_meta_read_mode(sub_all_access_paths);
1934
47.2k
    if (read_offset_only()) {
1935
1.18k
        _item_iterator->set_reading_flag(ReadingFlag::SKIP_READING);
1936
1.18k
        DLOG(INFO) << "Array column iterator set column " << _column_name
1937
1.18k
                   << " to OFFSET_ONLY reading mode, item column set to SKIP_READING";
1938
1.18k
        return Status::OK();
1939
1.18k
    }
1940
46.1k
    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
46.1k
    const auto no_sub_column_to_skip = sub_all_access_paths.empty();
1948
46.1k
    const auto no_predicate_sub_column = sub_predicate_access_paths.empty();
1949
1950
46.1k
    if (!no_sub_column_to_skip) {
1951
3.65k
        for (auto& path : sub_all_access_paths) {
1952
3.65k
            if (path.data_access_path.path[0] == ACCESS_ALL) {
1953
3.65k
                path.data_access_path.path[0] = _item_iterator->column_name();
1954
3.65k
            }
1955
3.65k
        }
1956
3.64k
    }
1957
1958
46.1k
    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
46.1k
    if (!no_sub_column_to_skip || !no_predicate_sub_column) {
1967
3.66k
        _item_iterator->set_reading_flag(ReadingFlag::NEED_TO_READ);
1968
3.66k
        RETURN_IF_ERROR(
1969
3.66k
                _item_iterator->set_access_paths(sub_all_access_paths, sub_predicate_access_paths));
1970
3.66k
    }
1971
46.1k
    return Status::OK();
1972
46.1k
}
1973
1974
////////////////////////////////////////////////////////////////////////////////
1975
// StringFileColumnIterator implementation
1976
////////////////////////////////////////////////////////////////////////////////
1977
1978
StringFileColumnIterator::StringFileColumnIterator(std::shared_ptr<ColumnReader> reader)
1979
13.5M
        : FileColumnIterator(std::move(reader)) {}
1980
1981
13.5M
Status StringFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1982
13.5M
    if (read_offset_only()) {
1983
        // Propagate only_read_offsets to the FileColumnIterator's options
1984
108
        auto modified_opts = opts;
1985
108
        modified_opts.only_read_offsets = true;
1986
108
        return FileColumnIterator::init(modified_opts);
1987
108
    }
1988
13.5M
    return FileColumnIterator::init(opts);
1989
13.5M
}
1990
1991
Status StringFileColumnIterator::set_access_paths(
1992
        const TColumnAccessPaths& all_access_paths,
1993
4.47k
        const TColumnAccessPaths& predicate_access_paths) {
1994
4.47k
    if (all_access_paths.empty()) {
1995
3.47k
        return Status::OK();
1996
3.47k
    }
1997
1998
996
    if (!predicate_access_paths.empty()) {
1999
187
        set_reading_flag(ReadingFlag::READING_FOR_PREDICATE);
2000
187
    }
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
996
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
2005
996
    _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
996
    if (read_offset_only() && get_reader() != nullptr &&
2020
996
        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
996
    if (read_offset_only()) {
2029
108
        DLOG(INFO) << "String column iterator set column " << _column_name
2030
108
                   << " to OFFSET_ONLY reading mode";
2031
888
    } else if (read_null_map_only()) {
2032
208
        DLOG(INFO) << "String column iterator set column " << _column_name
2033
208
                   << " to NULL_MAP_ONLY reading mode";
2034
208
    }
2035
2036
996
    return Status::OK();
2037
996
}
2038
2039
////////////////////////////////////////////////////////////////////////////////
2040
2041
22.6M
FileColumnIterator::FileColumnIterator(std::shared_ptr<ColumnReader> reader) : _reader(reader) {}
2042
2043
54.0k
void ColumnIterator::_check_and_set_meta_read_mode(const TColumnAccessPaths& sub_all_access_paths) {
2044
54.0k
    for (const auto& path : sub_all_access_paths) {
2045
6.63k
        if (!path.data_access_path.path.empty()) {
2046
6.63k
            if (StringCaseEqual()(path.data_access_path.path[0], ACCESS_OFFSET)) {
2047
1.76k
                _read_mode = ReadMode::OFFSET_ONLY;
2048
1.76k
                return;
2049
4.87k
            } else if (StringCaseEqual()(path.data_access_path.path[0], ACCESS_NULL)) {
2050
236
                _read_mode = ReadMode::NULL_MAP_ONLY;
2051
236
                return;
2052
236
            }
2053
6.63k
        }
2054
6.62k
    }
2055
52.0k
    _read_mode = ReadMode::DEFAULT;
2056
52.0k
}
2057
2058
22.4M
Status FileColumnIterator::init(const ColumnIteratorOptions& opts) {
2059
22.4M
    if (_reading_flag == ReadingFlag::SKIP_READING) {
2060
2.38k
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2061
2.38k
        return Status::OK();
2062
2.38k
    }
2063
2064
22.4M
    _opts = opts;
2065
22.6M
    if (!_opts.use_page_cache) {
2066
22.6M
        _reader->disable_index_meta_cache();
2067
22.6M
    }
2068
22.4M
    RETURN_IF_ERROR(get_block_compression_codec(_reader->get_compression(), &_compress_codec));
2069
22.4M
    if (config::enable_low_cardinality_optimize &&
2070
22.5M
        opts.io_ctx.reader_type == ReaderType::READER_QUERY &&
2071
22.4M
        _reader->encoding_info()->encoding() == DICT_ENCODING) {
2072
13.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
13.3M
        if (dict_encoding_type == ColumnReader::UNKNOWN_DICT_ENCODING && opts.is_predicate_column) {
2080
15.1k
            RETURN_IF_ERROR(seek_to_ordinal(_reader->num_rows() - 1));
2081
15.1k
            _is_all_dict_encoding = _page.is_dict_encoding;
2082
15.1k
            _reader->set_dict_encoding_type(_is_all_dict_encoding
2083
15.1k
                                                    ? ColumnReader::ALL_DICT_ENCODING
2084
15.1k
                                                    : ColumnReader::PARTIAL_DICT_ENCODING);
2085
13.3M
        } else {
2086
13.3M
            _is_all_dict_encoding = dict_encoding_type == ColumnReader::ALL_DICT_ENCODING;
2087
13.3M
        }
2088
13.3M
    }
2089
22.4M
    return Status::OK();
2090
22.4M
}
2091
2092
22.6M
FileColumnIterator::~FileColumnIterator() = default;
2093
2094
442k
void FileColumnIterator::_trigger_prefetch_if_eligible(ordinal_t ord) {
2095
442k
    std::vector<BlockRange> ranges;
2096
442k
    if (_prefetcher->need_prefetch(cast_set<uint32_t>(ord), &ranges)) {
2097
297k
        for (const auto& range : ranges) {
2098
297k
            _cached_remote_file_reader->prefetch_range(range.offset, range.size, &_opts.io_ctx);
2099
297k
        }
2100
297k
    }
2101
442k
}
2102
2103
3.17M
Status FileColumnIterator::seek_to_ordinal(ordinal_t ord) {
2104
3.17M
    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.17M
    if (_enable_prefetch) {
2113
442k
        _trigger_prefetch_if_eligible(ord);
2114
442k
    }
2115
2116
    // if current page contains this row, we don't need to seek
2117
3.17M
    if (!_page || !_page.contains(ord) || !_page_iter.valid()) {
2118
1.44M
        RETURN_IF_ERROR(_reader->seek_at_or_before(ord, &_page_iter, _opts));
2119
1.44M
        RETURN_IF_ERROR(_read_data_page(_page_iter));
2120
1.44M
    }
2121
3.17M
    RETURN_IF_ERROR(_seek_to_pos_in_page(&_page, ord - _page.first_ordinal));
2122
3.17M
    _current_ordinal = ord;
2123
3.17M
    return Status::OK();
2124
3.17M
}
2125
2126
0
Status FileColumnIterator::seek_to_page_start() {
2127
0
    return seek_to_ordinal(_page.first_ordinal);
2128
0
}
2129
2130
3.23M
Status FileColumnIterator::_seek_to_pos_in_page(ParsedPage* page, ordinal_t offset_in_page) const {
2131
3.23M
    if (page->offset_in_page == offset_in_page) {
2132
        // fast path, do nothing
2133
1.78M
        return Status::OK();
2134
1.78M
    }
2135
2136
1.44M
    ordinal_t pos_in_data = offset_in_page;
2137
1.44M
    if (_page.has_null) {
2138
100k
        ordinal_t offset_in_data = 0;
2139
100k
        ordinal_t skips = offset_in_page;
2140
2141
100k
        if (offset_in_page > page->offset_in_page) {
2142
            // forward, reuse null bitmap
2143
59.8k
            skips = offset_in_page - page->offset_in_page;
2144
59.8k
            offset_in_data = page->data_decoder->current_index();
2145
59.8k
        } else {
2146
            // rewind null bitmap, and
2147
40.5k
            page->null_decoder = RleDecoder<bool>((const uint8_t*)page->null_bitmap.data,
2148
40.5k
                                                  cast_set<int>(page->null_bitmap.size), 1);
2149
40.5k
        }
2150
2151
100k
        auto skip_nulls = page->null_decoder.Skip(skips);
2152
100k
        pos_in_data = offset_in_data + skips - skip_nulls;
2153
100k
    }
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
9.14k
Status FileColumnIterator::next_batch_of_zone_map(size_t* n, MutableColumnPtr& dst) {
2161
9.14k
    return _reader->next_batch_of_zone_map(n, dst);
2162
9.14k
}
2163
2164
2.40M
Status FileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2165
2.40M
    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
48
                bool eos = false;
2177
48
                RETURN_IF_ERROR(_load_next_page(&eos));
2178
48
                if (eos) {
2179
0
                    break;
2180
0
                }
2181
48
            }
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
197k
                while (nrows_to_read > 0) {
2187
194k
                    bool is_null = false;
2188
194k
                    size_t this_run = _page.null_decoder.GetNextRun(&is_null, nrows_to_read);
2189
194k
                    const size_t cur_size = null_map_data.size();
2190
194k
                    null_map_data.resize(cur_size + this_run);
2191
194k
                    memset(null_map_data.data() + cur_size, is_null ? 1 : 0, this_run);
2192
194k
                    if (is_null) {
2193
102k
                        *has_null = true;
2194
102k
                    }
2195
194k
                    nrows_to_read -= this_run;
2196
194k
                    _page.offset_in_page += this_run;
2197
194k
                    _current_ordinal += this_run;
2198
194k
                }
2199
2.93k
            } else {
2200
73
                const size_t cur_size = null_map_data.size();
2201
73
                null_map_data.resize(cur_size + nrows_to_read);
2202
73
                memset(null_map_data.data() + cur_size, 0, nrows_to_read);
2203
73
                _page.offset_in_page += nrows_to_read;
2204
73
                _current_ordinal += nrows_to_read;
2205
73
            }
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.40M
    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.40M
    size_t curr_size = dst->byte_size();
2220
2.40M
    dst->reserve(*n);
2221
2.40M
    size_t remaining = *n;
2222
2.40M
    *has_null = false;
2223
4.86M
    while (remaining > 0) {
2224
2.45M
        if (!_page.has_remaining()) {
2225
52.0k
            bool eos = false;
2226
52.0k
            RETURN_IF_ERROR(_load_next_page(&eos));
2227
52.0k
            if (eos) {
2228
0
                break;
2229
0
            }
2230
52.0k
        }
2231
2232
        // number of rows to be read from this page
2233
2.45M
        size_t nrows_in_page = std::min(remaining, _page.remaining());
2234
2.45M
        size_t nrows_to_read = nrows_in_page;
2235
2.45M
        if (_page.has_null) {
2236
1.24M
            while (nrows_to_read > 0) {
2237
1.03M
                bool is_null = false;
2238
1.03M
                size_t this_run = _page.null_decoder.GetNextRun(&is_null, nrows_to_read);
2239
                // we use num_rows only for CHECK
2240
1.03M
                size_t num_rows = this_run;
2241
1.03M
                if (!is_null) {
2242
543k
                    RETURN_IF_ERROR(_page.data_decoder->next_batch(&num_rows, dst));
2243
543k
                    DCHECK_EQ(this_run, num_rows);
2244
543k
                } else {
2245
491k
                    *has_null = true;
2246
491k
                    auto* null_col = check_and_get_column<ColumnNullable>(dst.get());
2247
494k
                    if (null_col != nullptr) {
2248
494k
                        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
491k
                }
2253
2254
1.03M
                nrows_to_read -= this_run;
2255
1.03M
                _page.offset_in_page += this_run;
2256
1.03M
                _current_ordinal += this_run;
2257
1.03M
            }
2258
2.24M
        } else {
2259
2.24M
            RETURN_IF_ERROR(_page.data_decoder->next_batch(&nrows_to_read, dst));
2260
2.24M
            DCHECK_EQ(nrows_to_read, nrows_in_page);
2261
2262
2.24M
            _page.offset_in_page += nrows_to_read;
2263
2.24M
            _current_ordinal += nrows_to_read;
2264
2.24M
        }
2265
2.45M
        remaining -= nrows_in_page;
2266
2.45M
    }
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.40M
}
2275
2276
Status FileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
2277
705k
                                          MutableColumnPtr& dst) {
2278
705k
    if (read_null_map_only()) {
2279
16
        DLOG(INFO) << "File column iterator column " << _column_name
2280
16
                   << " in NULL_MAP_ONLY mode, reading only null map by rowids.";
2281
2282
16
        DORIS_CHECK(dst->is_nullable());
2283
16
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
2284
16
        auto& null_map_data = nullable_col.get_null_map_data();
2285
16
        const size_t base_size = null_map_data.size();
2286
16
        null_map_data.resize(base_size + count);
2287
2288
16
        size_t remaining = count;
2289
16
        size_t total_read_count = 0;
2290
16
        size_t nrows_to_read = 0;
2291
32
        while (remaining > 0) {
2292
16
            RETURN_IF_ERROR(seek_to_ordinal(rowids[total_read_count]));
2293
2294
16
            nrows_to_read = std::min(remaining, _page.remaining());
2295
2296
16
            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
14
            } else {
2330
14
                memset(null_map_data.data() + base_size + total_read_count, 0, nrows_to_read);
2331
14
                total_read_count += nrows_to_read;
2332
14
                remaining -= nrows_to_read;
2333
14
            }
2334
16
        }
2335
2336
16
        null_map_data.resize(base_size + total_read_count);
2337
16
        nullable_col.get_nested_column().insert_many_defaults(total_read_count);
2338
16
        return Status::OK();
2339
16
    }
2340
2341
705k
    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
705k
    size_t remaining = count;
2348
705k
    size_t total_read_count = 0;
2349
705k
    size_t nrows_to_read = 0;
2350
1.44M
    while (remaining > 0) {
2351
735k
        RETURN_IF_ERROR(seek_to_ordinal(rowids[total_read_count]));
2352
2353
        // number of rows to be read from this page
2354
735k
        nrows_to_read = std::min(remaining, _page.remaining());
2355
2356
735k
        if (_page.has_null) {
2357
54.1k
            size_t already_read = 0;
2358
2.96M
            while ((nrows_to_read - already_read) > 0) {
2359
2.91M
                bool is_null = false;
2360
2.91M
                size_t this_run = std::min(nrows_to_read - already_read, _page.remaining());
2361
2.91M
                if (UNLIKELY(this_run == 0)) {
2362
191
                    break;
2363
191
                }
2364
2.91M
                this_run = _page.null_decoder.GetNextRun(&is_null, this_run);
2365
2.91M
                size_t offset = total_read_count + already_read;
2366
2.91M
                size_t this_read_count = 0;
2367
2.91M
                rowid_t current_ordinal_in_page =
2368
2.91M
                        cast_set<uint32_t>(_page.offset_in_page + _page.first_ordinal);
2369
5.87M
                for (size_t i = 0; i < this_run; ++i) {
2370
5.79M
                    if (rowids[offset + i] - current_ordinal_in_page >= this_run) {
2371
2.83M
                        break;
2372
2.83M
                    }
2373
2.96M
                    this_read_count++;
2374
2.96M
                }
2375
2376
2.91M
                auto origin_index = _page.data_decoder->current_index();
2377
2.91M
                if (this_read_count > 0) {
2378
82.5k
                    if (is_null) {
2379
57.8k
                        auto* null_col = check_and_get_column<ColumnNullable>(dst.get());
2380
57.8k
                        if (UNLIKELY(null_col == nullptr)) {
2381
0
                            return Status::InternalError("unexpected column type in column reader");
2382
0
                        }
2383
2384
57.8k
                        null_col->insert_many_defaults(this_read_count);
2385
57.8k
                    } else {
2386
24.6k
                        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.6k
                        size_t page_start_off_in_decoder =
2391
24.6k
                                _page.first_ordinal + _page.offset_in_page - origin_index;
2392
24.6k
                        RETURN_IF_ERROR(_page.data_decoder->read_by_rowids(
2393
24.6k
                                &rowids[offset], page_start_off_in_decoder, &read_count, dst));
2394
24.6k
                        DCHECK_EQ(read_count, this_read_count);
2395
24.6k
                    }
2396
82.5k
                }
2397
2398
2.91M
                if (!is_null) {
2399
2.85M
                    RETURN_IF_ERROR(
2400
2.85M
                            _page.data_decoder->seek_to_position_in_page(origin_index + this_run));
2401
2.85M
                }
2402
2403
2.91M
                already_read += this_read_count;
2404
2.91M
                _page.offset_in_page += this_run;
2405
2.91M
                DCHECK(_page.offset_in_page <= _page.num_rows);
2406
2.91M
            }
2407
2408
54.1k
            nrows_to_read = already_read;
2409
54.1k
            total_read_count += nrows_to_read;
2410
54.1k
            remaining -= nrows_to_read;
2411
681k
        } else {
2412
681k
            RETURN_IF_ERROR(_page.data_decoder->read_by_rowids(
2413
681k
                    &rowids[total_read_count], _page.first_ordinal, &nrows_to_read, dst));
2414
681k
            total_read_count += nrows_to_read;
2415
681k
            remaining -= nrows_to_read;
2416
681k
        }
2417
735k
    }
2418
705k
    return Status::OK();
2419
705k
}
2420
2421
52.0k
Status FileColumnIterator::_load_next_page(bool* eos) {
2422
52.0k
    _page_iter.next();
2423
52.0k
    if (!_page_iter.valid()) {
2424
0
        *eos = true;
2425
0
        return Status::OK();
2426
0
    }
2427
2428
52.0k
    RETURN_IF_ERROR(_read_data_page(_page_iter));
2429
52.0k
    RETURN_IF_ERROR(_seek_to_pos_in_page(&_page, 0));
2430
52.0k
    *eos = false;
2431
52.0k
    return Status::OK();
2432
52.0k
}
2433
2434
1.49M
Status FileColumnIterator::_read_data_page(const OrdinalPageIndexIterator& iter) {
2435
1.49M
    PageHandle handle;
2436
1.49M
    Slice page_body;
2437
1.49M
    PageFooterPB footer;
2438
1.49M
    _opts.type = DATA_PAGE;
2439
1.49M
    PageDecoderOptions decoder_opts;
2440
1.49M
    decoder_opts.only_read_offsets = _opts.only_read_offsets;
2441
1.49M
    RETURN_IF_ERROR(
2442
1.49M
            _reader->read_page(_opts, iter.page(), &handle, &page_body, &footer, _compress_codec));
2443
    // parse data page
2444
1.49M
    auto st = ParsedPage::create(std::move(handle), page_body, footer.data_page_footer(),
2445
1.49M
                                 _reader->encoding_info(), iter.page(), iter.page_index(), &_page,
2446
1.49M
                                 decoder_opts);
2447
1.49M
    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.49M
    if (_reader->encoding_info()->encoding() == DICT_ENCODING) {
2460
392k
        auto dict_page_decoder = reinterpret_cast<BinaryDictPageDecoder*>(_page.data_decoder.get());
2461
392k
        if (dict_page_decoder->is_dict_encoding()) {
2462
376k
            if (_dict_decoder == nullptr) {
2463
370k
                RETURN_IF_ERROR(_read_dict_data());
2464
370k
                CHECK_NOTNULL(_dict_decoder);
2465
370k
            }
2466
2467
376k
            dict_page_decoder->set_dict_decoder(cast_set<uint32_t>(_dict_decoder->count()),
2468
376k
                                                _dict_word_info.get());
2469
376k
        }
2470
392k
    }
2471
1.49M
    return Status::OK();
2472
1.49M
}
2473
2474
370k
Status FileColumnIterator::_read_dict_data() {
2475
370k
    CHECK_EQ(_reader->encoding_info()->encoding(), DICT_ENCODING);
2476
    // read dictionary page
2477
370k
    Slice dict_data;
2478
370k
    PageFooterPB dict_footer;
2479
370k
    _opts.type = INDEX_PAGE;
2480
2481
370k
    RETURN_IF_ERROR(_reader->read_page(_opts, _reader->get_dict_page_pointer(), &_dict_page_handle,
2482
370k
                                       &dict_data, &dict_footer, _compress_codec));
2483
370k
    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
370k
    RETURN_IF_ERROR(EncodingInfo::get(_reader->get_meta_type(),
2488
370k
                                      dict_footer.dict_page_footer().encoding(), &encoding_info));
2489
370k
    RETURN_IF_ERROR(encoding_info->create_page_decoder(dict_data, {}, _dict_decoder));
2490
370k
    RETURN_IF_ERROR(_dict_decoder->init());
2491
2492
370k
    _dict_word_info.reset(new StringRef[_dict_decoder->count()]);
2493
370k
    RETURN_IF_ERROR(_dict_decoder->get_dict_word_info(_dict_word_info.get()));
2494
370k
    return Status::OK();
2495
370k
}
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
102k
        RowRanges* row_ranges) {
2501
102k
    if (_reader->has_zone_map()) {
2502
101k
        RETURN_IF_ERROR(_reader->get_row_ranges_by_zone_map(col_predicates, delete_predicates,
2503
101k
                                                            row_ranges, _opts));
2504
101k
    }
2505
102k
    return Status::OK();
2506
102k
}
2507
2508
Status FileColumnIterator::get_row_ranges_by_bloom_filter(
2509
102k
        const AndBlockColumnPredicate* col_predicates, RowRanges* row_ranges) {
2510
102k
    if ((col_predicates->can_do_bloom_filter(false) && _reader->has_bloom_filter_index(false)) ||
2511
102k
        (col_predicates->can_do_bloom_filter(true) && _reader->has_bloom_filter_index(true))) {
2512
112
        RETURN_IF_ERROR(_reader->get_row_ranges_by_bloom_filter(col_predicates, row_ranges, _opts));
2513
112
    }
2514
102k
    return Status::OK();
2515
102k
}
2516
2517
Status FileColumnIterator::get_row_ranges_by_dict(const AndBlockColumnPredicate* col_predicates,
2518
104k
                                                  RowRanges* row_ranges) {
2519
104k
    if (!_is_all_dict_encoding) {
2520
93.0k
        return Status::OK();
2521
93.0k
    }
2522
2523
11.3k
    if (!_dict_decoder) {
2524
0
        RETURN_IF_ERROR(_read_dict_data());
2525
0
        CHECK_NOTNULL(_dict_decoder);
2526
0
    }
2527
2528
11.3k
    if (!col_predicates->evaluate_and(_dict_word_info.get(), _dict_decoder->count())) {
2529
1.25k
        row_ranges->clear();
2530
1.25k
    }
2531
11.3k
    return Status::OK();
2532
11.3k
}
2533
2534
297k
Status FileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
2535
297k
    if (_cached_remote_file_reader =
2536
297k
                std::dynamic_pointer_cast<io::CachedRemoteFileReader>(_reader->_file_reader);
2537
297k
        !_cached_remote_file_reader) {
2538
0
        return Status::OK();
2539
0
    }
2540
297k
    _enable_prefetch = true;
2541
297k
    _prefetcher = std::make_unique<SegmentPrefetcher>(params.config);
2542
297k
    RETURN_IF_ERROR(_prefetcher->init(_reader, params.read_options));
2543
297k
    return Status::OK();
2544
297k
}
2545
2546
void FileColumnIterator::collect_prefetchers(
2547
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
2548
297k
        PrefetcherInitMethod init_method) {
2549
297k
    if (_prefetcher) {
2550
297k
        prefetchers[init_method].emplace_back(_prefetcher.get());
2551
297k
    }
2552
297k
}
2553
2554
26.3k
Status DefaultValueColumnIterator::init(const ColumnIteratorOptions& opts) {
2555
26.3k
    _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.3k
    if (_has_default_value) {
2560
1.57k
        if (_default_value == "NULL") {
2561
832
            _default_value_field = Field::create_field<TYPE_NULL>(Null {});
2562
832
        } else {
2563
739
            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
731
            } else if (_type == FieldType::OLAP_FIELD_TYPE_STRUCT) {
2571
0
                return Status::NotSupported("STRUCT default type is unsupported");
2572
731
            } else if (_type == FieldType::OLAP_FIELD_TYPE_MAP) {
2573
0
                return Status::NotSupported("MAP default type is unsupported");
2574
0
            }
2575
731
            const auto t = _type;
2576
731
            const auto serde = DataTypeFactory::instance()
2577
731
                                       .create_data_type(t, _precision, _scale, _len)
2578
731
                                       ->get_serde();
2579
731
            RETURN_IF_ERROR(serde->from_fe_string(_default_value, _default_value_field));
2580
731
        }
2581
24.7k
    } else if (_is_nullable) {
2582
24.7k
        _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.3k
    return Status::OK();
2588
26.3k
}
2589
2590
2.80k
Status DefaultValueColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2591
2.80k
    *has_null = _default_value_field.is_null();
2592
2.80k
    _insert_many_default(dst, *n);
2593
2.80k
    return Status::OK();
2594
2.80k
}
2595
2596
Status DefaultValueColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
2597
7.85k
                                                  MutableColumnPtr& dst) {
2598
7.85k
    _insert_many_default(dst, count);
2599
7.85k
    return Status::OK();
2600
7.85k
}
2601
2602
10.6k
void DefaultValueColumnIterator::_insert_many_default(MutableColumnPtr& dst, size_t n) {
2603
10.6k
    if (_default_value_field.is_null()) {
2604
10.2k
        dst->insert_many_defaults(n);
2605
10.2k
    } else {
2606
407
        dst = dst->convert_to_predicate_column_if_dictionary();
2607
407
        dst->insert_duplicate_fields(_default_value_field, n);
2608
407
    }
2609
10.6k
}
2610
2611
3.23k
Status RowIdColumnIteratorV2::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2612
3.23k
    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.23k
    _current_rowid += *n;
2621
3.23k
    return Status::OK();
2622
3.23k
}
2623
2624
Status RowIdColumnIteratorV2::read_by_rowids(const rowid_t* rowids, const size_t count,
2625
24.8k
                                             MutableColumnPtr& dst) {
2626
24.8k
    auto* string_column = assert_cast<ColumnString*>(dst.get());
2627
2628
22.2M
    for (size_t i = 0; i < count; ++i) {
2629
22.2M
        uint32_t row_id = rowids[i];
2630
22.2M
        GlobalRowLoacationV2 location(_version, _backend_id, _file_id, row_id);
2631
22.2M
        string_column->insert_data(reinterpret_cast<const char*>(&location),
2632
22.2M
                                   sizeof(GlobalRowLoacationV2));
2633
22.2M
    }
2634
24.8k
    return Status::OK();
2635
24.8k
}
2636
2637
} // namespace doris::segment_v2