Coverage Report

Created: 2026-07-25 08:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/scan/file_scanner_v2.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 "exec/scan/file_scanner_v2.h"
19
20
#include <gen_cpp/Exprs_types.h>
21
#include <gen_cpp/PlanNodes_types.h>
22
23
#include <algorithm>
24
#include <map>
25
#include <memory>
26
#include <optional>
27
#include <sstream>
28
#include <string>
29
#include <utility>
30
31
#include "common/cast_set.h"
32
#include "common/config.h"
33
#include "common/consts.h"
34
#include "common/metrics/doris_metrics.h"
35
#include "common/status.h"
36
#include "core/assert_cast.h"
37
#include "core/block/column_with_type_and_name.h"
38
#include "core/column/column.h"
39
#include "core/data_type/data_type.h"
40
#include "core/data_type/data_type_nullable.h"
41
#include "core/data_type_serde/data_type_serde.h"
42
#include "core/string_ref.h"
43
#include "exec/common/util.hpp"
44
#include "exec/operator/scan_operator.h"
45
#include "exec/scan/access_path_parser.h"
46
#include "exec/scan/file_scan_io_context.h"
47
#include "exprs/runtime_filter_expr.h"
48
#include "exprs/vexpr.h"
49
#include "exprs/vexpr_context.h"
50
#include "exprs/vslot_ref.h"
51
#include "format/format_common.h"
52
#include "format/table/iceberg_scan_semantics.h"
53
#include "format_v2/column_mapper.h"
54
#include "format_v2/jni/iceberg_sys_table_reader.h"
55
#include "format_v2/jni/jdbc_reader.h"
56
#include "format_v2/jni/max_compute_jni_reader.h"
57
#include "format_v2/jni/trino_connector_jni_reader.h"
58
#include "format_v2/table/hive_reader.h"
59
#include "format_v2/table/hudi_reader.h"
60
#include "format_v2/table/iceberg_position_delete_sys_table_reader.h"
61
#include "format_v2/table/iceberg_reader.h"
62
#include "format_v2/table/paimon_reader.h"
63
#include "format_v2/table/remote_doris_reader.h"
64
#include "format_v2/table_reader.h"
65
#include "io/cache/block_file_cache_profile.h"
66
#include "io/fs/file_meta_cache.h"
67
#include "io/io_common.h"
68
#include "runtime/descriptors.h"
69
#include "runtime/exec_env.h"
70
#include "runtime/file_scan_profile.h"
71
#include "runtime/runtime_state.h"
72
#include "service/backend_options.h"
73
#include "storage/id_manager.h"
74
75
namespace doris {
76
namespace {
77
78
constexpr int kIcebergPositionDeleteContent = 1;
79
constexpr int kIcebergDeletionVectorContent = 3;
80
81
104k
std::string table_format_name(const TFileRangeDesc& range) {
82
104k
    return range.__isset.table_format_params ? range.table_format_params.table_format_type
83
104k
                                             : "NotSet";
84
104k
}
85
86
TFileFormatType::type get_range_format_type(const TFileScanRangeParams& params,
87
248k
                                            const TFileRangeDesc& range) {
88
248k
    return range.__isset.format_type ? range.format_type : params.format_type;
89
248k
}
90
91
63.0k
bool is_supported_table_format(const TFileRangeDesc& range) {
92
63.0k
    const auto table_format = table_format_name(range);
93
63.0k
    if (table_format == "hudi" && range.__isset.table_format_params &&
94
63.0k
        range.table_format_params.__isset.hudi_params &&
95
63.0k
        range.table_format_params.hudi_params.__isset.delta_logs &&
96
63.0k
        !range.table_format_params.hudi_params.delta_logs.empty()) {
97
        // Hudi MOR splits need log-file merge semantics and must stay on the existing JNI path.
98
        // FileScannerV2 currently supports native Parquet data files only.
99
1
        return false;
100
1
    }
101
63.0k
    return table_format == "NotSet" || table_format == "tvf" || table_format == "hive" ||
102
63.0k
           table_format == "iceberg" || table_format == "paimon" || table_format == "hudi";
103
63.0k
}
104
105
101
bool is_supported_arrow_table_format(const TFileRangeDesc& range) {
106
101
    return table_format_name(range) == "remote_doris";
107
101
}
108
109
5
bool is_supported_jni_table_format(const TFileRangeDesc& range) {
110
5
    const auto table_format = table_format_name(range);
111
5
    if (table_format == "paimon") {
112
2
        return range.__isset.table_format_params &&
113
2
               range.table_format_params.__isset.paimon_params &&
114
2
               range.table_format_params.paimon_params.__isset.reader_type &&
115
2
               range.table_format_params.paimon_params.reader_type == TPaimonReaderType::PAIMON_JNI;
116
2
    }
117
3
    return table_format == "jdbc" || table_format == "iceberg" || table_format == "hudi" ||
118
3
           table_format == "max_compute" || table_format == "trino_connector";
119
5
}
120
121
18.5k
bool is_iceberg_position_deletes_sys_table(const TFileRangeDesc& range) {
122
18.5k
    return range.__isset.table_format_params &&
123
18.5k
           range.table_format_params.table_format_type == "iceberg" &&
124
18.5k
           range.table_format_params.__isset.iceberg_params &&
125
18.5k
           range.table_format_params.iceberg_params.__isset.content &&
126
18.5k
           (range.table_format_params.iceberg_params.content == kIcebergPositionDeleteContent ||
127
1.12k
            range.table_format_params.iceberg_params.content == kIcebergDeletionVectorContent);
128
18.5k
}
129
130
6.13k
bool is_csv_format(TFileFormatType::type format_type) {
131
6.13k
    switch (format_type) {
132
811
    case TFileFormatType::FORMAT_CSV_PLAIN:
133
812
    case TFileFormatType::FORMAT_CSV_GZ:
134
813
    case TFileFormatType::FORMAT_CSV_BZ2:
135
814
    case TFileFormatType::FORMAT_CSV_LZ4FRAME:
136
815
    case TFileFormatType::FORMAT_CSV_LZ4BLOCK:
137
816
    case TFileFormatType::FORMAT_CSV_LZOP:
138
817
    case TFileFormatType::FORMAT_CSV_DEFLATE:
139
818
    case TFileFormatType::FORMAT_CSV_SNAPPYBLOCK:
140
819
    case TFileFormatType::FORMAT_PROTO:
141
819
        return true;
142
5.31k
    default:
143
5.31k
        return false;
144
6.13k
    }
145
6.13k
}
146
147
5.31k
bool is_text_format(TFileFormatType::type format_type) {
148
5.31k
    return format_type == TFileFormatType::FORMAT_TEXT;
149
5.31k
}
150
151
595
bool is_json_format(TFileFormatType::type format_type) {
152
595
    return format_type == TFileFormatType::FORMAT_JSON;
153
595
}
154
155
5
bool is_native_format(TFileFormatType::type format_type) {
156
5
    return format_type == TFileFormatType::FORMAT_NATIVE;
157
5
}
158
159
241k
bool is_partition_slot(const TFileScanSlotInfo& slot_info, const std::string& column_name) {
160
241k
    if (column_name.starts_with(BeConsts::GLOBAL_ROWID_COL) ||
161
241k
        column_name == BeConsts::ICEBERG_ROWID_COL) {
162
4.69k
        return false;
163
4.69k
    }
164
236k
    return slot_info.__isset.category ? slot_info.category == TColumnCategory::PARTITION_KEY
165
236k
                                      : !slot_info.is_file_slot;
166
241k
}
167
168
228k
bool is_data_file_slot(const TFileScanSlotInfo& slot_info, const std::string& column_name) {
169
228k
    if (column_name.starts_with(BeConsts::GLOBAL_ROWID_COL) ||
170
228k
        column_name == BeConsts::ICEBERG_ROWID_COL) {
171
4.69k
        return false;
172
4.69k
    }
173
    // CSV and other non-self-describing formats need FE slot descriptors for only the columns that
174
    // are physically read from the file. Partition/default/virtual columns stay in TableReader's
175
    // mapping layer and are materialized after the file-local block is read. New FE provides an
176
    // explicit category; old FE falls back to `is_file_slot`.
177
224k
    if (slot_info.__isset.category) {
178
224k
        return slot_info.category == TColumnCategory::REGULAR ||
179
224k
               slot_info.category == TColumnCategory::GENERATED;
180
224k
    }
181
2
    return slot_info.is_file_slot;
182
224k
}
183
184
Status rewrite_slot_refs_to_global_index(
185
        VExprSPtr* expr,
186
233k
        const std::unordered_map<int32_t, format::GlobalIndex>& slot_id_to_global_index) {
187
233k
    DORIS_CHECK(expr != nullptr);
188
233k
    if (*expr == nullptr) {
189
0
        return Status::OK();
190
0
    }
191
233k
    if (auto* runtime_filter = dynamic_cast<RuntimeFilterExpr*>(expr->get());
192
233k
        runtime_filter != nullptr) {
193
9.98k
        auto impl = runtime_filter->get_impl();
194
9.98k
        DORIS_CHECK(impl != nullptr);
195
9.98k
        RETURN_IF_ERROR(rewrite_slot_refs_to_global_index(&impl, slot_id_to_global_index));
196
9.98k
        runtime_filter->set_impl(std::move(impl));
197
9.98k
        return Status::OK();
198
9.98k
    }
199
223k
    if ((*expr)->is_slot_ref()) {
200
71.0k
        const auto* slot_ref = assert_cast<const VSlotRef*>(expr->get());
201
71.0k
        const auto global_index_it = slot_id_to_global_index.find(slot_ref->slot_id());
202
71.0k
        if (global_index_it == slot_id_to_global_index.end()) {
203
1
            return Status::InternalError(
204
1
                    "Can not resolve source slot id {} to a table global index for column {}",
205
1
                    slot_ref->slot_id(), slot_ref->column_name());
206
1
        }
207
71.0k
        const auto global_index = global_index_it->second;
208
71.0k
        *expr = VSlotRef::create_shared(cast_set<int>(global_index.value()),
209
71.0k
                                        cast_set<int>(global_index.value()), -1,
210
71.0k
                                        slot_ref->data_type(), slot_ref->column_name());
211
71.0k
        RETURN_IF_ERROR(expr->get()->prepare(nullptr, RowDescriptor(), nullptr));
212
71.0k
        return Status::OK();
213
71.0k
    }
214
152k
    auto children = (*expr)->children();
215
155k
    for (auto& child : children) {
216
155k
        if (child == nullptr) {
217
0
            continue;
218
0
        }
219
155k
        RETURN_IF_ERROR(rewrite_slot_refs_to_global_index(&child, slot_id_to_global_index));
220
155k
    }
221
152k
    (*expr)->set_children(std::move(children));
222
152k
    return Status::OK();
223
152k
}
224
225
} // namespace
226
227
#ifdef BE_TEST
228
FileScannerV2::FileScannerV2(RuntimeState* state, RuntimeProfile* profile,
229
                             std::unique_ptr<format::TableReader> table_reader)
230
        : Scanner(state, profile),
231
          _table_reader(std::move(table_reader)),
232
          _scanner_profile(profile) {}
233
234
Status FileScannerV2::TEST_validate_scan_range(const TFileScanRangeParams& params,
235
                                               const TFileRangeDesc& range) {
236
    return _validate_scan_range(params, range);
237
}
238
239
Status FileScannerV2::TEST_to_file_format(TFileFormatType::type format_type,
240
                                          format::FileFormat* file_format) {
241
    return _to_file_format(format_type, file_format);
242
}
243
244
bool FileScannerV2::TEST_is_partition_slot(const TFileScanSlotInfo& slot_info,
245
                                           const std::string& column_name) {
246
    return is_partition_slot(slot_info, column_name);
247
}
248
249
bool FileScannerV2::TEST_is_data_file_slot(const TFileScanSlotInfo& slot_info,
250
                                           const std::string& column_name) {
251
    return is_data_file_slot(slot_info, column_name);
252
}
253
254
Status FileScannerV2::TEST_rewrite_slot_refs_to_global_index(
255
        VExprSPtr* expr,
256
        const std::unordered_map<int32_t, format::GlobalIndex>& slot_id_to_global_index) {
257
    return rewrite_slot_refs_to_global_index(expr, slot_id_to_global_index);
258
}
259
260
FileScannerV2::RealtimeCounterDeltas FileScannerV2::TEST_collect_realtime_counter_deltas(
261
        const io::FileReaderStats& file_reader_stats,
262
        const io::FileCacheStatistics& file_cache_statistics,
263
        UncachedReaderBytesStorage uncached_reader_bytes_storage, int64_t* last_read_bytes,
264
        int64_t* last_read_rows, int64_t* last_bytes_read_from_local,
265
        int64_t* last_bytes_read_from_remote) {
266
    return _collect_realtime_counter_deltas(file_reader_stats, file_cache_statistics,
267
                                            uncached_reader_bytes_storage, last_read_bytes,
268
                                            last_read_rows, last_bytes_read_from_local,
269
                                            last_bytes_read_from_remote);
270
}
271
272
void FileScannerV2::TEST_report_file_cache_profile(
273
        RuntimeProfile* profile, const io::FileCacheStatistics& file_cache_statistics) {
274
    _report_file_cache_profile(profile, file_cache_statistics);
275
}
276
277
bool FileScannerV2::TEST_should_skip_not_found(const Status& status, bool ignore_not_found) {
278
    return _should_skip_not_found(status, ignore_not_found);
279
}
280
281
bool FileScannerV2::TEST_should_skip_empty(const Status& status, bool stopped) {
282
    return _should_skip_empty(status, stopped);
283
}
284
#endif
285
286
63.1k
bool FileScannerV2::is_supported(const TFileScanRangeParams& params, const TFileRangeDesc& range) {
287
63.1k
    const auto format_type = get_range_format_type(params, range);
288
63.1k
    if (format_type == TFileFormatType::FORMAT_PARQUET ||
289
63.1k
        format_type == TFileFormatType::FORMAT_ORC) {
290
56.9k
        return is_supported_table_format(range);
291
56.9k
    } else if (format_type == TFileFormatType::FORMAT_ARROW) {
292
101
        return is_supported_arrow_table_format(range);
293
6.14k
    } else if (format_type == TFileFormatType::FORMAT_JNI) {
294
5
        return is_supported_jni_table_format(range);
295
6.13k
    } else if (is_csv_format(format_type) || is_text_format(format_type) ||
296
6.13k
               is_json_format(format_type) || is_native_format(format_type)) {
297
6.13k
        return is_supported_table_format(range);
298
6.13k
    } else {
299
4
        LOG(WARNING) << "Unsupported file format type " << format_type << " for file scanner v2";
300
4
        return false;
301
4
    }
302
63.1k
}
303
304
Status FileScannerV2::_validate_scan_range(const TFileScanRangeParams& params,
305
63.1k
                                           const TFileRangeDesc& range) {
306
63.1k
    if (!is_supported(params, range)) {
307
1
        return Status::NotSupported(
308
1
                "FileScannerV2 does not support table format {} with file format {}",
309
1
                table_format_name(range), to_string(get_range_format_type(params, range)));
310
1
    }
311
63.1k
    return Status::OK();
312
63.1k
}
313
314
FileScannerV2::FileScannerV2(RuntimeState* state, FileScanLocalState* local_state, int64_t limit,
315
                             std::shared_ptr<SplitSourceConnector> split_source,
316
                             RuntimeProfile* profile, ShardedKVCache* kv_cache,
317
                             const std::unordered_map<std::string, int>* colname_to_slot_id)
318
76.5k
        : Scanner(state, local_state, limit, profile),
319
76.5k
          _split_source(std::move(split_source)),
320
76.5k
          _kv_cache(kv_cache) {
321
76.5k
    (void)colname_to_slot_id;
322
76.5k
    if (state->get_query_ctx() != nullptr &&
323
76.5k
        state->get_query_ctx()->file_scan_range_params_map.count(local_state->parent_id()) > 0) {
324
76.3k
        _params = &(state->get_query_ctx()->file_scan_range_params_map[local_state->parent_id()]);
325
76.3k
    } else {
326
198
        _params = _split_source->get_params();
327
198
    }
328
76.5k
}
329
330
76.2k
Status FileScannerV2::init(RuntimeState* state, const VExprContextSPtrs& conjuncts) {
331
76.2k
    RETURN_IF_ERROR(Scanner::init(state, conjuncts));
332
76.2k
    _initialize_scanner_residual_conjuncts();
333
76.2k
    auto* profile = _local_state->scanner_profile();
334
76.2k
    _scanner_profile = profile;
335
76.2k
    const auto hierarchy = file_scan_profile::ensure_hierarchy(profile);
336
76.2k
    _scanner_total_timer = hierarchy.scanner;
337
76.2k
    _io_timer = hierarchy.io;
338
76.2k
    _init_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "FileScannerV2InitTime",
339
76.2k
                                             file_scan_profile::SCANNER, 1);
340
76.2k
    _open_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "FileScannerV2OpenTime",
341
76.2k
                                             file_scan_profile::SCANNER, 1);
342
76.2k
    _get_block_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "FileScannerV2GetBlockTime",
343
76.2k
                                                  file_scan_profile::SCANNER, 1);
344
76.2k
    _prepare_split_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "FileScannerV2PrepareSplitTime",
345
76.2k
                                                      file_scan_profile::SCANNER, 1);
346
76.2k
    _get_next_range_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "FileScannerV2GetNextRangeTime",
347
76.2k
                                                       file_scan_profile::SCANNER, 1);
348
76.2k
    _close_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "FileScannerV2CloseTime",
349
76.2k
                                              file_scan_profile::SCANNER, 1);
350
76.2k
    _empty_file_counter = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "EmptyFileNum", TUnit::UNIT,
351
76.2k
                                                       file_scan_profile::SCANNER, 1);
352
76.2k
    _not_found_file_counter = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NotFoundFileNum", TUnit::UNIT,
353
76.2k
                                                           file_scan_profile::SCANNER, 1);
354
76.2k
    _file_counter = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "FileNumber", TUnit::UNIT,
355
76.2k
                                                 file_scan_profile::SCANNER, 1);
356
76.2k
    _file_read_bytes_counter = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "FileReadBytes", TUnit::BYTES,
357
76.2k
                                                            file_scan_profile::IO, 1);
358
76.2k
    _file_read_calls_counter = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "FileReadCalls", TUnit::UNIT,
359
76.2k
                                                            file_scan_profile::IO, 1);
360
76.2k
    _file_read_time_counter =
361
76.2k
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "FileReadTime", file_scan_profile::IO, 1);
362
76.2k
    _adaptive_batch_predicted_rows_counter = ADD_CHILD_COUNTER_WITH_LEVEL(
363
76.2k
            profile, "AdaptiveBatchPredictedRows", TUnit::UNIT, file_scan_profile::SCANNER, 1);
364
76.2k
    _adaptive_batch_actual_bytes_counter = ADD_CHILD_COUNTER_WITH_LEVEL(
365
76.2k
            profile, "AdaptiveBatchActualBytes", TUnit::BYTES, file_scan_profile::SCANNER, 1);
366
76.2k
    _adaptive_batch_probe_count_counter = ADD_CHILD_COUNTER_WITH_LEVEL(
367
76.2k
            profile, "AdaptiveBatchProbeCount", TUnit::UNIT, file_scan_profile::SCANNER, 1);
368
76.2k
    _scanner_residual_filter_timer = ADD_CHILD_TIMER_WITH_LEVEL(
369
76.2k
            profile, "ScannerResidualFilterTime", file_scan_profile::SCANNER, 1);
370
76.2k
    _scanner_residual_rows_filtered_counter = ADD_CHILD_COUNTER_WITH_LEVEL(
371
76.2k
            profile, "ScannerResidualRowsFiltered", TUnit::UNIT, file_scan_profile::SCANNER, 1);
372
76.2k
    _refresh_scanner_residual_profile();
373
76.2k
    SCOPED_TIMER(_scanner_total_timer);
374
76.2k
    SCOPED_TIMER(_init_timer);
375
76.2k
    _file_cache_statistics = std::make_unique<io::FileCacheStatistics>();
376
76.2k
    _file_reader_stats = std::make_unique<io::FileReaderStats>();
377
76.2k
    RETURN_IF_ERROR(_init_io_ctx());
378
76.2k
    _io_ctx->file_cache_stats = _file_cache_statistics.get();
379
76.2k
    _io_ctx->file_reader_stats = _file_reader_stats.get();
380
76.2k
    _io_ctx->is_disposable = _state->query_options().disable_file_cache;
381
76.2k
    return Status::OK();
382
76.2k
}
383
384
76.8k
Status FileScannerV2::_open_impl(RuntimeState* state) {
385
76.8k
    SCOPED_TIMER(_scanner_total_timer);
386
76.8k
    SCOPED_TIMER(_open_timer);
387
76.8k
    RETURN_IF_CANCELLED(state);
388
76.8k
    RETURN_IF_ERROR(Scanner::_open_impl(state));
389
76.8k
    RETURN_IF_ERROR(_get_next_scan_range(&_first_scan_range));
390
76.8k
    if (_first_scan_range) {
391
41.3k
        RETURN_IF_ERROR(_create_table_reader_for_format(_current_range, &_table_reader));
392
41.3k
        DORIS_CHECK(_table_reader != nullptr);
393
41.3k
        RETURN_IF_ERROR(_init_expr_ctxes());
394
41.3k
        RETURN_IF_ERROR(_init_table_reader(_current_range));
395
41.3k
    }
396
76.8k
    return Status::OK();
397
76.8k
}
398
399
174k
Status FileScannerV2::_get_next_scan_range(bool* has_next) {
400
174k
    SCOPED_TIMER(_get_next_range_timer);
401
174k
    DORIS_CHECK(has_next != nullptr);
402
174k
    RETURN_IF_ERROR(_split_source->get_next(has_next, &_current_range));
403
174k
    if (*has_next) {
404
63.1k
        RETURN_IF_ERROR(_validate_scan_range(*_params, _current_range));
405
63.1k
    }
406
174k
    return Status::OK();
407
174k
}
408
409
217k
Status FileScannerV2::_get_block_impl(RuntimeState* state, Block* block, bool* eof) {
410
217k
    SCOPED_TIMER(_scanner_total_timer);
411
217k
    SCOPED_TIMER(_get_block_timer);
412
280k
    while (true) {
413
280k
        RETURN_IF_CANCELLED(state);
414
280k
        RETURN_IF_ERROR(_sync_table_reader_conjuncts());
415
280k
        if (!_has_prepared_split) {
416
138k
            RETURN_IF_ERROR(_prepare_next_split(eof));
417
138k
            if (*eof) {
418
76.2k
                return Status::OK();
419
76.2k
            }
420
138k
        }
421
422
203k
        {
423
203k
            if (_should_run_adaptive_batch_size()) {
424
200k
                _table_reader->set_batch_size(_predict_reader_batch_rows());
425
200k
            }
426
203k
            const auto status = _table_reader->get_block(block, eof);
427
203k
            if (_should_skip_not_found(status, config::ignore_not_found_file_in_external_table)) {
428
0
                RETURN_IF_ERROR(_table_reader->abort_split());
429
0
                COUNTER_UPDATE(_not_found_file_counter, 1);
430
0
                _state->update_num_finished_scan_range(1);
431
0
                _has_prepared_split = false;
432
0
                block->clear_column_data(cast_set<int64_t>(_projected_columns.size()));
433
0
                *eof = false;
434
0
                continue;
435
0
            }
436
204k
            if (_should_skip_empty(status, _should_stop || _io_ctx->should_stop)) {
437
                // END_OF_FILE here means the reader discovered a valid split with no data while
438
                // opening or probing it, not that the Scanner has exhausted all splits. Examples
439
                // are a zero-byte CSV with an explicit schema and a Doris Native file containing
440
                // only its 12-byte header. Treat it like V1's empty-file path: finish this range,
441
                // discard partial reader state, and let the loop fetch the next split.
442
0
                RETURN_IF_ERROR(_table_reader->abort_split());
443
0
                COUNTER_UPDATE(_empty_file_counter, 1);
444
0
                _state->update_num_finished_scan_range(1);
445
0
                _has_prepared_split = false;
446
0
                block->clear_column_data(cast_set<int64_t>(_projected_columns.size()));
447
0
                *eof = false;
448
0
                continue;
449
0
            }
450
203k
            RETURN_IF_ERROR(status);
451
203k
        }
452
203k
        if (*eof) {
453
62.1k
            _state->update_num_finished_scan_range(1);
454
62.1k
            _has_prepared_split = false;
455
62.1k
            *eof = false;
456
62.1k
            continue;
457
62.1k
        }
458
141k
        _update_adaptive_batch_size(*block);
459
141k
        return Status::OK();
460
203k
    }
461
217k
}
462
463
141k
Status FileScannerV2::_filter_output_block(Block* block) {
464
141k
    if (_scanner_residual_conjuncts.empty() || block->rows() == 0) {
465
117k
        return Status::OK();
466
117k
    }
467
24.2k
    SCOPED_TIMER(_scanner_residual_filter_timer);
468
24.2k
    const size_t rows_before_filter = block->rows();
469
24.2k
    auto status = VExprContext::filter_block(_scanner_residual_conjuncts, block, block->columns());
470
24.2k
    if (!status.ok() && _params != nullptr &&
471
24.2k
        _get_current_format_type() == TFileFormatType::FORMAT_ORC) {
472
2
        status.prepend("Orc row reader nextBatch failed. reason = ");
473
2
    }
474
24.2k
    RETURN_IF_ERROR(status);
475
24.2k
    const int64_t filtered_rows = cast_set<int64_t>(rows_before_filter - block->rows());
476
24.2k
    _counter.num_rows_unselected += filtered_rows;
477
24.2k
    if (_scanner_residual_rows_filtered_counter != nullptr) {
478
24.2k
        COUNTER_UPDATE(_scanner_residual_rows_filtered_counter, filtered_rows);
479
24.2k
    }
480
24.2k
    return Status::OK();
481
24.2k
}
482
483
141k
size_t FileScannerV2::_last_block_rows_read(const Block& block) const {
484
141k
    const auto& stats = _table_reader->last_materialized_block_stats();
485
141k
    return stats.has_materialized_input ? stats.rows : block.rows();
486
141k
}
487
488
142k
size_t FileScannerV2::_last_block_bytes_read(const Block& block) const {
489
142k
    const auto& stats = _table_reader->last_materialized_block_stats();
490
142k
    return stats.has_materialized_input ? stats.allocated_bytes : block.allocated_bytes();
491
142k
}
492
493
138k
Status FileScannerV2::_prepare_next_split(bool* eos) {
494
138k
    SCOPED_TIMER(_prepare_split_timer);
495
139k
    while (true) {
496
139k
        bool has_next = _first_scan_range;
497
139k
        if (!_first_scan_range) {
498
97.8k
            RETURN_IF_ERROR(_get_next_scan_range(&has_next));
499
97.8k
        }
500
139k
        _first_scan_range = false;
501
139k
        if (!has_next || _should_stop) {
502
76.2k
            *eos = true;
503
76.2k
            return Status::OK();
504
76.2k
        }
505
62.9k
        DORIS_CHECK(_table_reader != nullptr);
506
62.9k
        _current_range_path = _current_range.path;
507
508
62.9k
        const auto format_type = get_range_format_type(*_params, _current_range);
509
62.9k
        _init_adaptive_batch_size_state(format_type);
510
62.9k
        if (_block_size_predictor != nullptr) {
511
            // JNI readers open eagerly in prepare_split(). Always seed the probe before preparing
512
            // the next split: its metadata-COUNT decision is not available yet, and the state
513
            // exposed by TableReader can still describe the preceding split. Metadata shortcuts
514
            // ignore this batch size, while row-scan fallbacks need it for their first physical
515
            // read batch.
516
62.3k
            _table_reader->set_batch_size(_predict_reader_batch_rows());
517
62.3k
        }
518
62.9k
        std::map<std::string, Field> partition_values;
519
62.9k
        RETURN_IF_ERROR(_generate_partition_values(_current_range, &partition_values));
520
62.9k
        const auto status =
521
62.9k
                _prepare_table_reader_split(_current_range, std::move(partition_values));
522
62.9k
        if (_should_skip_not_found(status, config::ignore_not_found_file_in_external_table)) {
523
0
            RETURN_IF_ERROR(_table_reader->abort_split());
524
0
            COUNTER_UPDATE(_not_found_file_counter, 1);
525
0
            _state->update_num_finished_scan_range(1);
526
0
            continue;
527
0
        }
528
62.9k
        if (_should_skip_empty(status, _should_stop || _io_ctx->should_stop)) {
529
            // Schema discovery can reach EOF before a split becomes prepared. A header-only Native
530
            // file follows this path, while a reader that discovers emptiness on its first
531
            // get_block() follows the symmetric branch in _get_block_impl(). Both paths must
532
            // advance exactly one scan range and preserve later files in the same scan.
533
0
            RETURN_IF_ERROR(_table_reader->abort_split());
534
0
            COUNTER_UPDATE(_empty_file_counter, 1);
535
0
            _state->update_num_finished_scan_range(1);
536
0
            continue;
537
0
        }
538
62.9k
        RETURN_IF_ERROR(status);
539
62.9k
        if (_table_reader->current_split_pruned()) {
540
282
            _state->update_num_finished_scan_range(1);
541
282
            continue;
542
282
        }
543
62.6k
        COUNTER_UPDATE(_file_counter, 1);
544
62.6k
        _has_prepared_split = true;
545
62.6k
        *eos = false;
546
62.6k
        return Status::OK();
547
62.9k
    }
548
138k
}
549
550
41.3k
Status FileScannerV2::_init_table_reader(const TFileRangeDesc& range) {
551
41.3k
    const auto format_type = get_range_format_type(*_params, range);
552
41.3k
    format::FileFormat file_format;
553
41.3k
    RETURN_IF_ERROR(_to_file_format(format_type, &file_format));
554
41.3k
    DORIS_CHECK(_table_reader != nullptr);
555
556
41.3k
    if (!_late_arrival_rf_conjuncts.empty()) {
557
0
        const size_t owned_count = _scanner_residual_conjuncts.empty()
558
0
                                           ? _safe_conjunct_prefix_size(_late_arrival_rf_conjuncts)
559
0
                                           : 0;
560
0
        _table_reader_owned_conjunct_count += owned_count;
561
0
        _scanner_residual_conjuncts.insert(
562
0
                _scanner_residual_conjuncts.end(),
563
0
                _late_arrival_rf_conjuncts.begin() + cast_set<ptrdiff_t>(owned_count),
564
0
                _late_arrival_rf_conjuncts.end());
565
0
        _append_ordered_conjuncts.insert(_append_ordered_conjuncts.end(),
566
0
                                         _late_arrival_rf_conjuncts.begin(),
567
0
                                         _late_arrival_rf_conjuncts.end());
568
0
        _late_arrival_rf_conjuncts.clear();
569
0
        _refresh_scanner_residual_profile();
570
0
    }
571
41.3k
    VExprContextSPtrs table_conjuncts;
572
41.3k
    RETURN_IF_ERROR(_build_table_conjuncts(&table_conjuncts));
573
41.3k
    std::optional<std::vector<format::GlobalIndex>> push_down_count_columns;
574
41.3k
    const auto& push_down_count_slot_ids = _local_state->get_push_down_count_slot_ids();
575
41.3k
    if (push_down_count_slot_ids.has_value()) {
576
41.3k
        push_down_count_columns.emplace();
577
41.3k
        push_down_count_columns->reserve(push_down_count_slot_ids->size());
578
41.3k
        for (const auto slot_id : *push_down_count_slot_ids) {
579
608
            const auto global_index_it = _slot_id_to_global_index.find(slot_id);
580
608
            if (global_index_it == _slot_id_to_global_index.end()) {
581
0
                return Status::InternalError(
582
0
                        "Pushed-down COUNT argument is not a projected file scan slot, slot_id={}",
583
0
                        slot_id);
584
0
            }
585
608
            push_down_count_columns->push_back(global_index_it->second);
586
608
        }
587
41.3k
    }
588
41.3k
    RETURN_IF_ERROR(_table_reader->init({
589
41.3k
            .projected_columns = _projected_columns,
590
41.3k
            .conjuncts = std::move(table_conjuncts),
591
41.3k
            .table_reader_owned_conjunct_count = _table_reader_owned_conjunct_count,
592
41.3k
            .format = file_format,
593
41.3k
            .scan_params = const_cast<TFileScanRangeParams*>(_params),
594
41.3k
            .io_ctx = _io_ctx,
595
41.3k
            .runtime_state = _state,
596
41.3k
            .scanner_profile = _local_state->scanner_profile(),
597
41.3k
            .file_slot_descs = &_file_slot_descs,
598
41.3k
            .push_down_agg_type = _local_state->get_push_down_agg_type(),
599
41.3k
            .push_down_count_columns = std::move(push_down_count_columns),
600
41.3k
            .condition_cache_digest = _local_state->get_condition_cache_digest(),
601
41.3k
    }));
602
41.3k
    _table_reader_applied_rf_num = _applied_rf_num;
603
41.3k
    return Status::OK();
604
41.3k
}
605
606
Status FileScannerV2::_create_table_reader_for_format(
607
41.3k
        const TFileRangeDesc& range, std::unique_ptr<format::TableReader>* reader) const {
608
41.3k
    DORIS_CHECK(reader != nullptr);
609
41.3k
    const auto table_format = table_format_name(range);
610
41.3k
    if (table_format == "NotSet" || table_format == "tvf") {
611
4.02k
        *reader = std::make_unique<format::TableReader>();
612
37.3k
    } else if (table_format == "hive") {
613
18.6k
        *reader = format::hive::HiveReader::create_unique();
614
18.6k
    } else if (table_format == "iceberg") {
615
18.5k
        if (is_iceberg_position_deletes_sys_table(range)) {
616
0
            *reader = std::make_unique<format::iceberg::IcebergPositionDeleteSysTableV2Reader>();
617
18.5k
        } else if (get_range_format_type(*_params, range) == TFileFormatType::FORMAT_JNI) {
618
0
            *reader = std::make_unique<format::iceberg::IcebergSysTableJniReader>();
619
18.5k
        } else {
620
18.5k
            *reader = std::make_unique<format::iceberg::IcebergTableReader>();
621
18.5k
        }
622
18.5k
    } else if (table_format == "paimon") {
623
0
        *reader = std::make_unique<format::paimon::PaimonHybridReader>();
624
94
    } else if (table_format == "hudi") {
625
0
        *reader = std::make_unique<format::hudi::HudiHybridReader>();
626
94
    } else if (table_format == "jdbc") {
627
0
        *reader = std::make_unique<format::jdbc::JdbcJniReader>();
628
94
    } else if (table_format == "max_compute") {
629
0
        const auto* mc_desc =
630
0
                static_cast<const MaxComputeTableDescriptor*>(_output_tuple_desc->table_desc());
631
0
        RETURN_IF_ERROR(mc_desc->init_status());
632
0
        *reader = std::make_unique<format::max_compute::MaxComputeJniReader>(mc_desc);
633
94
    } else if (table_format == "trino_connector") {
634
0
        *reader = std::make_unique<format::trino_connector::TrinoConnectorJniReader>();
635
98
    } else if (table_format == "remote_doris") {
636
98
        *reader = std::make_unique<format::remote_doris::RemoteDorisReader>();
637
18.4E
    } else {
638
18.4E
        return Status::NotSupported("FileScannerV2 does not support table format {}", table_format);
639
18.4E
    }
640
41.3k
    return Status::OK();
641
41.3k
}
642
643
Status FileScannerV2::_prepare_table_reader_split(const TFileRangeDesc& range,
644
62.7k
                                                  std::map<std::string, Field> partition_values) {
645
62.7k
    format::FileFormat current_split_format;
646
62.7k
    RETURN_IF_ERROR(_to_file_format(get_range_format_type(*_params, range), &current_split_format));
647
62.7k
    VExprContextSPtrs partition_prune_conjuncts;
648
62.7k
    if (_state->query_options().enable_runtime_filter_partition_prune) {
649
61.1k
        RETURN_IF_ERROR(_build_table_conjuncts(&partition_prune_conjuncts));
650
61.1k
    }
651
62.7k
    RETURN_IF_ERROR(_table_reader->prepare_split({
652
62.7k
            .partition_values = std::move(partition_values),
653
62.7k
            .partition_prune_conjuncts = std::move(partition_prune_conjuncts),
654
            // A metadata COUNT split may span scheduler turns. Do not enter that irreversible
655
            // synthetic-row path while a runtime filter can still arrive between batches.
656
62.7k
            .all_runtime_filters_applied = _applied_rf_num == _total_rf_num,
657
62.7k
            .condition_cache_digest = _current_condition_cache_digest(),
658
62.7k
            .cache = _kv_cache,
659
62.7k
            .current_range = range,
660
62.7k
            .current_split_format = current_split_format,
661
62.7k
            .global_rowid_context = _create_global_rowid_context(range),
662
62.7k
    }));
663
62.7k
    return Status::OK();
664
62.7k
}
665
666
267k
bool FileScannerV2::_should_skip_not_found(const Status& status, bool ignore_not_found) {
667
267k
    return ignore_not_found && status.is<ErrorCode::NOT_FOUND>();
668
267k
}
669
670
267k
bool FileScannerV2::_should_skip_empty(const Status& status, bool stopped) {
671
    // Several readers use END_OF_FILE both for a valid zero-row split and for an interrupted IO.
672
    // For example, DeletionVectorReader returns END_OF_FILE("stop read.") after try_stop() marks
673
    // the shared IOContext. That status must unwind the stopped scanner; counting it as an empty
674
    // file would incorrectly finish the scan range and increment EmptyFileNum.
675
267k
    return !stopped && status.is<ErrorCode::END_OF_FILE>();
676
267k
}
677
678
7.48k
bool FileScannerV2::_should_enable_file_meta_cache() const {
679
7.48k
    return ExecEnv::GetInstance()->file_meta_cache()->enabled() &&
680
7.49k
           _split_source->num_scan_ranges() < config::max_external_file_meta_cache_num / 3;
681
7.48k
}
682
683
std::optional<format::GlobalRowIdContext> FileScannerV2::_create_global_rowid_context(
684
62.7k
        const TFileRangeDesc& range) const {
685
62.7k
    if (!_need_global_rowid_column) {
686
55.3k
        return std::nullopt;
687
55.3k
    }
688
7.41k
    auto& id_file_map = _state->get_id_file_map();
689
7.41k
    DORIS_CHECK(id_file_map != nullptr);
690
7.41k
    const auto file_id = id_file_map->get_file_mapping_id(
691
7.41k
            std::make_shared<FileMapping>(_local_state->cast<FileScanLocalState>().parent_id(),
692
7.41k
                                          range, _should_enable_file_meta_cache()));
693
7.41k
    return format::GlobalRowIdContext {
694
7.41k
            .version = IdManager::ID_VERSION,
695
7.41k
            .backend_id = BackendOptions::get_backend_id(),
696
7.41k
            .file_id = file_id,
697
7.41k
    };
698
62.7k
}
699
700
Status FileScannerV2::_generate_partition_values(
701
62.5k
        const TFileRangeDesc& range, std::map<std::string, Field>* partition_values) const {
702
62.5k
    DORIS_CHECK(partition_values != nullptr);
703
62.5k
    partition_values->clear();
704
62.5k
    if (!range.__isset.columns_from_path_keys || !range.__isset.columns_from_path) {
705
46.7k
        return Status::OK();
706
46.7k
    }
707
15.8k
    DORIS_CHECK(range.columns_from_path_keys.size() == range.columns_from_path.size());
708
43.3k
    for (size_t idx = 0; idx < range.columns_from_path_keys.size(); ++idx) {
709
27.4k
        const auto& key = range.columns_from_path_keys[idx];
710
27.4k
        const auto it = _partition_slot_descs.find(key);
711
27.4k
        if (it == _partition_slot_descs.end()) {
712
14.1k
            continue;
713
14.1k
        }
714
13.3k
        const auto& value = range.columns_from_path[idx];
715
13.3k
        const bool is_null = range.__isset.columns_from_path_is_null &&
716
13.4k
                             idx < range.columns_from_path_is_null.size() &&
717
13.4k
                             range.columns_from_path_is_null[idx];
718
13.3k
        Field field;
719
13.3k
        DORIS_CHECK(it->second.slot_desc != nullptr);
720
13.3k
        RETURN_IF_ERROR(_parse_partition_value(it->second.slot_desc, value, is_null, &field));
721
13.3k
        partition_values->emplace(it->second.canonical_name, std::move(field));
722
13.3k
    }
723
15.8k
    return Status::OK();
724
15.8k
}
725
726
Status FileScannerV2::_parse_partition_value(const SlotDescriptor* slot_desc,
727
                                             const std::string& value, bool is_null,
728
13.4k
                                             Field* field) const {
729
13.4k
    DORIS_CHECK(slot_desc != nullptr);
730
13.4k
    DORIS_CHECK(field != nullptr);
731
13.4k
    if (is_null) {
732
866
        *field = Field::create_field<TYPE_NULL>(Null());
733
866
        return Status::OK();
734
866
    }
735
12.5k
    const auto data_type = remove_nullable(slot_desc->get_data_type_ptr());
736
12.5k
    auto column = data_type->create_column();
737
12.5k
    auto serde = data_type->get_serde();
738
12.5k
    DataTypeSerDe::FormatOptions options;
739
12.5k
    options.converted_from_string = true;
740
12.5k
    StringRef ref(value.data(), value.size());
741
12.5k
    RETURN_IF_ERROR(serde->from_string(ref, *column, options));
742
12.5k
    DORIS_CHECK(column->size() == 1);
743
12.5k
    *field = (*column)[0];
744
12.5k
    return Status::OK();
745
12.5k
}
746
747
41.3k
Status FileScannerV2::_init_expr_ctxes() {
748
41.3k
    _slot_id_to_desc.clear();
749
41.3k
    _slot_id_to_global_index.clear();
750
41.3k
    _partition_slot_descs.clear();
751
41.3k
    _file_slot_descs.clear();
752
239k
    for (const auto* slot_desc : _output_tuple_desc->slots()) {
753
239k
        _slot_id_to_desc.emplace(slot_desc->id(), slot_desc);
754
239k
    }
755
41.3k
    DORIS_CHECK(_table_reader != nullptr);
756
41.3k
    RETURN_IF_ERROR(_build_projected_columns(*_table_reader));
757
41.3k
    return Status::OK();
758
41.3k
}
759
760
41.3k
Status FileScannerV2::_build_projected_columns(const format::TableReader& table_reader) {
761
41.3k
    _projected_columns.clear();
762
41.3k
    _projected_columns.reserve(_params->required_slots.size());
763
41.3k
    _need_global_rowid_column = false;
764
41.3k
    format::ProjectedColumnBuildContext build_context {
765
41.3k
            .scan_params = _params,
766
41.3k
            .range = &_current_range,
767
41.3k
            .runtime_state = _state,
768
41.3k
    };
769
    // Field 34 is the rollout boundary for root and nested exact-name precedence.
770
41.3k
    const bool prefer_exact_name_match =
771
41.3k
            !_params->__isset.history_schema_info || supports_iceberg_scan_semantics_v1(_params);
772
773
282k
    for (size_t slot_idx = 0; slot_idx < _params->required_slots.size(); ++slot_idx) {
774
241k
        const auto& slot_info = _params->required_slots[slot_idx];
775
241k
        const auto it = _slot_id_to_desc.find(slot_info.slot_id);
776
241k
        if (it == _slot_id_to_desc.end()) {
777
0
            return Status::InternalError("Unknown source slot descriptor, slot_id={}",
778
0
                                         slot_info.slot_id);
779
0
        }
780
241k
        auto column = _build_table_column(it->second);
781
241k
        if (column.name.starts_with(BeConsts::GLOBAL_ROWID_COL)) {
782
4.26k
            _need_global_rowid_column = true;
783
4.26k
        }
784
241k
        RETURN_IF_ERROR(_build_default_expr(slot_info, &column.default_expr));
785
241k
        build_context.schema_column.reset();
786
241k
        RETURN_IF_ERROR(table_reader.annotate_projected_column(slot_info, &build_context, &column));
787
        // Build nested children from access paths generated by the slot's access-path
788
        // expressions. A projected column can therefore contain only a subset of the schema
789
        // column's nested children.
790
241k
        RETURN_IF_ERROR(AccessPathParser::build_nested_children(
791
241k
                &column, it->second,
792
241k
                build_context.schema_column.has_value() ? &*build_context.schema_column : nullptr,
793
241k
                prefer_exact_name_match));
794
241k
        if (is_partition_slot(slot_info, column.name)) {
795
12.4k
            column.is_partition_key = true;
796
12.4k
            _partition_slot_descs.emplace(
797
12.4k
                    column.name,
798
12.4k
                    PartitionSlotInfo {.slot_desc = it->second, .canonical_name = column.name});
799
12.4k
            for (const auto& alias : column.name_mapping) {
800
0
                _partition_slot_descs.emplace(
801
0
                        alias,
802
0
                        PartitionSlotInfo {.slot_desc = it->second, .canonical_name = column.name});
803
0
            }
804
228k
        } else if (is_data_file_slot(slot_info, column.name)) {
805
223k
            _file_slot_descs.push_back(const_cast<SlotDescriptor*>(it->second));
806
223k
        }
807
241k
        const auto global_index = format::GlobalIndex(slot_idx);
808
241k
        _slot_id_to_global_index.emplace(slot_info.slot_id, global_index);
809
241k
        _projected_columns.push_back(std::move(column));
810
241k
    }
811
41.3k
    RETURN_IF_ERROR(table_reader.validate_projected_columns(build_context));
812
41.3k
    return Status::OK();
813
41.3k
}
814
815
Status FileScannerV2::_build_default_expr(const TFileScanSlotInfo& slot_info,
816
241k
                                          VExprContextSPtr* ctx) const {
817
241k
    DORIS_CHECK(ctx != nullptr);
818
241k
    if (slot_info.__isset.default_value_expr && !slot_info.default_value_expr.nodes.empty()) {
819
235k
        return VExpr::create_expr_tree(slot_info.default_value_expr, *ctx);
820
235k
    }
821
822
5.30k
    if (_params->__isset.default_value_of_src_slot) {
823
5.30k
        const auto it = _params->default_value_of_src_slot.find(slot_info.slot_id);
824
5.30k
        if (it != _params->default_value_of_src_slot.end() && !it->second.nodes.empty()) {
825
0
            return VExpr::create_expr_tree(it->second, *ctx);
826
0
        }
827
5.30k
    }
828
5.28k
    return Status::OK();
829
5.28k
}
830
831
241k
format::ColumnDefinition FileScannerV2::_build_table_column(const SlotDescriptor* slot_desc) {
832
241k
    DORIS_CHECK(slot_desc != nullptr);
833
241k
    format::ColumnDefinition column;
834
    // TODO(gabriel): why always BY_NAME here?
835
241k
    column.identifier = Field::create_field<TYPE_STRING>(slot_desc->col_name());
836
241k
    column.name = slot_desc->col_name();
837
241k
    column.type = slot_desc->get_data_type_ptr();
838
241k
    return column;
839
241k
}
840
841
102k
Status FileScannerV2::_build_table_conjuncts(VExprContextSPtrs* conjuncts) const {
842
102k
    return _build_table_conjuncts(_append_ordered_conjuncts, conjuncts);
843
102k
}
844
845
Status FileScannerV2::_build_table_conjuncts(const VExprContextSPtrs& source,
846
104k
                                             VExprContextSPtrs* conjuncts) const {
847
104k
    DORIS_CHECK(conjuncts != nullptr);
848
104k
    conjuncts->clear();
849
104k
    conjuncts->reserve(source.size());
850
104k
    for (const auto& conjunct : source) {
851
68.1k
        VExprSPtr root;
852
68.1k
        RETURN_IF_ERROR(format::clone_table_expr_tree(conjunct->root(), &root));
853
68.1k
        RETURN_IF_ERROR(rewrite_slot_refs_to_global_index(&root, _slot_id_to_global_index));
854
68.1k
        conjuncts->push_back(VExprContext::create_shared(std::move(root)));
855
68.1k
    }
856
104k
    return Status::OK();
857
104k
}
858
859
78.1k
size_t FileScannerV2::_safe_conjunct_prefix_size(const VExprContextSPtrs& conjuncts) {
860
112k
    for (size_t conjunct_index = 0; conjunct_index < conjuncts.size(); ++conjunct_index) {
861
42.0k
        if (!format::TableReader::is_safe_to_pre_execute(conjuncts[conjunct_index])) {
862
8.07k
            return conjunct_index;
863
8.07k
        }
864
42.0k
    }
865
70.0k
    return conjuncts.size();
866
78.1k
}
867
868
76.4k
void FileScannerV2::_initialize_scanner_residual_conjuncts() {
869
76.4k
    _append_ordered_conjuncts = _conjuncts;
870
76.4k
    _table_reader_owned_conjunct_count = _safe_conjunct_prefix_size(_conjuncts);
871
    // Preserve the entire suffix, not only the unsafe expression. Otherwise a later safe
872
    // predicate could run below Scanner before a stateful/error-preserving ordering barrier.
873
76.4k
    _scanner_residual_conjuncts.assign(
874
76.4k
            _conjuncts.begin() + cast_set<ptrdiff_t>(_table_reader_owned_conjunct_count),
875
76.4k
            _conjuncts.end());
876
76.4k
    _refresh_scanner_residual_profile();
877
76.4k
}
878
879
154k
void FileScannerV2::_refresh_scanner_residual_profile() {
880
154k
    if (_scanner_profile == nullptr || _scanner_residual_conjuncts.empty()) {
881
146k
        return;
882
146k
    }
883
7.88k
    std::ostringstream predicates;
884
7.88k
    predicates << "[";
885
17.9k
    for (size_t conjunct_index = 0; conjunct_index < _scanner_residual_conjuncts.size();
886
10.0k
         ++conjunct_index) {
887
10.0k
        if (conjunct_index > 0) {
888
1.86k
            predicates << ", ";
889
1.86k
        }
890
10.0k
        predicates << _scanner_residual_conjuncts[conjunct_index]->root()->debug_string();
891
10.0k
    }
892
7.88k
    predicates << "]";
893
7.88k
    _scanner_profile->add_info_string("ScannerResidualPredicates", predicates.str());
894
7.88k
}
895
896
279k
Status FileScannerV2::_sync_table_reader_conjuncts() {
897
279k
    if (_table_reader == nullptr) {
898
35.4k
        return Status::OK();
899
35.4k
    }
900
244k
    if (_table_reader_applied_rf_num == _applied_rf_num) {
901
242k
        return Status::OK();
902
242k
    }
903
1.52k
    VExprContextSPtrs appended;
904
1.52k
    RETURN_IF_ERROR(_build_table_conjuncts(_late_arrival_rf_conjuncts, &appended));
905
1.52k
    const size_t owned_count = _scanner_residual_conjuncts.empty()
906
1.75k
                                       ? _safe_conjunct_prefix_size(_late_arrival_rf_conjuncts)
907
18.4E
                                       : 0;
908
    // Preserve existing expression state and append the identity-tracked RF delta. Cost sorting
909
    // may move a late RF ahead of an old stateful predicate in the full scanner snapshot.
910
1.52k
    RETURN_IF_ERROR(_table_reader->append_conjuncts_with_ownership(appended, owned_count));
911
1.52k
    _append_ordered_conjuncts.insert(_append_ordered_conjuncts.end(),
912
1.52k
                                     _late_arrival_rf_conjuncts.begin(),
913
1.52k
                                     _late_arrival_rf_conjuncts.end());
914
1.52k
    _table_reader_owned_conjunct_count += owned_count;
915
1.52k
    _scanner_residual_conjuncts.insert(
916
1.52k
            _scanner_residual_conjuncts.end(),
917
1.52k
            _late_arrival_rf_conjuncts.begin() + cast_set<ptrdiff_t>(owned_count),
918
1.52k
            _late_arrival_rf_conjuncts.end());
919
1.52k
    _refresh_scanner_residual_profile();
920
1.52k
    _late_arrival_rf_conjuncts.clear();
921
1.52k
    _table_reader_applied_rf_num = _applied_rf_num;
922
1.52k
    return Status::OK();
923
1.52k
}
924
925
2
TFileFormatType::type FileScannerV2::_get_current_format_type() const {
926
2
    return get_range_format_type(*_params, _current_range);
927
2
}
928
929
Status FileScannerV2::_to_file_format(TFileFormatType::type format_type,
930
104k
                                      format::FileFormat* file_format) {
931
104k
    DORIS_CHECK(file_format != nullptr);
932
104k
    switch (format_type) {
933
55.5k
    case TFileFormatType::FORMAT_PARQUET:
934
55.5k
        *file_format = format::FileFormat::PARQUET;
935
55.5k
        return Status::OK();
936
38.5k
    case TFileFormatType::FORMAT_ORC:
937
38.5k
        *file_format = format::FileFormat::ORC;
938
38.5k
        return Status::OK();
939
1
    case TFileFormatType::FORMAT_JNI:
940
1
        *file_format = format::FileFormat::JNI;
941
1
        return Status::OK();
942
1.51k
    case TFileFormatType::FORMAT_CSV_PLAIN:
943
1.51k
    case TFileFormatType::FORMAT_CSV_GZ:
944
1.51k
    case TFileFormatType::FORMAT_CSV_BZ2:
945
1.51k
    case TFileFormatType::FORMAT_CSV_LZ4FRAME:
946
1.51k
    case TFileFormatType::FORMAT_CSV_LZ4BLOCK:
947
1.51k
    case TFileFormatType::FORMAT_CSV_LZOP:
948
1.51k
    case TFileFormatType::FORMAT_CSV_DEFLATE:
949
1.52k
    case TFileFormatType::FORMAT_CSV_SNAPPYBLOCK:
950
1.52k
    case TFileFormatType::FORMAT_PROTO:
951
1.52k
        *file_format = format::FileFormat::CSV;
952
1.52k
        return Status::OK();
953
7.08k
    case TFileFormatType::FORMAT_TEXT:
954
7.08k
        *file_format = format::FileFormat::TEXT;
955
7.08k
        return Status::OK();
956
1.17k
    case TFileFormatType::FORMAT_JSON:
957
1.17k
        *file_format = format::FileFormat::JSON;
958
1.17k
        return Status::OK();
959
1
    case TFileFormatType::FORMAT_NATIVE:
960
1
        *file_format = format::FileFormat::NATIVE;
961
1
        return Status::OK();
962
197
    case TFileFormatType::FORMAT_ARROW:
963
197
        *file_format = format::FileFormat::ARROW;
964
197
        return Status::OK();
965
0
    default:
966
0
        return Status::NotSupported("FileScannerV2 does not support file format {}",
967
0
                                    to_string(format_type));
968
104k
    }
969
104k
}
970
971
76.5k
Status FileScannerV2::_init_io_ctx() {
972
76.5k
    _io_ctx = create_file_scan_io_context(_state);
973
76.5k
    return Status::OK();
974
76.5k
}
975
976
62.5k
void FileScannerV2::_reset_adaptive_batch_size_state() {
977
62.5k
    _block_size_predictor.reset();
978
62.5k
    COUNTER_SET(_adaptive_batch_predicted_rows_counter, int64_t(0));
979
62.5k
    COUNTER_SET(_adaptive_batch_actual_bytes_counter, int64_t(0));
980
62.5k
}
981
982
62.6k
void FileScannerV2::_init_adaptive_batch_size_state(TFileFormatType::type format_type) {
983
62.6k
    _reset_adaptive_batch_size_state();
984
62.6k
    if (!_should_enable_adaptive_batch_size(format_type)) {
985
98
        return;
986
98
    }
987
988
    // V2 native file readers do not have reliable row-width hints before the first batch. Start
989
    // every split with a small probe, then learn bytes-per-row from the materialized table block
990
    // and keep later batches close to RuntimeState::preferred_block_size_bytes().
991
62.5k
    _block_size_predictor = std::make_unique<AdaptiveBlockSizePredictor>(
992
62.5k
            _state->preferred_block_size_bytes(), 0.0, ADAPTIVE_BATCH_INITIAL_PROBE_ROWS,
993
62.5k
            _state->batch_size());
994
62.5k
}
995
996
63.0k
bool FileScannerV2::_should_enable_adaptive_batch_size(TFileFormatType::type format_type) const {
997
63.0k
    if (!config::enable_adaptive_batch_size) {
998
0
        return false;
999
0
    }
1000
63.0k
    switch (format_type) {
1001
32.5k
    case TFileFormatType::FORMAT_PARQUET:
1002
56.5k
    case TFileFormatType::FORMAT_ORC:
1003
57.3k
    case TFileFormatType::FORMAT_CSV_PLAIN:
1004
57.3k
    case TFileFormatType::FORMAT_CSV_GZ:
1005
57.3k
    case TFileFormatType::FORMAT_CSV_BZ2:
1006
57.3k
    case TFileFormatType::FORMAT_CSV_LZ4FRAME:
1007
57.3k
    case TFileFormatType::FORMAT_CSV_LZ4BLOCK:
1008
57.3k
    case TFileFormatType::FORMAT_CSV_LZOP:
1009
57.3k
    case TFileFormatType::FORMAT_CSV_DEFLATE:
1010
57.3k
    case TFileFormatType::FORMAT_CSV_SNAPPYBLOCK:
1011
57.3k
    case TFileFormatType::FORMAT_PROTO:
1012
62.0k
    case TFileFormatType::FORMAT_TEXT:
1013
62.6k
    case TFileFormatType::FORMAT_JSON:
1014
62.6k
    case TFileFormatType::FORMAT_JNI:
1015
62.6k
        return true;
1016
98
    default:
1017
98
        return false;
1018
63.0k
    }
1019
63.0k
}
1020
1021
345k
bool FileScannerV2::_should_run_adaptive_batch_size() const {
1022
345k
    DORIS_CHECK(_table_reader != nullptr);
1023
345k
    return _should_run_adaptive_batch_size(_block_size_predictor != nullptr,
1024
345k
                                           _table_reader->current_split_uses_metadata_count());
1025
345k
}
1026
1027
bool FileScannerV2::_should_run_adaptive_batch_size(bool predictor_initialized,
1028
345k
                                                    bool current_split_uses_metadata_count) {
1029
    // Metadata COUNT emits synthetic rows and has no physical row width to learn from. A raw COUNT
1030
    // opcode is not sufficient here: unsupported argument counts, mappings, filters, or deletes
1031
    // make TableReader fall back to materializing normal rows, which still need adaptive batching.
1032
345k
    return predictor_initialized && !current_split_uses_metadata_count;
1033
345k
}
1034
1035
262k
size_t FileScannerV2::_predict_reader_batch_rows() {
1036
262k
    DORIS_CHECK(_block_size_predictor != nullptr);
1037
    // Before history exists this returns the probe row count; after update(), it returns roughly
1038
    // preferred_block_size_bytes / EWMA(bytes_per_row), capped by RuntimeState::batch_size().
1039
262k
    const size_t predicted_rows = _block_size_predictor->predict_next_rows();
1040
262k
    COUNTER_SET(_adaptive_batch_predicted_rows_counter, static_cast<int64_t>(predicted_rows));
1041
262k
    return predicted_rows;
1042
262k
}
1043
1044
142k
void FileScannerV2::_update_adaptive_batch_size(const Block& block) {
1045
142k
    if (!_should_run_adaptive_batch_size()) {
1046
3.18k
        return;
1047
3.18k
    }
1048
138k
    const auto& stats = _table_reader->last_materialized_block_stats();
1049
18.4E
    const size_t rows = stats.has_materialized_input ? stats.rows : block.rows();
1050
18.4E
    const size_t bytes = stats.has_materialized_input ? stats.bytes : block.bytes();
1051
138k
    COUNTER_SET(_adaptive_batch_actual_bytes_counter, static_cast<int64_t>(bytes));
1052
138k
    if (rows == 0) {
1053
0
        return;
1054
0
    }
1055
    // Residual predicates run after wide table columns are materialized. Learn from that pre-filter
1056
    // shape so selective predicates cannot make the next reader batch dangerously large.
1057
138k
    if (!_block_size_predictor->has_history()) {
1058
51.1k
        COUNTER_UPDATE(_adaptive_batch_probe_count_counter, 1);
1059
51.1k
    }
1060
138k
    _block_size_predictor->update(rows, bytes);
1061
138k
}
1062
1063
76.8k
Status FileScannerV2::close(RuntimeState* state) {
1064
76.8k
    SCOPED_TIMER(_scanner_total_timer);
1065
76.8k
    SCOPED_TIMER(_close_timer);
1066
76.8k
    if (!_try_close()) {
1067
1
        return Status::OK();
1068
1
    }
1069
76.8k
    if (_table_reader != nullptr) {
1070
41.3k
        const auto close_status = _table_reader->close();
1071
41.3k
        if (!close_status.ok()) {
1072
            // Reserve the close attempt with _try_close(), but commit the scanner-level closed
1073
            // state only after the retained table reader has completed its retryable cleanup.
1074
1
            _is_closed.store(false);
1075
1
            return close_status;
1076
1
        }
1077
41.3k
        _report_condition_cache_profile();
1078
41.3k
        _table_reader.reset();
1079
41.3k
    }
1080
76.8k
    return Scanner::close(state);
1081
76.8k
}
1082
1083
76.9k
void FileScannerV2::try_stop() {
1084
76.9k
    Scanner::try_stop();
1085
76.9k
    if (_io_ctx) {
1086
76.9k
        _io_ctx->should_stop = true;
1087
76.9k
    }
1088
76.9k
}
1089
1090
129k
void FileScannerV2::update_realtime_counters() {
1091
129k
    if (_file_reader_stats == nullptr) {
1092
0
        return;
1093
0
    }
1094
129k
    DORIS_CHECK(_file_cache_statistics != nullptr);
1095
129k
    const int64_t bytes_read = cast_set<int64_t>(_file_reader_stats->read_bytes);
1096
129k
    auto* local_state = static_cast<FileScanLocalState*>(_local_state);
1097
129k
    const auto file_type =
1098
129k
            _current_range.__isset.file_type
1099
129k
                    ? _current_range.file_type
1100
129k
                    : (_params != nullptr && _params->__isset.file_type ? _params->file_type
1101
36.3k
                                                                        : TFileType::FILE_LOCAL);
1102
129k
    const auto deltas = _collect_realtime_counter_deltas(
1103
129k
            *_file_reader_stats, *_file_cache_statistics, _uncached_reader_bytes_storage(file_type),
1104
129k
            &_last_read_bytes, &_last_read_rows, &_last_bytes_read_from_local,
1105
129k
            &_last_bytes_read_from_remote);
1106
1107
129k
    COUNTER_UPDATE(local_state->_scan_bytes, deltas.scan_bytes);
1108
129k
    COUNTER_UPDATE(local_state->_scan_rows, deltas.scan_rows);
1109
1110
129k
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_rows(deltas.scan_rows);
1111
129k
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes(deltas.scan_bytes);
1112
129k
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes_from_local_storage(
1113
129k
            deltas.scan_bytes_from_local_storage);
1114
129k
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes_from_remote_storage(
1115
129k
            deltas.scan_bytes_from_remote_storage);
1116
1117
129k
    COUNTER_SET(_file_read_bytes_counter, bytes_read);
1118
129k
    COUNTER_SET(_file_read_calls_counter, cast_set<int64_t>(_file_reader_stats->read_calls));
1119
129k
    COUNTER_SET(_file_read_time_counter, cast_set<int64_t>(_file_reader_stats->read_time_ns));
1120
1121
129k
    DorisMetrics::instance()->query_scan_bytes->increment(deltas.scan_bytes);
1122
129k
    DorisMetrics::instance()->query_scan_rows->increment(deltas.scan_rows);
1123
129k
    DorisMetrics::instance()->query_scan_bytes_from_local->increment(
1124
129k
            deltas.scan_bytes_from_local_storage);
1125
129k
    DorisMetrics::instance()->query_scan_bytes_from_remote->increment(
1126
129k
            deltas.scan_bytes_from_remote_storage);
1127
129k
}
1128
1129
FileScannerV2::RealtimeCounterDeltas FileScannerV2::_collect_realtime_counter_deltas(
1130
        const io::FileReaderStats& file_reader_stats,
1131
        const io::FileCacheStatistics& file_cache_statistics,
1132
        UncachedReaderBytesStorage uncached_reader_bytes_storage, int64_t* last_read_bytes,
1133
        int64_t* last_read_rows, int64_t* last_bytes_read_from_local,
1134
130k
        int64_t* last_bytes_read_from_remote) {
1135
130k
    DORIS_CHECK(last_read_bytes != nullptr);
1136
130k
    DORIS_CHECK(last_read_rows != nullptr);
1137
130k
    DORIS_CHECK(last_bytes_read_from_local != nullptr);
1138
130k
    DORIS_CHECK(last_bytes_read_from_remote != nullptr);
1139
1140
130k
    const int64_t read_bytes = cast_set<int64_t>(file_reader_stats.read_bytes);
1141
130k
    const int64_t read_rows = cast_set<int64_t>(file_reader_stats.read_rows);
1142
130k
    const int64_t bytes_read_from_local = file_cache_statistics.bytes_read_from_local;
1143
130k
    const int64_t bytes_read_from_remote = file_cache_statistics.bytes_read_from_remote;
1144
130k
    DORIS_CHECK(read_bytes >= *last_read_bytes);
1145
130k
    DORIS_CHECK(read_rows >= *last_read_rows);
1146
130k
    DORIS_CHECK(bytes_read_from_local >= *last_bytes_read_from_local);
1147
130k
    DORIS_CHECK(bytes_read_from_remote >= *last_bytes_read_from_remote);
1148
1149
130k
    RealtimeCounterDeltas deltas;
1150
130k
    deltas.scan_rows = read_rows - *last_read_rows;
1151
130k
    deltas.scan_bytes = read_bytes - *last_read_bytes;
1152
    // Peer cache is a known cache source, but it is not remote object storage.
1153
130k
    const bool has_cache_source_stats = file_cache_statistics.num_local_io_total != 0 ||
1154
130k
                                        file_cache_statistics.num_remote_io_total != 0 ||
1155
130k
                                        file_cache_statistics.num_peer_io_total != 0 ||
1156
130k
                                        bytes_read_from_local != 0 || bytes_read_from_remote != 0 ||
1157
130k
                                        file_cache_statistics.bytes_read_from_peer != 0;
1158
130k
    if (!has_cache_source_stats) {
1159
116k
        switch (uncached_reader_bytes_storage) {
1160
844
        case UncachedReaderBytesStorage::LOCAL:
1161
844
            deltas.scan_bytes_from_local_storage = deltas.scan_bytes;
1162
844
            break;
1163
115k
        case UncachedReaderBytesStorage::REMOTE:
1164
115k
            deltas.scan_bytes_from_remote_storage = deltas.scan_bytes;
1165
115k
            break;
1166
133
        case UncachedReaderBytesStorage::NONE:
1167
133
            break;
1168
116k
        }
1169
116k
    } else {
1170
13.2k
        deltas.scan_bytes_from_local_storage = bytes_read_from_local - *last_bytes_read_from_local;
1171
13.2k
        deltas.scan_bytes_from_remote_storage =
1172
13.2k
                bytes_read_from_remote - *last_bytes_read_from_remote;
1173
13.2k
    }
1174
1175
130k
    *last_read_bytes = read_bytes;
1176
130k
    *last_read_rows = read_rows;
1177
130k
    *last_bytes_read_from_local = bytes_read_from_local;
1178
130k
    *last_bytes_read_from_remote = bytes_read_from_remote;
1179
130k
    return deltas;
1180
130k
}
1181
1182
FileScannerV2::UncachedReaderBytesStorage FileScannerV2::_uncached_reader_bytes_storage(
1183
129k
        TFileType::type file_type) {
1184
129k
    switch (file_type) {
1185
843
    case TFileType::FILE_LOCAL:
1186
843
        return UncachedReaderBytesStorage::LOCAL;
1187
133
    case TFileType::FILE_STREAM:
1188
133
        return UncachedReaderBytesStorage::NONE;
1189
0
    case TFileType::FILE_BROKER:
1190
53.3k
    case TFileType::FILE_S3:
1191
128k
    case TFileType::FILE_HDFS:
1192
128k
    case TFileType::FILE_NET:
1193
128k
    case TFileType::FILE_HTTP:
1194
128k
        return UncachedReaderBytesStorage::REMOTE;
1195
129k
    }
1196
0
    DORIS_CHECK(false) << "unknown file type: " << file_type;
1197
0
    return UncachedReaderBytesStorage::NONE;
1198
129k
}
1199
1200
76.6k
void FileScannerV2::_collect_profile_before_close() {
1201
76.6k
    _report_file_reader_predicate_filtered_rows();
1202
76.6k
    Scanner::_collect_profile_before_close();
1203
76.6k
    if (config::enable_file_cache && _state->query_options().enable_file_cache &&
1204
76.6k
        _profile != nullptr) {
1205
186
        auto file_cache_delta = io::diff_file_cache_statistics(*_file_cache_statistics,
1206
186
                                                               _reported_file_cache_statistics);
1207
        // Profile collection can run more than once. Keep additive fields incremental while
1208
        // publishing high-water gauges and peer identities from the latest complete snapshot.
1209
186
        file_cache_delta.remote_only_on_miss_triggered =
1210
186
                _file_cache_statistics->remote_only_on_miss_triggered;
1211
186
        file_cache_delta.remote_only_on_miss_threshold_bytes =
1212
186
                _file_cache_statistics->remote_only_on_miss_threshold_bytes;
1213
186
        file_cache_delta.peer_hosts = _file_cache_statistics->peer_hosts;
1214
186
        _report_file_cache_profile(_profile, file_cache_delta);
1215
186
        _state->get_query_ctx()->resource_ctx()->io_context()->update_bytes_write_into_cache(
1216
186
                file_cache_delta.bytes_write_into_cache);
1217
186
        _reported_file_cache_statistics = *_file_cache_statistics;
1218
186
    }
1219
76.6k
    if (_file_reader_stats != nullptr) {
1220
76.6k
        COUNTER_SET(_file_read_bytes_counter, cast_set<int64_t>(_file_reader_stats->read_bytes));
1221
76.6k
        COUNTER_SET(_file_read_calls_counter, cast_set<int64_t>(_file_reader_stats->read_calls));
1222
76.6k
        COUNTER_SET(_file_read_time_counter, cast_set<int64_t>(_file_reader_stats->read_time_ns));
1223
76.6k
        const auto read_time = cast_set<int64_t>(_file_reader_stats->read_time_ns);
1224
76.6k
        DORIS_CHECK(read_time >= _reported_io_read_time);
1225
        // Some transports (for example Arrow Flight) record directly into IO, while filesystem
1226
        // reads arrive through FileReaderStats. Add only the new traced delta so both paths remain
1227
        // visible without double counting repeated profile publication.
1228
76.6k
        COUNTER_UPDATE(_io_timer, read_time - _reported_io_read_time);
1229
76.6k
        _reported_io_read_time = read_time;
1230
76.6k
    }
1231
    // Query profiles can be collected before Scanner::close() runs. Publish condition-cache
1232
    // counters here as well, using deltas so this method and close() cannot double count.
1233
76.6k
    _report_condition_cache_profile();
1234
76.6k
}
1235
1236
void FileScannerV2::_report_file_cache_profile(
1237
187
        RuntimeProfile* profile, const io::FileCacheStatistics& file_cache_statistics) {
1238
187
    file_scan_profile::ensure_hierarchy(profile);
1239
187
    io::FileCacheProfileReporter cache_profile(profile, file_scan_profile::IO);
1240
187
    cache_profile.update(&file_cache_statistics);
1241
187
}
1242
1243
76.7k
bool FileScannerV2::_should_update_load_counters() const {
1244
76.7k
    if (_is_load) {
1245
0
        return true;
1246
0
    }
1247
    // TVF based loads (e.g. http_stream, group commit relay) plan the load source as a
1248
    // tvf query scan without src tuple desc, so _is_load is false. But rows filtered by
1249
    // the load's WHERE clause still need to be reported as unselected rows. FILE_STREAM
1250
    // is only reachable from such load entries, never from normal queries, so use it to
1251
    // identify these scanners.
1252
76.7k
    return (_params != nullptr && _params->__isset.file_type &&
1253
76.7k
            _params->file_type == TFileType::FILE_STREAM) ||
1254
76.7k
           (_current_range.__isset.file_type && _current_range.file_type == TFileType::FILE_STREAM);
1255
76.7k
}
1256
1257
76.6k
void FileScannerV2::_report_file_reader_predicate_filtered_rows() {
1258
18.4E
    const int64_t filtered_rows = _io_ctx != nullptr ? _io_ctx->predicate_filtered_rows : 0;
1259
76.6k
    const int64_t filtered_delta = filtered_rows - _reported_predicate_filtered_rows;
1260
76.6k
    if (filtered_delta > 0) {
1261
        // FileReader and TableReader both report their owned predicate rows through the shared IO
1262
        // context. Preserve scanner-level load statistics without re-evaluating either predicate.
1263
2.09k
        _counter.num_rows_unselected += filtered_delta;
1264
2.09k
        _reported_predicate_filtered_rows = filtered_rows;
1265
2.09k
    }
1266
76.6k
}
1267
1268
118k
void FileScannerV2::_report_condition_cache_profile() {
1269
118k
    auto* local_state = static_cast<FileScanLocalState*>(_local_state);
1270
118k
    const int64_t hit_count =
1271
118k
            _table_reader != nullptr ? _table_reader->condition_cache_hit_count() : 0;
1272
118k
    const int64_t hit_delta = hit_count - _reported_condition_cache_hit_count;
1273
118k
    if (hit_delta > 0) {
1274
1.95k
        COUNTER_UPDATE(local_state->_condition_cache_hit_counter, hit_delta);
1275
1.95k
        _reported_condition_cache_hit_count = hit_count;
1276
1.95k
    }
1277
118k
    const int64_t filtered_rows = _io_ctx != nullptr ? _io_ctx->condition_cache_filtered_rows : 0;
1278
118k
    const int64_t filtered_delta = filtered_rows - _reported_condition_cache_filtered_rows;
1279
118k
    if (filtered_delta > 0) {
1280
116
        COUNTER_UPDATE(local_state->_condition_cache_filtered_rows_counter, filtered_delta);
1281
116
        _reported_condition_cache_filtered_rows = filtered_rows;
1282
116
    }
1283
118k
}
1284
1285
} // namespace doris