Coverage Report

Created: 2026-04-15 16:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/parquet/vparquet_group_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 "format/parquet/vparquet_group_reader.h"
19
20
#include <gen_cpp/Exprs_types.h>
21
#include <gen_cpp/Opcodes_types.h>
22
#include <gen_cpp/Types_types.h>
23
#include <gen_cpp/parquet_types.h>
24
#include <string.h>
25
26
#include <algorithm>
27
#include <boost/iterator/iterator_facade.hpp>
28
#include <memory>
29
#include <ostream>
30
31
#include "common/config.h"
32
#include "common/consts.h"
33
#include "common/logging.h"
34
#include "common/object_pool.h"
35
#include "common/status.h"
36
#include "core/assert_cast.h"
37
#include "core/block/block.h"
38
#include "core/block/column_with_type_and_name.h"
39
#include "core/column/column_const.h"
40
#include "core/column/column_nullable.h"
41
#include "core/column/column_string.h"
42
#include "core/column/column_struct.h"
43
#include "core/column/column_vector.h"
44
#include "core/custom_allocator.h"
45
#include "core/data_type/data_type.h"
46
#include "core/data_type/data_type_number.h"
47
#include "core/data_type/data_type_string.h"
48
#include "core/data_type/data_type_struct.h"
49
#include "core/data_type/define_primitive_type.h"
50
#include "core/pod_array.h"
51
#include "core/types.h"
52
#include "exprs/create_predicate_function.h"
53
#include "exprs/hybrid_set.h"
54
#include "exprs/vdirect_in_predicate.h"
55
#include "exprs/vectorized_fn_call.h"
56
#include "exprs/vexpr.h"
57
#include "exprs/vexpr_context.h"
58
#include "exprs/vliteral.h"
59
#include "exprs/vslot_ref.h"
60
#include "format/parquet/schema_desc.h"
61
#include "format/parquet/vparquet_column_reader.h"
62
#include "format/table/iceberg_reader.h"
63
#include "runtime/descriptors.h"
64
#include "runtime/runtime_state.h"
65
#include "runtime/thread_context.h"
66
#include "storage/segment/column_reader.h"
67
68
namespace cctz {
69
class time_zone;
70
} // namespace cctz
71
namespace doris {
72
class RuntimeState;
73
74
namespace io {
75
struct IOContext;
76
} // namespace io
77
} // namespace doris
78
79
namespace doris {
80
81
namespace {
82
Status build_iceberg_rowid_column(const DataTypePtr& type, const std::string& file_path,
83
                                  const std::vector<rowid_t>& row_ids, int32_t partition_spec_id,
84
                                  const std::string& partition_data_json,
85
0
                                  MutableColumnPtr* column_out) {
86
0
    if (type == nullptr || column_out == nullptr) {
87
0
        return Status::InvalidArgument("Invalid iceberg rowid column type or output column");
88
0
    }
89
90
0
    MutableColumnPtr column = type->create_column();
91
0
    ColumnNullable* nullable_col = check_and_get_column<ColumnNullable>(column.get());
92
0
    ColumnStruct* struct_col = nullptr;
93
0
    if (nullable_col != nullptr) {
94
0
        struct_col =
95
0
                check_and_get_column<ColumnStruct>(nullable_col->get_nested_column_ptr().get());
96
0
    } else {
97
0
        struct_col = check_and_get_column<ColumnStruct>(column.get());
98
0
    }
99
100
0
    if (struct_col == nullptr || struct_col->tuple_size() < 4) {
101
0
        return Status::InternalError("Invalid iceberg rowid column structure");
102
0
    }
103
104
0
    size_t num_rows = row_ids.size();
105
0
    auto& file_path_col = struct_col->get_column(0);
106
0
    auto& row_pos_col = struct_col->get_column(1);
107
0
    auto& spec_id_col = struct_col->get_column(2);
108
0
    auto& partition_data_col = struct_col->get_column(3);
109
110
0
    file_path_col.reserve(num_rows);
111
0
    row_pos_col.reserve(num_rows);
112
0
    spec_id_col.reserve(num_rows);
113
0
    partition_data_col.reserve(num_rows);
114
115
0
    for (size_t i = 0; i < num_rows; ++i) {
116
0
        file_path_col.insert_data(file_path.data(), file_path.size());
117
0
    }
118
0
    for (size_t i = 0; i < num_rows; ++i) {
119
0
        int64_t row_pos = static_cast<int64_t>(row_ids[i]);
120
0
        row_pos_col.insert_data(reinterpret_cast<const char*>(&row_pos), sizeof(row_pos));
121
0
    }
122
0
    for (size_t i = 0; i < num_rows; ++i) {
123
0
        int32_t spec_id = partition_spec_id;
124
0
        spec_id_col.insert_data(reinterpret_cast<const char*>(&spec_id), sizeof(spec_id));
125
0
    }
126
0
    for (size_t i = 0; i < num_rows; ++i) {
127
0
        partition_data_col.insert_data(partition_data_json.data(), partition_data_json.size());
128
0
    }
129
130
0
    if (nullable_col != nullptr) {
131
0
        nullable_col->get_null_map_data().resize_fill(num_rows, 0);
132
0
    }
133
134
0
    *column_out = std::move(column);
135
0
    return Status::OK();
136
0
}
137
} // namespace
138
const std::vector<int64_t> RowGroupReader::NO_DELETE = {};
139
static constexpr uint32_t MAX_DICT_CODE_PREDICATE_TO_REWRITE = std::numeric_limits<uint32_t>::max();
140
141
RowGroupReader::RowGroupReader(io::FileReaderSPtr file_reader,
142
                               const std::vector<std::string>& read_columns,
143
                               const int32_t row_group_id, const tparquet::RowGroup& row_group,
144
                               const cctz::time_zone* ctz, io::IOContext* io_ctx,
145
                               const PositionDeleteContext& position_delete_ctx,
146
                               const LazyReadContext& lazy_read_ctx, RuntimeState* state,
147
                               const std::set<uint64_t>& column_ids,
148
                               const std::set<uint64_t>& filter_column_ids)
149
38
        : _file_reader(file_reader),
150
38
          _read_table_columns(read_columns),
151
38
          _row_group_id(row_group_id),
152
38
          _row_group_meta(row_group),
153
38
          _remaining_rows(row_group.num_rows),
154
38
          _ctz(ctz),
155
38
          _io_ctx(io_ctx),
156
38
          _position_delete_ctx(position_delete_ctx),
157
38
          _lazy_read_ctx(lazy_read_ctx),
158
38
          _state(state),
159
38
          _obj_pool(new ObjectPool()),
160
38
          _column_ids(column_ids),
161
38
          _filter_column_ids(filter_column_ids) {}
162
163
38
RowGroupReader::~RowGroupReader() {
164
38
    _column_readers.clear();
165
38
    _obj_pool->clear();
166
38
}
167
168
Status RowGroupReader::init(
169
        const FieldDescriptor& schema, RowRanges& row_ranges,
170
        std::unordered_map<int, tparquet::OffsetIndex>& col_offsets,
171
        const TupleDescriptor* tuple_descriptor, const RowDescriptor* row_descriptor,
172
        const std::unordered_map<std::string, int>* colname_to_slot_id,
173
        const VExprContextSPtrs* not_single_slot_filter_conjuncts,
174
38
        const std::unordered_map<int, VExprContextSPtrs>* slot_id_to_filter_conjuncts) {
175
38
    _tuple_descriptor = tuple_descriptor;
176
38
    _row_descriptor = row_descriptor;
177
38
    _col_name_to_slot_id = colname_to_slot_id;
178
38
    _slot_id_to_filter_conjuncts = slot_id_to_filter_conjuncts;
179
38
    _read_ranges = row_ranges;
180
38
    _filter_read_ranges_by_condition_cache();
181
38
    _remaining_rows = _read_ranges.count();
182
183
38
    if (_read_table_columns.empty()) {
184
        // Query task that only select columns in path.
185
1
        return Status::OK();
186
1
    }
187
37
    const size_t MAX_GROUP_BUF_SIZE = config::parquet_rowgroup_max_buffer_mb << 20;
188
37
    const size_t MAX_COLUMN_BUF_SIZE = config::parquet_column_max_buffer_mb << 20;
189
37
    size_t max_buf_size =
190
37
            std::min(MAX_COLUMN_BUF_SIZE, MAX_GROUP_BUF_SIZE / _read_table_columns.size());
191
108
    for (const auto& read_table_col : _read_table_columns) {
192
108
        auto read_file_col = _table_info_node_ptr->children_file_column_name(read_table_col);
193
108
        auto* field = schema.get_column(read_file_col);
194
108
        std::unique_ptr<ParquetColumnReader> reader;
195
108
        RETURN_IF_ERROR(ParquetColumnReader::create(
196
108
                _file_reader, field, _row_group_meta, _read_ranges, _ctz, _io_ctx, reader,
197
108
                max_buf_size, col_offsets, _state, false, _column_ids, _filter_column_ids));
198
108
        if (reader == nullptr) {
199
0
            VLOG_DEBUG << "Init row group(" << _row_group_id << ") reader failed";
200
0
            return Status::Corruption("Init row group reader failed");
201
0
        }
202
108
        _column_readers[read_table_col] = std::move(reader);
203
108
    }
204
205
37
    bool disable_dict_filter = false;
206
37
    if (not_single_slot_filter_conjuncts != nullptr && !not_single_slot_filter_conjuncts->empty()) {
207
0
        disable_dict_filter = true;
208
0
        _filter_conjuncts.insert(_filter_conjuncts.end(), not_single_slot_filter_conjuncts->begin(),
209
0
                                 not_single_slot_filter_conjuncts->end());
210
0
    }
211
212
    // Check if single slot can be filtered by dict.
213
37
    if (_slot_id_to_filter_conjuncts && !_slot_id_to_filter_conjuncts->empty()) {
214
6
        const std::vector<std::string>& predicate_col_names =
215
6
                _lazy_read_ctx.predicate_columns.first;
216
6
        const std::vector<int>& predicate_col_slot_ids = _lazy_read_ctx.predicate_columns.second;
217
14
        for (size_t i = 0; i < predicate_col_names.size(); ++i) {
218
8
            const std::string& predicate_col_name = predicate_col_names[i];
219
8
            int slot_id = predicate_col_slot_ids[i];
220
8
            if (predicate_col_name == IcebergTableReader::ROW_LINEAGE_ROW_ID ||
221
8
                predicate_col_name == IcebergTableReader::ROW_LINEAGE_LAST_UPDATED_SEQ_NUMBER) {
222
                // row lineage column can not dict filter.
223
0
                if (_slot_id_to_filter_conjuncts->find(slot_id) !=
224
0
                    _slot_id_to_filter_conjuncts->end()) {
225
0
                    for (auto& ctx : _slot_id_to_filter_conjuncts->at(slot_id)) {
226
0
                        _filter_conjuncts.push_back(ctx);
227
0
                    }
228
0
                }
229
0
                continue;
230
0
            }
231
232
8
            auto predicate_file_col_name =
233
8
                    _table_info_node_ptr->children_file_column_name(predicate_col_name);
234
8
            auto field = schema.get_column(predicate_file_col_name);
235
8
            if (!disable_dict_filter && !_lazy_read_ctx.has_complex_type &&
236
8
                _can_filter_by_dict(
237
8
                        slot_id, _row_group_meta.columns[field->physical_column_index].meta_data)) {
238
2
                _dict_filter_cols.emplace_back(std::make_pair(predicate_col_name, slot_id));
239
6
            } else {
240
6
                if (_slot_id_to_filter_conjuncts->find(slot_id) !=
241
6
                    _slot_id_to_filter_conjuncts->end()) {
242
6
                    for (auto& ctx : _slot_id_to_filter_conjuncts->at(slot_id)) {
243
6
                        _filter_conjuncts.push_back(ctx);
244
6
                    }
245
6
                }
246
6
            }
247
8
        }
248
        // Add predicate_partition_columns in _slot_id_to_filter_conjuncts(single slot conjuncts)
249
        // to _filter_conjuncts, others should be added from not_single_slot_filter_conjuncts.
250
6
        for (auto& kv : _lazy_read_ctx.predicate_partition_columns) {
251
4
            auto& [value, slot_desc] = kv.second;
252
4
            auto iter = _slot_id_to_filter_conjuncts->find(slot_desc->id());
253
4
            if (iter != _slot_id_to_filter_conjuncts->end()) {
254
4
                for (auto& ctx : iter->second) {
255
4
                    _filter_conjuncts.push_back(ctx);
256
4
                }
257
4
            }
258
4
        }
259
        //For check missing column :   missing column == xx, missing column is null,missing column is not null.
260
6
        _filter_conjuncts.insert(_filter_conjuncts.end(),
261
6
                                 _lazy_read_ctx.missing_columns_conjuncts.begin(),
262
6
                                 _lazy_read_ctx.missing_columns_conjuncts.end());
263
6
        RETURN_IF_ERROR(_rewrite_dict_predicates());
264
6
    }
265
    // _state is nullptr in some ut.
266
37
    if (_state && _state->enable_adjust_conjunct_order_by_cost()) {
267
8
        std::ranges::sort(_filter_conjuncts, [](const auto& a, const auto& b) {
268
8
            return a->execute_cost() < b->execute_cost();
269
8
        });
270
8
    }
271
37
    return Status::OK();
272
37
}
273
274
bool RowGroupReader::_can_filter_by_dict(int slot_id,
275
8
                                         const tparquet::ColumnMetaData& column_metadata) {
276
8
    SlotDescriptor* slot = nullptr;
277
8
    const std::vector<SlotDescriptor*>& slots = _tuple_descriptor->slots();
278
14
    for (auto each : slots) {
279
14
        if (each->id() == slot_id) {
280
8
            slot = each;
281
8
            break;
282
8
        }
283
14
    }
284
8
    if (!is_string_type(slot->type()->get_primitive_type()) &&
285
8
        !is_var_len_object(slot->type()->get_primitive_type())) {
286
6
        return false;
287
6
    }
288
2
    if (column_metadata.type != tparquet::Type::BYTE_ARRAY) {
289
0
        return false;
290
0
    }
291
292
2
    if (!is_dictionary_encoded(column_metadata)) {
293
0
        return false;
294
0
    }
295
296
2
    if (_slot_id_to_filter_conjuncts->find(slot_id) == _slot_id_to_filter_conjuncts->end()) {
297
0
        return false;
298
0
    }
299
300
    // TODO: The current implementation of dictionary filtering does not take into account
301
    //  the implementation of NULL values because the dictionary itself does not contain
302
    //  NULL value encoding. As a result, many NULL-related functions or expressions
303
    //  cannot work properly, such as is null, is not null, coalesce, etc.
304
    //  Here we check if the predicate expr is IN or BINARY_PRED.
305
    //  Implementation of NULL value dictionary filtering will be carried out later.
306
2
    return std::ranges::all_of(_slot_id_to_filter_conjuncts->at(slot_id), [&](const auto& ctx) {
307
2
        return (ctx->root()->node_type() == TExprNodeType::IN_PRED ||
308
2
                ctx->root()->node_type() == TExprNodeType::BINARY_PRED) &&
309
2
               ctx->root()->children()[0]->node_type() == TExprNodeType::SLOT_REF;
310
2
    });
311
2
}
312
313
// This function is copied from
314
// https://github.com/apache/impala/blob/master/be/src/exec/parquet/hdfs-parquet-scanner.cc#L1717
315
2
bool RowGroupReader::is_dictionary_encoded(const tparquet::ColumnMetaData& column_metadata) {
316
    // The Parquet spec allows for column chunks to have mixed encodings
317
    // where some data pages are dictionary-encoded and others are plain
318
    // encoded. For example, a Parquet file writer might start writing
319
    // a column chunk as dictionary encoded, but it will switch to plain
320
    // encoding if the dictionary grows too large.
321
    //
322
    // In order for dictionary filters to skip the entire row group,
323
    // the conjuncts must be evaluated on column chunks that are entirely
324
    // encoded with the dictionary encoding. There are two checks
325
    // available to verify this:
326
    // 1. The encoding_stats field on the column chunk metadata provides
327
    //    information about the number of data pages written in each
328
    //    format. This allows for a specific check of whether all the
329
    //    data pages are dictionary encoded.
330
    // 2. The encodings field on the column chunk metadata lists the
331
    //    encodings used. If this list contains the dictionary encoding
332
    //    and does not include unexpected encodings (i.e. encodings not
333
    //    associated with definition/repetition levels), then it is entirely
334
    //    dictionary encoded.
335
2
    if (column_metadata.__isset.encoding_stats) {
336
        // Condition #1 above
337
4
        for (const tparquet::PageEncodingStats& enc_stat : column_metadata.encoding_stats) {
338
4
            if (enc_stat.page_type == tparquet::PageType::DATA_PAGE &&
339
4
                (enc_stat.encoding != tparquet::Encoding::PLAIN_DICTIONARY &&
340
2
                 enc_stat.encoding != tparquet::Encoding::RLE_DICTIONARY) &&
341
4
                enc_stat.count > 0) {
342
0
                return false;
343
0
            }
344
4
        }
345
2
    } else {
346
        // Condition #2 above
347
0
        bool has_dict_encoding = false;
348
0
        bool has_nondict_encoding = false;
349
0
        for (const tparquet::Encoding::type& encoding : column_metadata.encodings) {
350
0
            if (encoding == tparquet::Encoding::PLAIN_DICTIONARY ||
351
0
                encoding == tparquet::Encoding::RLE_DICTIONARY) {
352
0
                has_dict_encoding = true;
353
0
            }
354
355
            // RLE and BIT_PACKED are used for repetition/definition levels
356
0
            if (encoding != tparquet::Encoding::PLAIN_DICTIONARY &&
357
0
                encoding != tparquet::Encoding::RLE_DICTIONARY &&
358
0
                encoding != tparquet::Encoding::RLE && encoding != tparquet::Encoding::BIT_PACKED) {
359
0
                has_nondict_encoding = true;
360
0
                break;
361
0
            }
362
0
        }
363
        // Not entirely dictionary encoded if:
364
        // 1. No dictionary encoding listed
365
        // OR
366
        // 2. Some non-dictionary encoding is listed
367
0
        if (!has_dict_encoding || has_nondict_encoding) {
368
0
            return false;
369
0
        }
370
0
    }
371
372
2
    return true;
373
2
}
374
375
Status RowGroupReader::next_batch(Block* block, size_t batch_size, size_t* read_rows,
376
50
                                  bool* batch_eof) {
377
50
    if (_is_row_group_filtered) {
378
2
        *read_rows = 0;
379
2
        *batch_eof = true;
380
2
        return Status::OK();
381
2
    }
382
383
    // Process external table query task that select columns are all from path.
384
48
    if (_read_table_columns.empty()) {
385
3
        bool modify_row_ids = false;
386
3
        RETURN_IF_ERROR(_read_empty_batch(batch_size, read_rows, batch_eof, &modify_row_ids));
387
388
3
        RETURN_IF_ERROR(
389
3
                _fill_partition_columns(block, *read_rows, _lazy_read_ctx.partition_columns));
390
3
        RETURN_IF_ERROR(_fill_missing_columns(block, *read_rows, _lazy_read_ctx.missing_columns));
391
392
3
        RETURN_IF_ERROR(_fill_row_id_columns(block, *read_rows, modify_row_ids));
393
3
        RETURN_IF_ERROR(_append_iceberg_rowid_column(block, *read_rows, modify_row_ids));
394
395
3
        Status st = VExprContext::filter_block(_lazy_read_ctx.conjuncts, block, block->columns());
396
3
        *read_rows = block->rows();
397
3
        return st;
398
3
    }
399
45
    if (_lazy_read_ctx.can_lazy_read) {
400
        // call _do_lazy_read recursively when current batch is skipped
401
4
        return _do_lazy_read(block, batch_size, read_rows, batch_eof);
402
41
    } else {
403
41
        FilterMap filter_map;
404
41
        int64_t batch_base_row = _total_read_rows;
405
41
        RETURN_IF_ERROR((_read_column_data(block, _lazy_read_ctx.all_read_columns, batch_size,
406
41
                                           read_rows, batch_eof, filter_map)));
407
41
        RETURN_IF_ERROR(
408
41
                _fill_partition_columns(block, *read_rows, _lazy_read_ctx.partition_columns));
409
41
        RETURN_IF_ERROR(_fill_missing_columns(block, *read_rows, _lazy_read_ctx.missing_columns));
410
41
        RETURN_IF_ERROR(_fill_row_id_columns(block, *read_rows, false));
411
41
        RETURN_IF_ERROR(_append_iceberg_rowid_column(block, *read_rows, false));
412
413
41
#ifndef NDEBUG
414
127
        for (auto col : *block) {
415
127
            col.column->sanity_check();
416
127
            DCHECK(block->rows() == col.column->size())
417
0
                    << absl::Substitute("block rows = $0 , column rows = $1, col name = $2",
418
0
                                        block->rows(), col.column->size(), col.name);
419
127
        }
420
41
#endif
421
422
41
        if (block->rows() == 0) {
423
0
            RETURN_IF_ERROR(_convert_dict_cols_to_string_cols(block));
424
0
            *read_rows = block->rows();
425
0
#ifndef NDEBUG
426
0
            for (auto col : *block) {
427
0
                col.column->sanity_check();
428
0
                DCHECK(block->rows() == col.column->size())
429
0
                        << absl::Substitute("block rows = $0 , column rows = $1, col name = $2",
430
0
                                            block->rows(), col.column->size(), col.name);
431
0
            }
432
0
#endif
433
0
            return Status::OK();
434
0
        }
435
41
        {
436
41
            SCOPED_RAW_TIMER(&_predicate_filter_time);
437
41
            RETURN_IF_ERROR(_build_pos_delete_filter(*read_rows));
438
439
41
            std::vector<uint32_t> columns_to_filter;
440
41
            int column_to_keep = block->columns();
441
41
            columns_to_filter.resize(column_to_keep);
442
168
            for (uint32_t i = 0; i < column_to_keep; ++i) {
443
127
                columns_to_filter[i] = i;
444
127
            }
445
41
            if (!_lazy_read_ctx.conjuncts.empty()) {
446
6
                std::vector<IColumn::Filter*> filters;
447
6
                if (_position_delete_ctx.has_filter) {
448
0
                    filters.push_back(_pos_delete_filter_ptr.get());
449
0
                }
450
6
                IColumn::Filter result_filter(block->rows(), 1);
451
6
                bool can_filter_all = false;
452
453
6
                {
454
6
                    RETURN_IF_ERROR_OR_CATCH_EXCEPTION(VExprContext::execute_conjuncts(
455
6
                            _filter_conjuncts, &filters, block, &result_filter, &can_filter_all));
456
6
                }
457
458
                // Condition cache MISS: mark granules with surviving rows (non-lazy path)
459
6
                if (!can_filter_all) {
460
3
                    _mark_condition_cache_granules(result_filter.data(), block->rows(),
461
3
                                                   batch_base_row);
462
3
                }
463
464
6
                if (can_filter_all) {
465
9
                    for (auto& col : columns_to_filter) {
466
9
                        std::move(*block->get_by_position(col).column).assume_mutable()->clear();
467
9
                    }
468
3
                    Block::erase_useless_column(block, column_to_keep);
469
3
                    RETURN_IF_ERROR(_convert_dict_cols_to_string_cols(block));
470
3
                    return Status::OK();
471
3
                }
472
473
3
                RETURN_IF_CATCH_EXCEPTION(
474
3
                        Block::filter_block_internal(block, columns_to_filter, result_filter));
475
3
                Block::erase_useless_column(block, column_to_keep);
476
35
            } else {
477
35
                RETURN_IF_CATCH_EXCEPTION(
478
35
                        RETURN_IF_ERROR(_filter_block(block, column_to_keep, columns_to_filter)));
479
35
            }
480
38
            RETURN_IF_ERROR(_convert_dict_cols_to_string_cols(block));
481
38
        }
482
38
#ifndef NDEBUG
483
118
        for (auto col : *block) {
484
118
            col.column->sanity_check();
485
118
            DCHECK(block->rows() == col.column->size())
486
0
                    << absl::Substitute("block rows = $0 , column rows = $1, col name = $2",
487
0
                                        block->rows(), col.column->size(), col.name);
488
118
        }
489
38
#endif
490
38
        *read_rows = block->rows();
491
38
        return Status::OK();
492
38
    }
493
45
}
494
495
// Maps each batch row to its global parquet file position via _read_ranges, then marks
496
// the corresponding condition cache granule as true if the filter indicates the row survived.
497
// batch_seq_start is the number of rows already read sequentially before this batch
498
// (i.e., _total_read_rows before the batch started).
499
void RowGroupReader::_mark_condition_cache_granules(const uint8_t* filter_data, size_t num_rows,
500
6
                                                    int64_t batch_seq_start) {
501
6
    if (!_condition_cache_ctx || _condition_cache_ctx->is_hit) {
502
6
        return;
503
6
    }
504
0
    auto& cache = *_condition_cache_ctx->filter_result;
505
0
    for (size_t i = 0; i < num_rows; i++) {
506
0
        if (filter_data[i]) {
507
            // row-group-relative position of this row
508
0
            int64_t rg_pos = _read_ranges.get_row_index_by_pos(batch_seq_start + i);
509
            // global row number in the parquet file
510
0
            size_t granule = (_current_row_group_idx.first_row + rg_pos) /
511
0
                             ConditionCacheContext::GRANULE_SIZE;
512
0
            size_t cache_idx = granule - _condition_cache_ctx->base_granule;
513
0
            if (cache_idx < cache.size()) {
514
0
                cache[cache_idx] = true;
515
0
            }
516
0
        }
517
0
    }
518
0
}
519
520
// On condition cache HIT, removes row ranges whose granules have no surviving rows from
521
// _read_ranges BEFORE column readers are created. This makes ParquetColumnReader skip I/O
522
// entirely for false-granule rows — both predicate and lazy columns — via its existing
523
// page/row-skipping infrastructure.
524
38
void RowGroupReader::_filter_read_ranges_by_condition_cache() {
525
38
    if (!_condition_cache_ctx || !_condition_cache_ctx->is_hit) {
526
38
        return;
527
38
    }
528
0
    auto& filter_result = *_condition_cache_ctx->filter_result;
529
0
    if (filter_result.empty()) {
530
0
        return;
531
0
    }
532
533
0
    auto old_row_count = _read_ranges.count();
534
0
    _read_ranges =
535
0
            filter_ranges_by_cache(_read_ranges, filter_result, _current_row_group_idx.first_row,
536
0
                                   _condition_cache_ctx->base_granule);
537
0
    _is_row_group_filtered = _read_ranges.is_empty();
538
0
    _condition_cache_filtered_rows += old_row_count - _read_ranges.count();
539
0
}
540
541
// Filters read_ranges by removing rows whose cache granule is false.
542
//
543
// Cache index i maps to global granule (base_granule + i), which covers global file
544
// rows [(base_granule+i)*GS, (base_granule+i+1)*GS). Since read_ranges uses
545
// row-group-relative indices and first_row is the global position of the row group's
546
// first row, global granule g maps to row-group-relative range:
547
//   [max(0, g*GS - first_row), max(0, (g+1)*GS - first_row))
548
//
549
// We build a RowRanges of all false-granule regions (in row-group-relative coordinates),
550
// then subtract from read_ranges via ranges_exception.
551
//
552
// Granules beyond cache.size() are kept conservatively (assumed true).
553
//
554
// When base_granule > 0, the cache only covers granules starting from base_granule.
555
// This happens when a Parquet file is split across multiple scan ranges and this reader
556
// only processes row groups starting at a non-zero offset in the file.
557
RowRanges RowGroupReader::filter_ranges_by_cache(const RowRanges& read_ranges,
558
                                                 const std::vector<bool>& cache, int64_t first_row,
559
21
                                                 int64_t base_granule) {
560
21
    constexpr int64_t GS = ConditionCacheContext::GRANULE_SIZE;
561
21
    RowRanges filtered_ranges;
562
563
138
    for (size_t i = 0; i < cache.size(); i++) {
564
117
        if (!cache[i]) {
565
64
            int64_t global_granule = base_granule + static_cast<int64_t>(i);
566
64
            int64_t rg_from = std::max(static_cast<int64_t>(0), global_granule * GS - first_row);
567
64
            int64_t rg_to =
568
64
                    std::max(static_cast<int64_t>(0), (global_granule + 1) * GS - first_row);
569
64
            if (rg_from < rg_to) {
570
16
                filtered_ranges.add(RowRange(rg_from, rg_to));
571
16
            }
572
64
        }
573
117
    }
574
575
21
    RowRanges result;
576
21
    RowRanges::ranges_exception(read_ranges, filtered_ranges, &result);
577
21
    return result;
578
21
}
579
580
Status RowGroupReader::_read_column_data(Block* block,
581
                                         const std::vector<std::string>& table_columns,
582
                                         size_t batch_size, size_t* read_rows, bool* batch_eof,
583
50
                                         FilterMap& filter_map) {
584
50
    size_t batch_read_rows = 0;
585
50
    bool has_eof = false;
586
125
    for (auto& read_col_name : table_columns) {
587
125
        auto& column_with_type_and_name =
588
125
                block->safe_get_by_position((*_col_name_to_block_idx)[read_col_name]);
589
125
        auto& column_ptr = column_with_type_and_name.column;
590
125
        auto& column_type = column_with_type_and_name.type;
591
125
        bool is_dict_filter = false;
592
125
        for (auto& _dict_filter_col : _dict_filter_cols) {
593
0
            if (_dict_filter_col.first == read_col_name) {
594
0
                MutableColumnPtr dict_column = ColumnInt32::create();
595
0
                if (!_col_name_to_block_idx->contains(read_col_name)) {
596
0
                    return Status::InternalError(
597
0
                            "Wrong read column '{}' in parquet file, block: {}", read_col_name,
598
0
                            block->dump_structure());
599
0
                }
600
0
                if (column_type->is_nullable()) {
601
0
                    block->get_by_position((*_col_name_to_block_idx)[read_col_name]).type =
602
0
                            std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt32>());
603
0
                    block->replace_by_position(
604
0
                            (*_col_name_to_block_idx)[read_col_name],
605
0
                            ColumnNullable::create(std::move(dict_column),
606
0
                                                   ColumnUInt8::create(dict_column->size(), 0)));
607
0
                } else {
608
0
                    block->get_by_position((*_col_name_to_block_idx)[read_col_name]).type =
609
0
                            std::make_shared<DataTypeInt32>();
610
0
                    block->replace_by_position((*_col_name_to_block_idx)[read_col_name],
611
0
                                               std::move(dict_column));
612
0
                }
613
0
                is_dict_filter = true;
614
0
                break;
615
0
            }
616
0
        }
617
618
125
        size_t col_read_rows = 0;
619
125
        bool col_eof = false;
620
        // Should reset _filter_map_index to 0 when reading next column.
621
        //        select_vector.reset();
622
125
        _column_readers[read_col_name]->reset_filter_map_index();
623
313
        while (!col_eof && col_read_rows < batch_size) {
624
188
            size_t loop_rows = 0;
625
188
            RETURN_IF_ERROR(_column_readers[read_col_name]->read_column_data(
626
188
                    column_ptr, column_type, _table_info_node_ptr->get_children_node(read_col_name),
627
188
                    filter_map, batch_size - col_read_rows, &loop_rows, &col_eof, is_dict_filter));
628
188
            VLOG_DEBUG << "[RowGroupReader] column '" << read_col_name
629
0
                       << "' loop_rows=" << loop_rows << " col_read_rows_so_far=" << col_read_rows
630
0
                       << std::endl;
631
188
            col_read_rows += loop_rows;
632
188
        }
633
125
        VLOG_DEBUG << "[RowGroupReader] column '" << read_col_name
634
0
                   << "' read_rows=" << col_read_rows << std::endl;
635
125
        if (batch_read_rows > 0 && batch_read_rows != col_read_rows) {
636
0
            LOG(WARNING) << "[RowGroupReader] Mismatched read rows among parquet columns. "
637
0
                            "previous_batch_read_rows="
638
0
                         << batch_read_rows << ", current_column='" << read_col_name
639
0
                         << "', current_col_read_rows=" << col_read_rows;
640
0
            return Status::Corruption("Can't read the same number of rows among parquet columns");
641
0
        }
642
125
        batch_read_rows = col_read_rows;
643
644
125
#ifndef NDEBUG
645
125
        column_ptr->sanity_check();
646
125
#endif
647
125
        if (col_eof) {
648
103
            has_eof = true;
649
103
        }
650
125
    }
651
652
50
    *read_rows = batch_read_rows;
653
50
    *batch_eof = has_eof;
654
655
50
    return Status::OK();
656
50
}
657
658
Status RowGroupReader::_do_lazy_read(Block* block, size_t batch_size, size_t* read_rows,
659
4
                                     bool* batch_eof) {
660
4
    std::unique_ptr<FilterMap> filter_map_ptr = nullptr;
661
4
    size_t pre_read_rows;
662
4
    bool pre_eof;
663
4
    std::vector<uint32_t> columns_to_filter;
664
4
    uint32_t origin_column_num = block->columns();
665
4
    columns_to_filter.resize(origin_column_num);
666
16
    for (uint32_t i = 0; i < origin_column_num; ++i) {
667
12
        columns_to_filter[i] = i;
668
12
    }
669
4
    IColumn::Filter result_filter;
670
4
    size_t pre_raw_read_rows = 0;
671
6
    while (!_state->is_cancelled()) {
672
        // read predicate columns
673
6
        pre_read_rows = 0;
674
6
        pre_eof = false;
675
6
        FilterMap filter_map;
676
6
        int64_t batch_base_row = _total_read_rows;
677
6
        RETURN_IF_ERROR(_read_column_data(block, _lazy_read_ctx.predicate_columns.first, batch_size,
678
6
                                          &pre_read_rows, &pre_eof, filter_map));
679
6
        if (pre_read_rows == 0) {
680
0
            DCHECK_EQ(pre_eof, true);
681
0
            break;
682
0
        }
683
6
        pre_raw_read_rows += pre_read_rows;
684
685
6
        RETURN_IF_ERROR(_fill_partition_columns(block, pre_read_rows,
686
6
                                                _lazy_read_ctx.predicate_partition_columns));
687
6
        RETURN_IF_ERROR(_fill_missing_columns(block, pre_read_rows,
688
6
                                              _lazy_read_ctx.predicate_missing_columns));
689
6
        RETURN_IF_ERROR(_fill_row_id_columns(block, pre_read_rows, false));
690
6
        RETURN_IF_ERROR(_append_iceberg_rowid_column(block, pre_read_rows, false));
691
692
6
        RETURN_IF_ERROR(_build_pos_delete_filter(pre_read_rows));
693
694
6
#ifndef NDEBUG
695
18
        for (auto col : *block) {
696
18
            if (col.column->size() == 0) { // lazy read column.
697
6
                continue;
698
6
            }
699
12
            col.column->sanity_check();
700
12
            DCHECK(pre_read_rows == col.column->size())
701
0
                    << absl::Substitute("pre_read_rows = $0 , column rows = $1, col name = $2",
702
0
                                        pre_read_rows, col.column->size(), col.name);
703
12
        }
704
6
#endif
705
706
6
        bool can_filter_all = false;
707
6
        bool resize_first_column = _lazy_read_ctx.resize_first_column;
708
6
        if (resize_first_column && _iceberg_rowid_params.enabled) {
709
0
            int row_id_idx = block->get_position_by_name(doris::BeConsts::ICEBERG_ROWID_COL);
710
0
            if (row_id_idx == 0) {
711
0
                resize_first_column = false;
712
0
            }
713
0
        }
714
6
        {
715
6
            SCOPED_RAW_TIMER(&_predicate_filter_time);
716
717
            // generate filter vector
718
6
            if (resize_first_column) {
719
                // VExprContext.execute has an optimization, the filtering is executed when block->rows() > 0
720
                // The following process may be tricky and time-consuming, but we have no other way.
721
6
                block->get_by_position(0).column->assume_mutable()->resize(pre_read_rows);
722
6
            }
723
6
            result_filter.assign(pre_read_rows, static_cast<unsigned char>(1));
724
6
            std::vector<IColumn::Filter*> filters;
725
6
            if (_position_delete_ctx.has_filter) {
726
0
                filters.push_back(_pos_delete_filter_ptr.get());
727
0
            }
728
729
6
            VExprContextSPtrs filter_contexts;
730
12
            for (auto& conjunct : _filter_conjuncts) {
731
12
                filter_contexts.emplace_back(conjunct);
732
12
            }
733
734
6
            {
735
6
                RETURN_IF_ERROR(VExprContext::execute_conjuncts(filter_contexts, &filters, block,
736
6
                                                                &result_filter, &can_filter_all));
737
6
            }
738
739
            // Condition cache MISS: mark granules with surviving rows
740
6
            if (!can_filter_all) {
741
3
                _mark_condition_cache_granules(result_filter.data(), pre_read_rows, batch_base_row);
742
3
            }
743
744
6
            if (resize_first_column) {
745
                // We have to clean the first column to insert right data.
746
6
                block->get_by_position(0).column->assume_mutable()->clear();
747
6
            }
748
6
        }
749
750
0
        const uint8_t* __restrict filter_map_data = result_filter.data();
751
6
        filter_map_ptr = std::make_unique<FilterMap>();
752
6
        RETURN_IF_ERROR(filter_map_ptr->init(filter_map_data, pre_read_rows, can_filter_all));
753
6
        if (filter_map_ptr->filter_all()) {
754
3
            {
755
3
                SCOPED_RAW_TIMER(&_predicate_filter_time);
756
3
                for (const auto& col : _lazy_read_ctx.predicate_columns.first) {
757
                    // clean block to read predicate columns
758
3
                    block->get_by_position((*_col_name_to_block_idx)[col])
759
3
                            .column->assume_mutable()
760
3
                            ->clear();
761
3
                }
762
3
                for (const auto& col : _lazy_read_ctx.predicate_partition_columns) {
763
3
                    block->get_by_position((*_col_name_to_block_idx)[col.first])
764
3
                            .column->assume_mutable()
765
3
                            ->clear();
766
3
                }
767
3
                for (const auto& col : _lazy_read_ctx.predicate_missing_columns) {
768
0
                    block->get_by_position((*_col_name_to_block_idx)[col.first])
769
0
                            .column->assume_mutable()
770
0
                            ->clear();
771
0
                }
772
3
                if (_row_id_column_iterator_pair.first != nullptr) {
773
0
                    block->get_by_position(_row_id_column_iterator_pair.second)
774
0
                            .column->assume_mutable()
775
0
                            ->clear();
776
0
                }
777
3
                if (_iceberg_rowid_params.enabled) {
778
0
                    int row_id_idx =
779
0
                            block->get_position_by_name(doris::BeConsts::ICEBERG_ROWID_COL);
780
0
                    if (row_id_idx >= 0) {
781
0
                        block->get_by_position(static_cast<size_t>(row_id_idx))
782
0
                                .column->assume_mutable()
783
0
                                ->clear();
784
0
                    }
785
0
                }
786
3
                Block::erase_useless_column(block, origin_column_num);
787
3
            }
788
789
3
            if (!pre_eof) {
790
                // If continuous batches are skipped, we can cache them to skip a whole page
791
2
                _cached_filtered_rows += pre_read_rows;
792
2
                if (pre_raw_read_rows >= config::doris_scanner_row_num) {
793
0
                    *read_rows = 0;
794
0
                    RETURN_IF_ERROR(_convert_dict_cols_to_string_cols(block));
795
0
                    return Status::OK();
796
0
                }
797
2
            } else { // pre_eof
798
                // If filter_map_ptr->filter_all() and pre_eof, we can skip whole row group.
799
1
                *read_rows = 0;
800
1
                *batch_eof = true;
801
1
                _lazy_read_filtered_rows += (pre_read_rows + _cached_filtered_rows);
802
1
                RETURN_IF_ERROR(_convert_dict_cols_to_string_cols(block));
803
1
                return Status::OK();
804
1
            }
805
3
        } else {
806
3
            break;
807
3
        }
808
6
    }
809
3
    if (_state->is_cancelled()) {
810
0
        return Status::Cancelled("cancelled");
811
0
    }
812
813
3
    if (filter_map_ptr == nullptr) {
814
0
        DCHECK_EQ(pre_read_rows + _cached_filtered_rows, 0);
815
0
        *read_rows = 0;
816
0
        *batch_eof = true;
817
0
        return Status::OK();
818
0
    }
819
820
3
    FilterMap& filter_map = *filter_map_ptr;
821
3
    DorisUniqueBufferPtr<uint8_t> rebuild_filter_map = nullptr;
822
3
    if (_cached_filtered_rows != 0) {
823
0
        RETURN_IF_ERROR(_rebuild_filter_map(filter_map, rebuild_filter_map, pre_read_rows));
824
0
        pre_read_rows += _cached_filtered_rows;
825
0
        _cached_filtered_rows = 0;
826
0
    }
827
828
    // lazy read columns
829
3
    size_t lazy_read_rows;
830
3
    bool lazy_eof;
831
3
    RETURN_IF_ERROR(_read_column_data(block, _lazy_read_ctx.lazy_read_columns, pre_read_rows,
832
3
                                      &lazy_read_rows, &lazy_eof, filter_map));
833
834
3
    if (pre_read_rows != lazy_read_rows) {
835
0
        return Status::Corruption("Can't read the same number of rows when doing lazy read");
836
0
    }
837
    // pre_eof ^ lazy_eof
838
    // we set pre_read_rows as batch_size for lazy read columns, so pre_eof != lazy_eof
839
840
    // filter data in predicate columns, and remove filter column
841
3
    {
842
3
        SCOPED_RAW_TIMER(&_predicate_filter_time);
843
3
        if (filter_map.has_filter()) {
844
0
            std::vector<uint32_t> predicate_columns = _lazy_read_ctx.all_predicate_col_ids;
845
0
            if (_iceberg_rowid_params.enabled) {
846
0
                int row_id_idx = block->get_position_by_name(doris::BeConsts::ICEBERG_ROWID_COL);
847
0
                if (row_id_idx >= 0 &&
848
0
                    std::find(predicate_columns.begin(), predicate_columns.end(),
849
0
                              static_cast<uint32_t>(row_id_idx)) == predicate_columns.end()) {
850
0
                    predicate_columns.push_back(static_cast<uint32_t>(row_id_idx));
851
0
                }
852
0
            }
853
0
            RETURN_IF_CATCH_EXCEPTION(
854
0
                    Block::filter_block_internal(block, predicate_columns, result_filter));
855
0
            Block::erase_useless_column(block, origin_column_num);
856
857
3
        } else {
858
3
            Block::erase_useless_column(block, origin_column_num);
859
3
        }
860
3
    }
861
862
3
    RETURN_IF_ERROR(_convert_dict_cols_to_string_cols(block));
863
864
3
    size_t column_num = block->columns();
865
3
    size_t column_size = 0;
866
12
    for (int i = 0; i < column_num; ++i) {
867
9
        size_t cz = block->get_by_position(i).column->size();
868
9
        if (column_size != 0 && cz != 0) {
869
6
            DCHECK_EQ(column_size, cz);
870
6
        }
871
9
        if (cz != 0) {
872
9
            column_size = cz;
873
9
        }
874
9
    }
875
3
    _lazy_read_filtered_rows += pre_read_rows - column_size;
876
3
    *read_rows = column_size;
877
878
3
    *batch_eof = pre_eof;
879
3
    RETURN_IF_ERROR(_fill_partition_columns(block, column_size, _lazy_read_ctx.partition_columns));
880
3
    RETURN_IF_ERROR(_fill_missing_columns(block, column_size, _lazy_read_ctx.missing_columns));
881
3
#ifndef NDEBUG
882
9
    for (auto col : *block) {
883
9
        col.column->sanity_check();
884
9
        DCHECK(block->rows() == col.column->size())
885
0
                << absl::Substitute("block rows = $0 , column rows = $1, col name = $2",
886
0
                                    block->rows(), col.column->size(), col.name);
887
9
    }
888
3
#endif
889
3
    return Status::OK();
890
3
}
891
892
Status RowGroupReader::_rebuild_filter_map(FilterMap& filter_map,
893
                                           DorisUniqueBufferPtr<uint8_t>& filter_map_data,
894
0
                                           size_t pre_read_rows) const {
895
0
    if (_cached_filtered_rows == 0) {
896
0
        return Status::OK();
897
0
    }
898
0
    size_t total_rows = _cached_filtered_rows + pre_read_rows;
899
0
    if (filter_map.filter_all()) {
900
0
        RETURN_IF_ERROR(filter_map.init(nullptr, total_rows, true));
901
0
        return Status::OK();
902
0
    }
903
904
0
    filter_map_data = make_unique_buffer<uint8_t>(total_rows);
905
0
    auto* map = filter_map_data.get();
906
0
    for (size_t i = 0; i < _cached_filtered_rows; ++i) {
907
0
        map[i] = 0;
908
0
    }
909
0
    const uint8_t* old_map = filter_map.filter_map_data();
910
0
    if (old_map == nullptr) {
911
        // select_vector.filter_all() == true is already built.
912
0
        for (size_t i = _cached_filtered_rows; i < total_rows; ++i) {
913
0
            map[i] = 1;
914
0
        }
915
0
    } else {
916
0
        memcpy(map + _cached_filtered_rows, old_map, pre_read_rows);
917
0
    }
918
0
    RETURN_IF_ERROR(filter_map.init(map, total_rows, false));
919
0
    return Status::OK();
920
0
}
921
922
Status RowGroupReader::_fill_partition_columns(
923
        Block* block, size_t rows,
924
        const std::unordered_map<std::string, std::tuple<std::string, const SlotDescriptor*>>&
925
53
                partition_columns) {
926
53
    DataTypeSerDe::FormatOptions _text_formatOptions;
927
53
    for (const auto& kv : partition_columns) {
928
15
        auto doris_column = block->get_by_position((*_col_name_to_block_idx)[kv.first]).column;
929
        // obtained from block*, it is a mutable object.
930
15
        auto* col_ptr = const_cast<IColumn*>(doris_column.get());
931
15
        const auto& [value, slot_desc] = kv.second;
932
15
        auto _text_serde = slot_desc->get_data_type_ptr()->get_serde();
933
15
        Slice slice(value.data(), value.size());
934
15
        uint64_t num_deserialized = 0;
935
        // Be careful when reading empty rows from parquet row groups.
936
15
        if (_text_serde->deserialize_column_from_fixed_json(*col_ptr, slice, rows,
937
15
                                                            &num_deserialized,
938
15
                                                            _text_formatOptions) != Status::OK()) {
939
0
            return Status::InternalError("Failed to fill partition column: {}={}",
940
0
                                         slot_desc->col_name(), value);
941
0
        }
942
15
        if (num_deserialized != rows) {
943
0
            return Status::InternalError(
944
0
                    "Failed to fill partition column: {}={} ."
945
0
                    "Number of rows expected to be written : {}, number of rows actually written : "
946
0
                    "{}",
947
0
                    slot_desc->col_name(), value, num_deserialized, rows);
948
0
        }
949
15
    }
950
53
    return Status::OK();
951
53
}
952
953
Status RowGroupReader::_fill_missing_columns(
954
        Block* block, size_t rows,
955
53
        const std::unordered_map<std::string, VExprContextSPtr>& missing_columns) {
956
53
    for (const auto& kv : missing_columns) {
957
0
        if (!_col_name_to_block_idx->contains(kv.first)) {
958
0
            return Status::InternalError("Missing column: {} not found in block {}", kv.first,
959
0
                                         block->dump_structure());
960
0
        }
961
0
        if (kv.second == nullptr) {
962
            // no default column, fill with null
963
0
            auto mutable_column = block->get_by_position((*_col_name_to_block_idx)[kv.first])
964
0
                                          .column->assume_mutable();
965
0
            auto* nullable_column = assert_cast<ColumnNullable*>(mutable_column.get());
966
0
            nullable_column->insert_many_defaults(rows);
967
0
        } else {
968
            // fill with default value
969
0
            const auto& ctx = kv.second;
970
0
            ColumnPtr result_column_ptr;
971
            // PT1 => dest primitive type
972
0
            RETURN_IF_ERROR(ctx->execute(block, result_column_ptr));
973
0
            if (result_column_ptr->use_count() == 1) {
974
                // call resize because the first column of _src_block_ptr may not be filled by reader,
975
                // so _src_block_ptr->rows() may return wrong result, cause the column created by `ctx->execute()`
976
                // has only one row.
977
0
                auto mutable_column = result_column_ptr->assume_mutable();
978
0
                mutable_column->resize(rows);
979
                // result_column_ptr maybe a ColumnConst, convert it to a normal column
980
0
                result_column_ptr = result_column_ptr->convert_to_full_column_if_const();
981
0
                auto origin_column_type =
982
0
                        block->get_by_position((*_col_name_to_block_idx)[kv.first]).type;
983
0
                bool is_nullable = origin_column_type->is_nullable();
984
0
                block->replace_by_position(
985
0
                        (*_col_name_to_block_idx)[kv.first],
986
0
                        is_nullable ? make_nullable(result_column_ptr) : result_column_ptr);
987
0
            }
988
0
        }
989
0
    }
990
53
    return Status::OK();
991
53
}
992
993
Status RowGroupReader::_read_empty_batch(size_t batch_size, size_t* read_rows, bool* batch_eof,
994
3
                                         bool* modify_row_ids) {
995
3
    *modify_row_ids = false;
996
3
    if (_position_delete_ctx.has_filter) {
997
0
        int64_t start_row_id = _position_delete_ctx.current_row_id;
998
0
        int64_t end_row_id = std::min(_position_delete_ctx.current_row_id + (int64_t)batch_size,
999
0
                                      _position_delete_ctx.last_row_id);
1000
0
        int64_t num_delete_rows = 0;
1001
0
        auto before_index = _position_delete_ctx.index;
1002
0
        while (_position_delete_ctx.index < _position_delete_ctx.end_index) {
1003
0
            const int64_t& delete_row_id =
1004
0
                    _position_delete_ctx.delete_rows[_position_delete_ctx.index];
1005
0
            if (delete_row_id < start_row_id) {
1006
0
                _position_delete_ctx.index++;
1007
0
                before_index = _position_delete_ctx.index;
1008
0
            } else if (delete_row_id < end_row_id) {
1009
0
                num_delete_rows++;
1010
0
                _position_delete_ctx.index++;
1011
0
            } else { // delete_row_id >= end_row_id
1012
0
                break;
1013
0
            }
1014
0
        }
1015
0
        *read_rows = end_row_id - start_row_id - num_delete_rows;
1016
0
        _position_delete_ctx.current_row_id = end_row_id;
1017
0
        *batch_eof = _position_delete_ctx.current_row_id == _position_delete_ctx.last_row_id;
1018
1019
0
        if (_row_id_column_iterator_pair.first != nullptr || _iceberg_rowid_params.enabled ||
1020
0
            (_row_lineage_columns != nullptr && _row_lineage_columns->need_row_ids())) {
1021
0
            *modify_row_ids = true;
1022
0
            _current_batch_row_ids.clear();
1023
0
            _current_batch_row_ids.resize(*read_rows);
1024
0
            size_t idx = 0;
1025
0
            for (auto id = start_row_id; id < end_row_id; id++) {
1026
0
                if (before_index < _position_delete_ctx.index &&
1027
0
                    id == _position_delete_ctx.delete_rows[before_index]) {
1028
0
                    before_index++;
1029
0
                    continue;
1030
0
                }
1031
0
                _current_batch_row_ids[idx++] = (rowid_t)id;
1032
0
            }
1033
0
        }
1034
3
    } else {
1035
3
        if (batch_size < _remaining_rows) {
1036
2
            *read_rows = batch_size;
1037
2
            _remaining_rows -= batch_size;
1038
2
            *batch_eof = false;
1039
2
        } else {
1040
1
            *read_rows = _remaining_rows;
1041
1
            _remaining_rows = 0;
1042
1
            *batch_eof = true;
1043
1
        }
1044
3
        if (_iceberg_rowid_params.enabled) {
1045
0
            *modify_row_ids = true;
1046
0
            RETURN_IF_ERROR(_get_current_batch_row_id(*read_rows));
1047
0
        }
1048
3
    }
1049
3
    _total_read_rows += *read_rows;
1050
3
    return Status::OK();
1051
3
}
1052
1053
5
Status RowGroupReader::_get_current_batch_row_id(size_t read_rows) {
1054
5
    _current_batch_row_ids.clear();
1055
5
    _current_batch_row_ids.resize(read_rows);
1056
1057
5
    int64_t idx = 0;
1058
5
    int64_t read_range_rows = 0;
1059
19
    for (size_t range_idx = 0; range_idx < _read_ranges.range_size(); range_idx++) {
1060
14
        auto range = _read_ranges.get_range(range_idx);
1061
14
        if (read_rows == 0) {
1062
0
            break;
1063
0
        }
1064
14
        if (read_range_rows + (range.to() - range.from()) > _total_read_rows) {
1065
14
            int64_t fi =
1066
14
                    std::max(_total_read_rows, read_range_rows) - read_range_rows + range.from();
1067
14
            size_t len = std::min(read_rows, (size_t)(std::max(range.to(), fi) - fi));
1068
1069
14
            read_rows -= len;
1070
1071
28
            for (auto i = 0; i < len; i++) {
1072
14
                _current_batch_row_ids[idx++] =
1073
14
                        (rowid_t)(fi + i + _current_row_group_idx.first_row);
1074
14
            }
1075
14
        }
1076
14
        read_range_rows += range.to() - range.from();
1077
14
    }
1078
5
    return Status::OK();
1079
5
}
1080
1081
Status RowGroupReader::_fill_row_id_columns(Block* block, size_t read_rows,
1082
50
                                            bool is_current_row_ids) {
1083
50
    const bool need_row_ids =
1084
50
            _row_id_column_iterator_pair.first != nullptr ||
1085
50
            (_row_lineage_columns != nullptr && _row_lineage_columns->need_row_ids());
1086
50
    if (need_row_ids && !is_current_row_ids) {
1087
5
        RETURN_IF_ERROR(_get_current_batch_row_id(read_rows));
1088
5
    }
1089
50
    if (_row_id_column_iterator_pair.first != nullptr) {
1090
5
        auto col = block->get_by_position(_row_id_column_iterator_pair.second)
1091
5
                           .column->assume_mutable();
1092
5
        RETURN_IF_ERROR(_row_id_column_iterator_pair.first->read_by_rowids(
1093
5
                _current_batch_row_ids.data(), _current_batch_row_ids.size(), col));
1094
5
    }
1095
1096
50
    if (_row_lineage_columns != nullptr && _row_lineage_columns->need_row_ids() &&
1097
50
        _row_lineage_columns->first_row_id >= 0) {
1098
0
        auto col = block->get_by_position(_row_lineage_columns->row_id_column_idx)
1099
0
                           .column->assume_mutable();
1100
0
        auto* nullable_column = assert_cast<ColumnNullable*>(col.get());
1101
0
        auto& null_map = nullable_column->get_null_map_data();
1102
0
        auto& data =
1103
0
                assert_cast<ColumnInt64&>(*nullable_column->get_nested_column_ptr()).get_data();
1104
0
        for (size_t i = 0; i < read_rows; ++i) {
1105
0
            if (null_map[i] != 0) {
1106
0
                null_map[i] = 0;
1107
0
                data[i] = _row_lineage_columns->first_row_id +
1108
0
                          static_cast<int64_t>(_current_batch_row_ids[i]);
1109
0
            }
1110
0
        }
1111
0
    }
1112
1113
50
    if (_row_lineage_columns != nullptr &&
1114
50
        _row_lineage_columns->has_last_updated_sequence_number_column() &&
1115
50
        _row_lineage_columns->last_updated_sequence_number >= 0) {
1116
0
        auto col = block->get_by_position(
1117
0
                                _row_lineage_columns->last_updated_sequence_number_column_idx)
1118
0
                           .column->assume_mutable();
1119
0
        auto* nullable_column = assert_cast<ColumnNullable*>(col.get());
1120
0
        auto& null_map = nullable_column->get_null_map_data();
1121
0
        auto& data =
1122
0
                assert_cast<ColumnInt64&>(*nullable_column->get_nested_column_ptr()).get_data();
1123
0
        for (size_t i = 0; i < read_rows; ++i) {
1124
0
            if (null_map[i] != 0) {
1125
0
                null_map[i] = 0;
1126
0
                data[i] = _row_lineage_columns->last_updated_sequence_number;
1127
0
            }
1128
0
        }
1129
0
    }
1130
1131
50
    return Status::OK();
1132
50
}
1133
1134
Status RowGroupReader::_append_iceberg_rowid_column(Block* block, size_t read_rows,
1135
50
                                                    bool is_current_row_ids) {
1136
50
    if (!_iceberg_rowid_params.enabled) {
1137
50
        return Status::OK();
1138
50
    }
1139
0
    if (!is_current_row_ids) {
1140
0
        RETURN_IF_ERROR(_get_current_batch_row_id(read_rows));
1141
0
    }
1142
1143
0
    int row_id_idx = block->get_position_by_name(doris::BeConsts::ICEBERG_ROWID_COL);
1144
0
    if (row_id_idx >= 0) {
1145
0
        auto& col_with_type = block->get_by_position(static_cast<size_t>(row_id_idx));
1146
0
        MutableColumnPtr row_id_column;
1147
0
        RETURN_IF_ERROR(build_iceberg_rowid_column(
1148
0
                col_with_type.type, _iceberg_rowid_params.file_path, _current_batch_row_ids,
1149
0
                _iceberg_rowid_params.partition_spec_id, _iceberg_rowid_params.partition_data_json,
1150
0
                &row_id_column));
1151
0
        col_with_type.column = std::move(row_id_column);
1152
0
    } else {
1153
0
        DataTypes field_types;
1154
0
        field_types.push_back(std::make_shared<DataTypeString>());
1155
0
        field_types.push_back(std::make_shared<DataTypeInt64>());
1156
0
        field_types.push_back(std::make_shared<DataTypeInt32>());
1157
0
        field_types.push_back(std::make_shared<DataTypeString>());
1158
1159
0
        std::vector<std::string> field_names = {"file_path", "row_position", "partition_spec_id",
1160
0
                                                "partition_data"};
1161
1162
0
        auto row_id_type = std::make_shared<DataTypeStruct>(field_types, field_names);
1163
0
        MutableColumnPtr row_id_column;
1164
0
        RETURN_IF_ERROR(build_iceberg_rowid_column(
1165
0
                row_id_type, _iceberg_rowid_params.file_path, _current_batch_row_ids,
1166
0
                _iceberg_rowid_params.partition_spec_id, _iceberg_rowid_params.partition_data_json,
1167
0
                &row_id_column));
1168
0
        int insert_pos = _iceberg_rowid_params.row_id_column_pos;
1169
0
        if (insert_pos < 0 || insert_pos > static_cast<int>(block->columns())) {
1170
0
            insert_pos = static_cast<int>(block->columns());
1171
0
        }
1172
0
        block->insert(static_cast<size_t>(insert_pos),
1173
0
                      ColumnWithTypeAndName(std::move(row_id_column), row_id_type,
1174
0
                                            doris::BeConsts::ICEBERG_ROWID_COL));
1175
0
    }
1176
1177
0
    if (_col_name_to_block_idx != nullptr) {
1178
0
        *_col_name_to_block_idx = block->get_name_to_pos_map();
1179
0
    }
1180
1181
0
    return Status::OK();
1182
0
}
1183
1184
47
Status RowGroupReader::_build_pos_delete_filter(size_t read_rows) {
1185
47
    if (!_position_delete_ctx.has_filter) {
1186
47
        _pos_delete_filter_ptr.reset(nullptr);
1187
47
        _total_read_rows += read_rows;
1188
47
        return Status::OK();
1189
47
    }
1190
0
    _pos_delete_filter_ptr.reset(new IColumn::Filter(read_rows, 1));
1191
0
    auto* __restrict _pos_delete_filter_data = _pos_delete_filter_ptr->data();
1192
0
    while (_position_delete_ctx.index < _position_delete_ctx.end_index) {
1193
0
        const int64_t delete_row_index_in_row_group =
1194
0
                _position_delete_ctx.delete_rows[_position_delete_ctx.index] -
1195
0
                _position_delete_ctx.first_row_id;
1196
0
        int64_t read_range_rows = 0;
1197
0
        size_t remaining_read_rows = _total_read_rows + read_rows;
1198
0
        for (size_t range_idx = 0; range_idx < _read_ranges.range_size(); range_idx++) {
1199
0
            auto range = _read_ranges.get_range(range_idx);
1200
0
            if (delete_row_index_in_row_group < range.from()) {
1201
0
                ++_position_delete_ctx.index;
1202
0
                break;
1203
0
            } else if (delete_row_index_in_row_group < range.to()) {
1204
0
                int64_t index = (delete_row_index_in_row_group - range.from()) + read_range_rows -
1205
0
                                _total_read_rows;
1206
0
                if (index > read_rows - 1) {
1207
0
                    _total_read_rows += read_rows;
1208
0
                    return Status::OK();
1209
0
                }
1210
0
                _pos_delete_filter_data[index] = 0;
1211
0
                ++_position_delete_ctx.index;
1212
0
                break;
1213
0
            } else { // delete_row >= range.last_row
1214
0
            }
1215
1216
0
            int64_t range_size = range.to() - range.from();
1217
            // Don't search next range when there is no remaining_read_rows.
1218
0
            if (remaining_read_rows <= range_size) {
1219
0
                _total_read_rows += read_rows;
1220
0
                return Status::OK();
1221
0
            } else {
1222
0
                remaining_read_rows -= range_size;
1223
0
                read_range_rows += range_size;
1224
0
            }
1225
0
        }
1226
0
    }
1227
0
    _total_read_rows += read_rows;
1228
0
    return Status::OK();
1229
0
}
1230
1231
// need exception safety
1232
Status RowGroupReader::_filter_block(Block* block, int column_to_keep,
1233
35
                                     const std::vector<uint32_t>& columns_to_filter) {
1234
35
    if (_pos_delete_filter_ptr) {
1235
0
        RETURN_IF_CATCH_EXCEPTION(
1236
0
                Block::filter_block_internal(block, columns_to_filter, (*_pos_delete_filter_ptr)));
1237
0
    }
1238
35
    Block::erase_useless_column(block, column_to_keep);
1239
1240
35
    return Status::OK();
1241
35
}
1242
1243
6
Status RowGroupReader::_rewrite_dict_predicates() {
1244
6
    SCOPED_RAW_TIMER(&_dict_filter_rewrite_time);
1245
6
    for (auto it = _dict_filter_cols.begin(); it != _dict_filter_cols.end();) {
1246
2
        std::string& dict_filter_col_name = it->first;
1247
2
        int slot_id = it->second;
1248
        // 1. Get dictionary values to a string column.
1249
2
        MutableColumnPtr dict_value_column = ColumnString::create();
1250
2
        bool has_dict = false;
1251
2
        RETURN_IF_ERROR(_column_readers[dict_filter_col_name]->read_dict_values_to_column(
1252
2
                dict_value_column, &has_dict));
1253
2
#ifndef NDEBUG
1254
2
        dict_value_column->sanity_check();
1255
2
#endif
1256
2
        size_t dict_value_column_size = dict_value_column->size();
1257
2
        DCHECK(has_dict);
1258
        // 2. Build a temp block from the dict string column, then execute conjuncts and filter block.
1259
        // 2.1 Build a temp block from the dict string column to match the conjuncts executing.
1260
2
        Block temp_block;
1261
2
        int dict_pos = -1;
1262
2
        int index = 0;
1263
4
        for (const auto slot_desc : _tuple_descriptor->slots()) {
1264
4
            if (slot_desc->id() == slot_id) {
1265
2
                auto data_type = slot_desc->get_data_type_ptr();
1266
2
                if (data_type->is_nullable()) {
1267
0
                    temp_block.insert(
1268
0
                            {ColumnNullable::create(
1269
0
                                     std::move(
1270
0
                                             dict_value_column), // NOLINT(bugprone-use-after-move)
1271
0
                                     ColumnUInt8::create(dict_value_column_size, 0)),
1272
0
                             std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>()),
1273
0
                             ""});
1274
2
                } else {
1275
2
                    temp_block.insert(
1276
2
                            {std::move(dict_value_column), std::make_shared<DataTypeString>(), ""});
1277
2
                }
1278
2
                dict_pos = index;
1279
1280
2
            } else {
1281
2
                temp_block.insert(ColumnWithTypeAndName(slot_desc->get_empty_mutable_column(),
1282
2
                                                        slot_desc->get_data_type_ptr(),
1283
2
                                                        slot_desc->col_name()));
1284
2
            }
1285
4
            ++index;
1286
4
        }
1287
1288
        // 2.2 Execute conjuncts.
1289
2
        VExprContextSPtrs ctxs;
1290
2
        auto iter = _slot_id_to_filter_conjuncts->find(slot_id);
1291
2
        if (iter != _slot_id_to_filter_conjuncts->end()) {
1292
2
            for (auto& ctx : iter->second) {
1293
2
                ctxs.push_back(ctx);
1294
2
            }
1295
2
        } else {
1296
0
            std::stringstream msg;
1297
0
            msg << "_slot_id_to_filter_conjuncts: slot_id [" << slot_id << "] not found";
1298
0
            return Status::NotFound(msg.str());
1299
0
        }
1300
1301
2
        if (dict_pos != 0) {
1302
            // VExprContext.execute has an optimization, the filtering is executed when block->rows() > 0
1303
            // The following process may be tricky and time-consuming, but we have no other way.
1304
0
            temp_block.get_by_position(0).column->assume_mutable()->resize(dict_value_column_size);
1305
0
        }
1306
2
        IColumn::Filter result_filter(temp_block.rows(), 1);
1307
2
        bool can_filter_all;
1308
2
        {
1309
2
            RETURN_IF_ERROR(VExprContext::execute_conjuncts(ctxs, nullptr, &temp_block,
1310
2
                                                            &result_filter, &can_filter_all));
1311
2
        }
1312
2
        if (dict_pos != 0) {
1313
            // We have to clean the first column to insert right data.
1314
0
            temp_block.get_by_position(0).column->assume_mutable()->clear();
1315
0
        }
1316
1317
        // If can_filter_all = true, can filter this row group.
1318
2
        if (can_filter_all) {
1319
2
            _is_row_group_filtered = true;
1320
2
            return Status::OK();
1321
2
        }
1322
1323
        // 3. Get dict codes.
1324
0
        std::vector<int32_t> dict_codes;
1325
0
        for (size_t i = 0; i < result_filter.size(); ++i) {
1326
0
            if (result_filter[i]) {
1327
0
                dict_codes.emplace_back(i);
1328
0
            }
1329
0
        }
1330
1331
        // About Performance: if dict_column size is too large, it will generate a large IN filter.
1332
0
        if (dict_codes.size() > MAX_DICT_CODE_PREDICATE_TO_REWRITE) {
1333
0
            it = _dict_filter_cols.erase(it);
1334
0
            for (auto& ctx : ctxs) {
1335
0
                _filter_conjuncts.push_back(ctx);
1336
0
            }
1337
0
            continue;
1338
0
        }
1339
1340
        // 4. Rewrite conjuncts.
1341
0
        RETURN_IF_ERROR(_rewrite_dict_conjuncts(
1342
0
                dict_codes, slot_id, temp_block.get_by_position(dict_pos).column->is_nullable()));
1343
0
        ++it;
1344
0
    }
1345
4
    return Status::OK();
1346
6
}
1347
1348
Status RowGroupReader::_rewrite_dict_conjuncts(std::vector<int32_t>& dict_codes, int slot_id,
1349
0
                                               bool is_nullable) {
1350
0
    VExprSPtr root;
1351
0
    if (dict_codes.size() == 1) {
1352
0
        {
1353
0
            TFunction fn;
1354
0
            TFunctionName fn_name;
1355
0
            fn_name.__set_db_name("");
1356
0
            fn_name.__set_function_name("eq");
1357
0
            fn.__set_name(fn_name);
1358
0
            fn.__set_binary_type(TFunctionBinaryType::BUILTIN);
1359
0
            std::vector<TTypeDesc> arg_types;
1360
0
            arg_types.push_back(create_type_desc(PrimitiveType::TYPE_INT));
1361
0
            arg_types.push_back(create_type_desc(PrimitiveType::TYPE_INT));
1362
0
            fn.__set_arg_types(arg_types);
1363
0
            fn.__set_ret_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
1364
0
            fn.__set_has_var_args(false);
1365
1366
0
            TExprNode texpr_node;
1367
0
            texpr_node.__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
1368
0
            texpr_node.__set_node_type(TExprNodeType::BINARY_PRED);
1369
0
            texpr_node.__set_opcode(TExprOpcode::EQ);
1370
0
            texpr_node.__set_fn(fn);
1371
0
            texpr_node.__set_num_children(2);
1372
0
            texpr_node.__set_is_nullable(is_nullable);
1373
0
            root = VectorizedFnCall::create_shared(texpr_node);
1374
0
        }
1375
0
        {
1376
0
            SlotDescriptor* slot = nullptr;
1377
0
            const std::vector<SlotDescriptor*>& slots = _tuple_descriptor->slots();
1378
0
            for (auto each : slots) {
1379
0
                if (each->id() == slot_id) {
1380
0
                    slot = each;
1381
0
                    break;
1382
0
                }
1383
0
            }
1384
0
            root->add_child(VSlotRef::create_shared(slot));
1385
0
        }
1386
0
        {
1387
0
            TExprNode texpr_node;
1388
0
            texpr_node.__set_node_type(TExprNodeType::INT_LITERAL);
1389
0
            texpr_node.__set_type(create_type_desc(TYPE_INT));
1390
0
            TIntLiteral int_literal;
1391
0
            int_literal.__set_value(dict_codes[0]);
1392
0
            texpr_node.__set_int_literal(int_literal);
1393
0
            texpr_node.__set_is_nullable(is_nullable);
1394
0
            root->add_child(VLiteral::create_shared(texpr_node));
1395
0
        }
1396
0
    } else {
1397
0
        {
1398
0
            TTypeDesc type_desc = create_type_desc(PrimitiveType::TYPE_BOOLEAN);
1399
0
            TExprNode node;
1400
0
            node.__set_type(type_desc);
1401
0
            node.__set_node_type(TExprNodeType::IN_PRED);
1402
0
            node.in_predicate.__set_is_not_in(false);
1403
0
            node.__set_opcode(TExprOpcode::FILTER_IN);
1404
            // VdirectInPredicate assume is_nullable = false.
1405
0
            node.__set_is_nullable(false);
1406
1407
0
            std::shared_ptr<HybridSetBase> hybrid_set(
1408
0
                    create_set(PrimitiveType::TYPE_INT, dict_codes.size(), false));
1409
0
            for (int j = 0; j < dict_codes.size(); ++j) {
1410
0
                hybrid_set->insert(&dict_codes[j]);
1411
0
            }
1412
0
            root = VDirectInPredicate::create_shared(node, hybrid_set);
1413
0
        }
1414
0
        {
1415
0
            SlotDescriptor* slot = nullptr;
1416
0
            const std::vector<SlotDescriptor*>& slots = _tuple_descriptor->slots();
1417
0
            for (auto each : slots) {
1418
0
                if (each->id() == slot_id) {
1419
0
                    slot = each;
1420
0
                    break;
1421
0
                }
1422
0
            }
1423
0
            root->add_child(VSlotRef::create_shared(slot));
1424
0
        }
1425
0
    }
1426
0
    VExprContextSPtr rewritten_conjunct_ctx = VExprContext::create_shared(root);
1427
0
    RETURN_IF_ERROR(rewritten_conjunct_ctx->prepare(_state, *_row_descriptor));
1428
0
    RETURN_IF_ERROR(rewritten_conjunct_ctx->open(_state));
1429
0
    _dict_filter_conjuncts.push_back(rewritten_conjunct_ctx);
1430
0
    _filter_conjuncts.push_back(rewritten_conjunct_ctx);
1431
0
    return Status::OK();
1432
0
}
1433
1434
45
Status RowGroupReader::_convert_dict_cols_to_string_cols(Block* block) {
1435
45
    for (auto& dict_filter_cols : _dict_filter_cols) {
1436
0
        if (!_col_name_to_block_idx->contains(dict_filter_cols.first)) {
1437
0
            throw Exception(ErrorCode::INTERNAL_ERROR,
1438
0
                            "Wrong read column '{}' in parquet file, block: {}",
1439
0
                            dict_filter_cols.first, block->dump_structure());
1440
0
        }
1441
0
        ColumnWithTypeAndName& column_with_type_and_name =
1442
0
                block->get_by_position((*_col_name_to_block_idx)[dict_filter_cols.first]);
1443
0
        const ColumnPtr& column = column_with_type_and_name.column;
1444
0
        if (const auto* nullable_column = check_and_get_column<ColumnNullable>(*column)) {
1445
0
            const ColumnPtr& nested_column = nullable_column->get_nested_column_ptr();
1446
0
            const auto* dict_column = assert_cast<const ColumnInt32*>(nested_column.get());
1447
0
            DCHECK(dict_column);
1448
1449
0
            auto string_column = DORIS_TRY(
1450
0
                    _column_readers[dict_filter_cols.first]->convert_dict_column_to_string_column(
1451
0
                            dict_column));
1452
1453
0
            column_with_type_and_name.type =
1454
0
                    std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>());
1455
0
            block->replace_by_position(
1456
0
                    (*_col_name_to_block_idx)[dict_filter_cols.first],
1457
0
                    ColumnNullable::create(std::move(string_column),
1458
0
                                           nullable_column->get_null_map_column_ptr()));
1459
0
        } else {
1460
0
            const auto* dict_column = assert_cast<const ColumnInt32*>(column.get());
1461
0
            auto string_column = DORIS_TRY(
1462
0
                    _column_readers[dict_filter_cols.first]->convert_dict_column_to_string_column(
1463
0
                            dict_column));
1464
1465
0
            column_with_type_and_name.type = std::make_shared<DataTypeString>();
1466
0
            block->replace_by_position((*_col_name_to_block_idx)[dict_filter_cols.first],
1467
0
                                       std::move(string_column));
1468
0
        }
1469
0
    }
1470
45
    return Status::OK();
1471
45
}
1472
1473
38
ParquetColumnReader::ColumnStatistics RowGroupReader::merged_column_statistics() {
1474
38
    ParquetColumnReader::ColumnStatistics st;
1475
108
    for (auto& reader : _column_readers) {
1476
108
        auto ost = reader.second->column_statistics();
1477
108
        st.merge(ost);
1478
108
    }
1479
38
    return st;
1480
38
}
1481
1482
} // namespace doris