Coverage Report

Created: 2026-07-24 11:49

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