Coverage Report

Created: 2026-07-08 16:10

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 <string>
28
#include <utility>
29
30
#include "common/cast_set.h"
31
#include "common/config.h"
32
#include "common/consts.h"
33
#include "common/metrics/doris_metrics.h"
34
#include "common/status.h"
35
#include "core/assert_cast.h"
36
#include "core/block/column_with_type_and_name.h"
37
#include "core/column/column.h"
38
#include "core/data_type/data_type.h"
39
#include "core/data_type/data_type_nullable.h"
40
#include "core/data_type_serde/data_type_serde.h"
41
#include "core/string_ref.h"
42
#include "exec/common/util.hpp"
43
#include "exec/operator/scan_operator.h"
44
#include "exec/scan/access_path_parser.h"
45
#include "exprs/runtime_filter_expr.h"
46
#include "exprs/vexpr.h"
47
#include "exprs/vexpr_context.h"
48
#include "exprs/vslot_ref.h"
49
#include "format/format_common.h"
50
#include "format_v2/column_mapper.h"
51
#include "format_v2/jni/iceberg_sys_table_reader.h"
52
#include "format_v2/jni/jdbc_reader.h"
53
#include "format_v2/jni/max_compute_jni_reader.h"
54
#include "format_v2/jni/trino_connector_jni_reader.h"
55
#include "format_v2/table/hive_reader.h"
56
#include "format_v2/table/hudi_reader.h"
57
#include "format_v2/table/iceberg_reader.h"
58
#include "format_v2/table/paimon_reader.h"
59
#include "format_v2/table/remote_doris_reader.h"
60
#include "format_v2/table_reader.h"
61
#include "io/fs/file_meta_cache.h"
62
#include "io/io_common.h"
63
#include "runtime/descriptors.h"
64
#include "runtime/exec_env.h"
65
#include "runtime/runtime_state.h"
66
#include "service/backend_options.h"
67
#include "storage/id_manager.h"
68
69
namespace doris {
70
namespace {
71
72
973
std::string table_format_name(const TFileRangeDesc& range) {
73
973
    return range.__isset.table_format_params ? range.table_format_params.table_format_type
74
973
                                             : "NotSet";
75
973
}
76
77
TFileFormatType::type get_range_format_type(const TFileScanRangeParams& params,
78
2.01k
                                            const TFileRangeDesc& range) {
79
2.01k
    return range.__isset.format_type ? range.format_type : params.format_type;
80
2.01k
}
81
82
498
bool is_supported_table_format(const TFileRangeDesc& range) {
83
498
    const auto table_format = table_format_name(range);
84
498
    if (table_format == "hudi" && range.__isset.table_format_params &&
85
498
        range.table_format_params.__isset.hudi_params &&
86
498
        range.table_format_params.hudi_params.__isset.delta_logs &&
87
498
        !range.table_format_params.hudi_params.delta_logs.empty()) {
88
        // Hudi MOR splits need log-file merge semantics and must stay on the existing JNI path.
89
        // FileScannerV2 currently supports native Parquet data files only.
90
1
        return false;
91
1
    }
92
497
    return table_format == "NotSet" || table_format == "tvf" || table_format == "hive" ||
93
497
           table_format == "iceberg" || table_format == "paimon" || table_format == "hudi";
94
498
}
95
96
3
bool is_supported_arrow_table_format(const TFileRangeDesc& range) {
97
3
    return table_format_name(range) == "remote_doris";
98
3
}
99
100
5
bool is_supported_jni_table_format(const TFileRangeDesc& range) {
101
5
    const auto table_format = table_format_name(range);
102
5
    if (table_format == "paimon") {
103
0
        return range.__isset.table_format_params &&
104
0
               range.table_format_params.__isset.paimon_params &&
105
0
               range.table_format_params.paimon_params.__isset.reader_type &&
106
0
               range.table_format_params.paimon_params.reader_type == TPaimonReaderType::PAIMON_JNI;
107
0
    }
108
5
    return table_format == "jdbc" || table_format == "iceberg" || table_format == "hudi" ||
109
5
           table_format == "max_compute" || table_format == "trino_connector";
110
5
}
111
112
473
bool is_csv_format(TFileFormatType::type format_type) {
113
473
    switch (format_type) {
114
339
    case TFileFormatType::FORMAT_CSV_PLAIN:
115
340
    case TFileFormatType::FORMAT_CSV_GZ:
116
341
    case TFileFormatType::FORMAT_CSV_BZ2:
117
342
    case TFileFormatType::FORMAT_CSV_LZ4FRAME:
118
343
    case TFileFormatType::FORMAT_CSV_LZ4BLOCK:
119
344
    case TFileFormatType::FORMAT_CSV_LZOP:
120
345
    case TFileFormatType::FORMAT_CSV_DEFLATE:
121
346
    case TFileFormatType::FORMAT_CSV_SNAPPYBLOCK:
122
347
    case TFileFormatType::FORMAT_PROTO:
123
347
        return true;
124
126
    default:
125
126
        return false;
126
473
    }
127
473
}
128
129
126
bool is_text_format(TFileFormatType::type format_type) {
130
126
    return format_type == TFileFormatType::FORMAT_TEXT;
131
126
}
132
133
124
bool is_json_format(TFileFormatType::type format_type) {
134
124
    return format_type == TFileFormatType::FORMAT_JSON;
135
124
}
136
137
104
bool is_native_format(TFileFormatType::type format_type) {
138
104
    return format_type == TFileFormatType::FORMAT_NATIVE;
139
104
}
140
141
3.07k
bool is_partition_slot(const TFileScanSlotInfo& slot_info, const std::string& column_name) {
142
3.07k
    if (column_name.starts_with(BeConsts::GLOBAL_ROWID_COL) ||
143
3.07k
        column_name == BeConsts::ICEBERG_ROWID_COL) {
144
11
        return false;
145
11
    }
146
3.05k
    return slot_info.__isset.category ? slot_info.category == TColumnCategory::PARTITION_KEY
147
3.05k
                                      : !slot_info.is_file_slot;
148
3.07k
}
149
150
3.07k
bool is_data_file_slot(const TFileScanSlotInfo& slot_info, const std::string& column_name) {
151
3.07k
    if (column_name.starts_with(BeConsts::GLOBAL_ROWID_COL) ||
152
3.07k
        column_name == BeConsts::ICEBERG_ROWID_COL) {
153
11
        return false;
154
11
    }
155
    // CSV and other non-self-describing formats need FE slot descriptors for only the columns that
156
    // are physically read from the file. Partition/default/virtual columns stay in TableReader's
157
    // mapping layer and are materialized after the file-local block is read. New FE provides an
158
    // explicit category; old FE falls back to `is_file_slot`.
159
3.06k
    if (slot_info.__isset.category) {
160
3.05k
        return slot_info.category == TColumnCategory::REGULAR ||
161
3.05k
               slot_info.category == TColumnCategory::GENERATED;
162
3.05k
    }
163
2
    return slot_info.is_file_slot;
164
3.06k
}
165
166
Status rewrite_slot_refs_to_global_index(
167
        VExprSPtr* expr,
168
29
        const std::unordered_map<int32_t, format::GlobalIndex>& slot_id_to_global_index) {
169
29
    DORIS_CHECK(expr != nullptr);
170
29
    if (*expr == nullptr) {
171
0
        return Status::OK();
172
0
    }
173
29
    if (auto* runtime_filter = dynamic_cast<RuntimeFilterExpr*>(expr->get());
174
29
        runtime_filter != nullptr) {
175
1
        auto impl = runtime_filter->get_impl();
176
1
        DORIS_CHECK(impl != nullptr);
177
1
        RETURN_IF_ERROR(rewrite_slot_refs_to_global_index(&impl, slot_id_to_global_index));
178
1
        runtime_filter->set_impl(std::move(impl));
179
1
        return Status::OK();
180
1
    }
181
28
    if ((*expr)->is_slot_ref()) {
182
13
        const auto* slot_ref = assert_cast<const VSlotRef*>(expr->get());
183
13
        const auto global_index_it = slot_id_to_global_index.find(slot_ref->slot_id());
184
13
        if (global_index_it == slot_id_to_global_index.end()) {
185
1
            DORIS_CHECK(slot_ref->slot_id() >= 0);
186
1
            const auto global_index = format::GlobalIndex(cast_set<size_t>(slot_ref->slot_id()));
187
1
            *expr = VSlotRef::create_shared(cast_set<int>(global_index.value()),
188
1
                                            cast_set<int>(global_index.value()), -1,
189
1
                                            slot_ref->data_type(), slot_ref->column_name());
190
1
            RETURN_IF_ERROR(expr->get()->prepare(nullptr, RowDescriptor(), nullptr));
191
1
            return Status::OK();
192
1
        }
193
12
        const auto global_index = global_index_it->second;
194
12
        *expr = VSlotRef::create_shared(cast_set<int>(global_index.value()),
195
12
                                        cast_set<int>(global_index.value()), -1,
196
12
                                        slot_ref->data_type(), slot_ref->column_name());
197
12
        RETURN_IF_ERROR(expr->get()->prepare(nullptr, RowDescriptor(), nullptr));
198
12
        return Status::OK();
199
12
    }
200
15
    auto children = (*expr)->children();
201
15
    for (auto& child : children) {
202
15
        if (child == nullptr) {
203
0
            continue;
204
0
        }
205
15
        RETURN_IF_ERROR(rewrite_slot_refs_to_global_index(&child, slot_id_to_global_index));
206
15
    }
207
15
    (*expr)->set_children(std::move(children));
208
15
    return Status::OK();
209
15
}
210
211
} // namespace
212
213
#ifdef BE_TEST
214
Status FileScannerV2::TEST_to_file_format(TFileFormatType::type format_type,
215
                                          format::FileFormat* file_format) {
216
    return _to_file_format(format_type, file_format);
217
}
218
219
bool FileScannerV2::TEST_is_partition_slot(const TFileScanSlotInfo& slot_info,
220
                                           const std::string& column_name) {
221
    return is_partition_slot(slot_info, column_name);
222
}
223
224
bool FileScannerV2::TEST_is_data_file_slot(const TFileScanSlotInfo& slot_info,
225
                                           const std::string& column_name) {
226
    return is_data_file_slot(slot_info, column_name);
227
}
228
229
Status FileScannerV2::TEST_rewrite_slot_refs_to_global_index(
230
        VExprSPtr* expr,
231
        const std::unordered_map<int32_t, format::GlobalIndex>& slot_id_to_global_index) {
232
    return rewrite_slot_refs_to_global_index(expr, slot_id_to_global_index);
233
}
234
235
FileScannerV2::RealtimeCounterDeltas FileScannerV2::TEST_collect_realtime_counter_deltas(
236
        const io::FileReaderStats& file_reader_stats,
237
        const io::FileCacheStatistics& file_cache_statistics,
238
        UncachedReaderBytesStorage uncached_reader_bytes_storage, int64_t* last_read_bytes,
239
        int64_t* last_read_rows, int64_t* last_bytes_read_from_local,
240
        int64_t* last_bytes_read_from_remote) {
241
    return _collect_realtime_counter_deltas(file_reader_stats, file_cache_statistics,
242
                                            uncached_reader_bytes_storage, last_read_bytes,
243
                                            last_read_rows, last_bytes_read_from_local,
244
                                            last_bytes_read_from_remote);
245
}
246
#endif
247
248
607
bool FileScannerV2::is_supported(const TFileScanRangeParams& params, const TFileRangeDesc& range) {
249
607
    const auto format_type = get_range_format_type(params, range);
250
607
    if (format_type == TFileFormatType::FORMAT_PARQUET) {
251
126
        return is_supported_table_format(range);
252
481
    } else if (format_type == TFileFormatType::FORMAT_ARROW) {
253
3
        return is_supported_arrow_table_format(range);
254
478
    } else if (format_type == TFileFormatType::FORMAT_JNI) {
255
5
        return is_supported_jni_table_format(range);
256
473
    } else if (is_csv_format(format_type) || is_text_format(format_type) ||
257
473
               is_json_format(format_type) || is_native_format(format_type)) {
258
372
        return is_supported_table_format(range);
259
372
    } else {
260
101
        LOG(WARNING) << "Unsupported file format type " << format_type << " for file scanner v2";
261
101
        return false;
262
101
    }
263
607
}
264
265
FileScannerV2::FileScannerV2(RuntimeState* state, FileScanLocalState* local_state, int64_t limit,
266
                             std::shared_ptr<SplitSourceConnector> split_source,
267
                             RuntimeProfile* profile, ShardedKVCache* kv_cache,
268
                             const std::unordered_map<std::string, int>* colname_to_slot_id)
269
469
        : Scanner(state, local_state, limit, profile),
270
469
          _split_source(std::move(split_source)),
271
469
          _kv_cache(kv_cache) {
272
469
    (void)colname_to_slot_id;
273
469
    if (state->get_query_ctx() != nullptr &&
274
469
        state->get_query_ctx()->file_scan_range_params_map.count(local_state->parent_id()) > 0) {
275
469
        _params = &(state->get_query_ctx()->file_scan_range_params_map[local_state->parent_id()]);
276
469
    } else {
277
0
        _params = _split_source->get_params();
278
0
    }
279
469
}
280
281
469
Status FileScannerV2::init(RuntimeState* state, const VExprContextSPtrs& conjuncts) {
282
469
    RETURN_IF_ERROR(Scanner::init(state, conjuncts));
283
469
    _get_block_timer =
284
469
            ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), "FileScannerV2GetBlockTime", 1);
285
469
    _file_counter =
286
469
            ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), "FileNumber", TUnit::UNIT, 1);
287
469
    _file_read_bytes_counter = ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(),
288
469
                                                      "FileReadBytes", TUnit::BYTES, 1);
289
469
    _file_read_calls_counter = ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(),
290
469
                                                      "FileReadCalls", TUnit::UNIT, 1);
291
469
    _file_read_time_counter =
292
469
            ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), "FileReadTime", 1);
293
469
    _adaptive_batch_predicted_rows_counter = ADD_COUNTER_WITH_LEVEL(
294
469
            _local_state->scanner_profile(), "AdaptiveBatchPredictedRows", TUnit::UNIT, 1);
295
469
    _adaptive_batch_actual_bytes_counter = ADD_COUNTER_WITH_LEVEL(
296
469
            _local_state->scanner_profile(), "AdaptiveBatchActualBytes", TUnit::BYTES, 1);
297
469
    _adaptive_batch_probe_count_counter = ADD_COUNTER_WITH_LEVEL(
298
469
            _local_state->scanner_profile(), "AdaptiveBatchProbeCount", TUnit::UNIT, 1);
299
469
    _file_cache_statistics = std::make_unique<io::FileCacheStatistics>();
300
469
    _file_reader_stats = std::make_unique<io::FileReaderStats>();
301
469
    RETURN_IF_ERROR(_init_io_ctx());
302
469
    _io_ctx->file_cache_stats = _file_cache_statistics.get();
303
469
    _io_ctx->file_reader_stats = _file_reader_stats.get();
304
469
    _io_ctx->is_disposable = _state->query_options().disable_file_cache;
305
469
    return Status::OK();
306
469
}
307
308
469
Status FileScannerV2::_open_impl(RuntimeState* state) {
309
469
    RETURN_IF_CANCELLED(state);
310
469
    RETURN_IF_ERROR(Scanner::_open_impl(state));
311
469
    RETURN_IF_ERROR(_split_source->get_next(&_first_scan_range, &_current_range));
312
469
    if (_first_scan_range) {
313
467
        RETURN_IF_ERROR(_create_table_reader_for_format(_current_range, &_table_reader));
314
467
        DORIS_CHECK(_table_reader != nullptr);
315
467
        RETURN_IF_ERROR(_init_expr_ctxes());
316
467
        RETURN_IF_ERROR(_init_table_reader(_current_range));
317
467
    }
318
469
    return Status::OK();
319
469
}
320
321
1.12k
Status FileScannerV2::_get_block_impl(RuntimeState* state, Block* block, bool* eof) {
322
1.59k
    while (true) {
323
1.59k
        RETURN_IF_CANCELLED(state);
324
1.59k
        if (!_has_prepared_split) {
325
937
            RETURN_IF_ERROR(_prepare_next_split(eof));
326
937
            if (*eof) {
327
469
                return Status::OK();
328
469
            }
329
937
        }
330
331
1.12k
        {
332
1.12k
            SCOPED_TIMER(_get_block_timer);
333
1.12k
            if (_should_run_adaptive_batch_size()) {
334
1.11k
                _table_reader->set_batch_size(_predict_reader_batch_rows());
335
1.11k
            }
336
1.12k
            RETURN_IF_ERROR(_table_reader->get_block(block, eof));
337
1.12k
        }
338
1.12k
        if (*eof) {
339
469
            _state->update_num_finished_scan_range(1);
340
469
            _has_prepared_split = false;
341
469
            *eof = false;
342
469
            continue;
343
469
        }
344
656
        _update_adaptive_batch_size(*block);
345
656
        return Status::OK();
346
1.12k
    }
347
1.12k
}
348
349
937
Status FileScannerV2::_prepare_next_split(bool* eos) {
350
937
    bool has_next = _first_scan_range;
351
937
    if (!_first_scan_range) {
352
471
        RETURN_IF_ERROR(_split_source->get_next(&has_next, &_current_range));
353
471
    }
354
937
    _first_scan_range = false;
355
937
    if (!has_next || _should_stop) {
356
469
        *eos = true;
357
469
        return Status::OK();
358
469
    }
359
468
    DORIS_CHECK(_table_reader != nullptr);
360
468
    _current_range_path = _current_range.path;
361
468
    _init_adaptive_batch_size_state(get_range_format_type(*_params, _current_range));
362
468
    RETURN_IF_ERROR(_prepare_table_reader_split(_current_range));
363
468
    COUNTER_UPDATE(_file_counter, 1);
364
468
    _has_prepared_split = true;
365
468
    *eos = false;
366
468
    return Status::OK();
367
468
}
368
369
467
Status FileScannerV2::_init_table_reader(const TFileRangeDesc& range) {
370
467
    const auto format_type = get_range_format_type(*_params, range);
371
467
    format::FileFormat file_format;
372
467
    RETURN_IF_ERROR(_to_file_format(format_type, &file_format));
373
467
    DORIS_CHECK(_table_reader != nullptr);
374
375
467
    VExprContextSPtrs table_conjuncts;
376
467
    RETURN_IF_ERROR(_build_table_conjuncts(&table_conjuncts));
377
467
    RETURN_IF_ERROR(_table_reader->init({
378
467
            .projected_columns = _projected_columns,
379
467
            .conjuncts = std::move(table_conjuncts),
380
467
            .format = file_format,
381
467
            .scan_params = const_cast<TFileScanRangeParams*>(_params),
382
467
            .io_ctx = _io_ctx,
383
467
            .runtime_state = _state,
384
467
            .scanner_profile = _local_state->scanner_profile(),
385
467
            .file_slot_descs = &_file_slot_descs,
386
467
            .push_down_agg_type = _local_state->get_push_down_agg_type(),
387
467
            .condition_cache_digest = _local_state->get_condition_cache_digest(),
388
467
    }));
389
467
    return Status::OK();
390
467
}
391
392
Status FileScannerV2::_create_table_reader_for_format(
393
467
        const TFileRangeDesc& range, std::unique_ptr<format::TableReader>* reader) const {
394
467
    DORIS_CHECK(reader != nullptr);
395
467
    const auto table_format = table_format_name(range);
396
467
    if (table_format == "NotSet" || table_format == "tvf") {
397
465
        *reader = std::make_unique<format::TableReader>();
398
465
    } else if (table_format == "hive") {
399
0
        *reader = format::hive::HiveReader::create_unique();
400
2
    } else if (table_format == "iceberg") {
401
0
        if (get_range_format_type(*_params, range) == TFileFormatType::FORMAT_JNI) {
402
0
            *reader = std::make_unique<format::iceberg::IcebergSysTableJniReader>();
403
0
        } else {
404
0
            *reader = std::make_unique<format::iceberg::IcebergTableReader>();
405
0
        }
406
2
    } else if (table_format == "paimon") {
407
0
        *reader = std::make_unique<format::paimon::PaimonHybridReader>();
408
2
    } else if (table_format == "hudi") {
409
0
        *reader = std::make_unique<format::hudi::HudiHybridReader>();
410
2
    } else if (table_format == "jdbc") {
411
2
        *reader = std::make_unique<format::jdbc::JdbcJniReader>();
412
2
    } else if (table_format == "max_compute") {
413
0
        const auto* mc_desc =
414
0
                static_cast<const MaxComputeTableDescriptor*>(_output_tuple_desc->table_desc());
415
0
        RETURN_IF_ERROR(mc_desc->init_status());
416
0
        *reader = std::make_unique<format::max_compute::MaxComputeJniReader>(mc_desc);
417
0
    } else if (table_format == "trino_connector") {
418
0
        *reader = std::make_unique<format::trino_connector::TrinoConnectorJniReader>();
419
0
    } else if (table_format == "remote_doris") {
420
0
        *reader = std::make_unique<format::remote_doris::RemoteDorisReader>();
421
0
    } else {
422
0
        return Status::NotSupported("FileScannerV2 does not support table format {}", table_format);
423
0
    }
424
467
    return Status::OK();
425
467
}
426
427
469
Status FileScannerV2::_prepare_table_reader_split(const TFileRangeDesc& range) {
428
469
    std::map<std::string, Field> partition_values;
429
469
    RETURN_IF_ERROR(_generate_partition_values(range, &partition_values));
430
469
    format::FileFormat current_split_format;
431
469
    RETURN_IF_ERROR(_to_file_format(get_range_format_type(*_params, range), &current_split_format));
432
469
    RETURN_IF_ERROR(_table_reader->prepare_split({
433
469
            .partition_values = std::move(partition_values),
434
469
            .cache = _kv_cache,
435
469
            .current_range = range,
436
469
            .current_split_format = current_split_format,
437
469
            .global_rowid_context = _create_global_rowid_context(range),
438
469
    }));
439
469
    return Status::OK();
440
469
}
441
442
9
bool FileScannerV2::_should_enable_file_meta_cache() const {
443
9
    return ExecEnv::GetInstance()->file_meta_cache()->enabled() &&
444
9
           _split_source->num_scan_ranges() < config::max_external_file_meta_cache_num / 3;
445
9
}
446
447
std::optional<format::GlobalRowIdContext> FileScannerV2::_create_global_rowid_context(
448
468
        const TFileRangeDesc& range) const {
449
468
    if (!_need_global_rowid_column) {
450
459
        return std::nullopt;
451
459
    }
452
9
    auto& id_file_map = _state->get_id_file_map();
453
9
    DORIS_CHECK(id_file_map != nullptr);
454
9
    const auto file_id = id_file_map->get_file_mapping_id(
455
9
            std::make_shared<FileMapping>(_local_state->cast<FileScanLocalState>().parent_id(),
456
9
                                          range, _should_enable_file_meta_cache()));
457
9
    return format::GlobalRowIdContext {
458
9
            .version = IdManager::ID_VERSION,
459
9
            .backend_id = BackendOptions::get_backend_id(),
460
9
            .file_id = file_id,
461
9
    };
462
468
}
463
464
Status FileScannerV2::_generate_partition_values(
465
469
        const TFileRangeDesc& range, std::map<std::string, Field>* partition_values) const {
466
469
    DORIS_CHECK(partition_values != nullptr);
467
469
    partition_values->clear();
468
469
    if (!range.__isset.columns_from_path_keys || !range.__isset.columns_from_path) {
469
469
        return Status::OK();
470
469
    }
471
0
    DORIS_CHECK(range.columns_from_path_keys.size() == range.columns_from_path.size());
472
0
    for (size_t idx = 0; idx < range.columns_from_path_keys.size(); ++idx) {
473
0
        const auto& key = range.columns_from_path_keys[idx];
474
0
        const auto it = _partition_slot_descs.find(key);
475
0
        if (it == _partition_slot_descs.end()) {
476
0
            continue;
477
0
        }
478
0
        const auto& value = range.columns_from_path[idx];
479
0
        const bool is_null = range.__isset.columns_from_path_is_null &&
480
0
                             idx < range.columns_from_path_is_null.size() &&
481
0
                             range.columns_from_path_is_null[idx];
482
0
        Field field;
483
0
        DORIS_CHECK(it->second.slot_desc != nullptr);
484
0
        RETURN_IF_ERROR(_parse_partition_value(it->second.slot_desc, value, is_null, &field));
485
0
        partition_values->emplace(it->second.canonical_name, std::move(field));
486
0
    }
487
0
    return Status::OK();
488
0
}
489
490
Status FileScannerV2::_parse_partition_value(const SlotDescriptor* slot_desc,
491
                                             const std::string& value, bool is_null,
492
0
                                             Field* field) const {
493
0
    DORIS_CHECK(slot_desc != nullptr);
494
0
    DORIS_CHECK(field != nullptr);
495
0
    if (is_null) {
496
0
        *field = Field::create_field<TYPE_NULL>(Null());
497
0
        return Status::OK();
498
0
    }
499
0
    const auto data_type = remove_nullable(slot_desc->get_data_type_ptr());
500
0
    auto column = data_type->create_column();
501
0
    auto serde = data_type->get_serde();
502
0
    DataTypeSerDe::FormatOptions options;
503
0
    options.converted_from_string = true;
504
0
    StringRef ref(value.data(), value.size());
505
0
    RETURN_IF_ERROR(serde->from_string(ref, *column, options));
506
0
    DORIS_CHECK(column->size() == 1);
507
0
    *field = (*column)[0];
508
0
    return Status::OK();
509
0
}
510
511
467
Status FileScannerV2::_init_expr_ctxes() {
512
467
    _slot_id_to_desc.clear();
513
467
    _slot_id_to_global_index.clear();
514
467
    _partition_slot_descs.clear();
515
467
    _file_slot_descs.clear();
516
3.06k
    for (const auto* slot_desc : _output_tuple_desc->slots()) {
517
3.06k
        _slot_id_to_desc.emplace(slot_desc->id(), slot_desc);
518
3.06k
    }
519
467
    DORIS_CHECK(_table_reader != nullptr);
520
467
    RETURN_IF_ERROR(_build_projected_columns(*_table_reader));
521
467
    return Status::OK();
522
467
}
523
524
467
Status FileScannerV2::_build_projected_columns(const format::TableReader& table_reader) {
525
467
    _projected_columns.clear();
526
467
    _projected_columns.reserve(_params->required_slots.size());
527
467
    _need_global_rowid_column = false;
528
467
    format::ProjectedColumnBuildContext build_context {
529
467
            .scan_params = _params,
530
467
            .range = &_current_range,
531
467
            .runtime_state = _state,
532
467
    };
533
534
3.53k
    for (size_t slot_idx = 0; slot_idx < _params->required_slots.size(); ++slot_idx) {
535
3.06k
        const auto& slot_info = _params->required_slots[slot_idx];
536
3.06k
        const auto it = _slot_id_to_desc.find(slot_info.slot_id);
537
3.06k
        if (it == _slot_id_to_desc.end()) {
538
0
            return Status::InternalError("Unknown source slot descriptor, slot_id={}",
539
0
                                         slot_info.slot_id);
540
0
        }
541
3.06k
        auto column = _build_table_column(it->second);
542
3.06k
        if (column.name.starts_with(BeConsts::GLOBAL_ROWID_COL)) {
543
9
            _need_global_rowid_column = true;
544
9
        }
545
3.06k
        RETURN_IF_ERROR(_build_default_expr(slot_info, &column.default_expr));
546
3.06k
        build_context.schema_column.reset();
547
3.06k
        RETURN_IF_ERROR(table_reader.annotate_projected_column(slot_info, &build_context, &column));
548
        // Build nested children from access paths generated by the slot's access-path
549
        // expressions. A projected column can therefore contain only a subset of the schema
550
        // column's nested children.
551
3.06k
        RETURN_IF_ERROR(AccessPathParser::build_nested_children(
552
3.06k
                &column, it->second,
553
3.06k
                build_context.schema_column.has_value() ? &*build_context.schema_column : nullptr));
554
3.06k
        if (is_partition_slot(slot_info, column.name)) {
555
0
            column.is_partition_key = true;
556
0
            _partition_slot_descs.emplace(
557
0
                    column.name,
558
0
                    PartitionSlotInfo {.slot_desc = it->second, .canonical_name = column.name});
559
0
            for (const auto& alias : column.name_mapping) {
560
0
                _partition_slot_descs.emplace(
561
0
                        alias,
562
0
                        PartitionSlotInfo {.slot_desc = it->second, .canonical_name = column.name});
563
0
            }
564
3.06k
        } else if (is_data_file_slot(slot_info, column.name)) {
565
3.05k
            _file_slot_descs.push_back(const_cast<SlotDescriptor*>(it->second));
566
3.05k
        }
567
3.06k
        const auto global_index = format::GlobalIndex(slot_idx);
568
3.06k
        _slot_id_to_global_index.emplace(slot_info.slot_id, global_index);
569
3.06k
        _projected_columns.push_back(std::move(column));
570
3.06k
    }
571
467
    RETURN_IF_ERROR(table_reader.validate_projected_columns(build_context));
572
467
    return Status::OK();
573
467
}
574
575
Status FileScannerV2::_build_default_expr(const TFileScanSlotInfo& slot_info,
576
3.06k
                                          VExprContextSPtr* ctx) const {
577
3.06k
    DORIS_CHECK(ctx != nullptr);
578
3.06k
    if (slot_info.__isset.default_value_expr && !slot_info.default_value_expr.nodes.empty()) {
579
3.05k
        return VExpr::create_expr_tree(slot_info.default_value_expr, *ctx);
580
3.05k
    }
581
582
10
    if (_params->__isset.default_value_of_src_slot) {
583
10
        const auto it = _params->default_value_of_src_slot.find(slot_info.slot_id);
584
10
        if (it != _params->default_value_of_src_slot.end() && !it->second.nodes.empty()) {
585
0
            return VExpr::create_expr_tree(it->second, *ctx);
586
0
        }
587
10
    }
588
10
    return Status::OK();
589
10
}
590
591
3.06k
format::ColumnDefinition FileScannerV2::_build_table_column(const SlotDescriptor* slot_desc) {
592
3.06k
    DORIS_CHECK(slot_desc != nullptr);
593
3.06k
    format::ColumnDefinition column;
594
    // TODO(gabriel): why always BY_NAME here?
595
3.06k
    column.identifier = Field::create_field<TYPE_STRING>(slot_desc->col_name());
596
3.06k
    column.name = slot_desc->col_name();
597
3.06k
    column.type = slot_desc->get_data_type_ptr();
598
3.06k
    return column;
599
3.06k
}
600
601
467
Status FileScannerV2::_build_table_conjuncts(VExprContextSPtrs* conjuncts) const {
602
467
    DORIS_CHECK(conjuncts != nullptr);
603
467
    conjuncts->clear();
604
467
    conjuncts->reserve(_conjuncts.size());
605
467
    for (const auto& conjunct : _conjuncts) {
606
9
        VExprSPtr root;
607
9
        RETURN_IF_ERROR(format::clone_table_expr_tree(conjunct->root(), &root));
608
9
        RETURN_IF_ERROR(rewrite_slot_refs_to_global_index(&root, _slot_id_to_global_index));
609
9
        conjuncts->push_back(VExprContext::create_shared(std::move(root)));
610
9
    }
611
467
    return Status::OK();
612
467
}
613
614
0
TFileFormatType::type FileScannerV2::_get_current_format_type() const {
615
0
    return get_range_format_type(*_params, _current_range);
616
0
}
617
618
Status FileScannerV2::_to_file_format(TFileFormatType::type format_type,
619
952
                                      format::FileFormat* file_format) {
620
952
    DORIS_CHECK(file_format != nullptr);
621
952
    switch (format_type) {
622
221
    case TFileFormatType::FORMAT_PARQUET:
623
221
        *file_format = format::FileFormat::PARQUET;
624
221
        return Status::OK();
625
5
    case TFileFormatType::FORMAT_JNI:
626
5
        *file_format = format::FileFormat::JNI;
627
5
        return Status::OK();
628
673
    case TFileFormatType::FORMAT_CSV_PLAIN:
629
674
    case TFileFormatType::FORMAT_CSV_GZ:
630
675
    case TFileFormatType::FORMAT_CSV_BZ2:
631
676
    case TFileFormatType::FORMAT_CSV_LZ4FRAME:
632
677
    case TFileFormatType::FORMAT_CSV_LZ4BLOCK:
633
678
    case TFileFormatType::FORMAT_CSV_LZOP:
634
679
    case TFileFormatType::FORMAT_CSV_DEFLATE:
635
680
    case TFileFormatType::FORMAT_CSV_SNAPPYBLOCK:
636
681
    case TFileFormatType::FORMAT_PROTO:
637
681
        *file_format = format::FileFormat::CSV;
638
681
        return Status::OK();
639
1
    case TFileFormatType::FORMAT_TEXT:
640
1
        *file_format = format::FileFormat::TEXT;
641
1
        return Status::OK();
642
37
    case TFileFormatType::FORMAT_JSON:
643
37
        *file_format = format::FileFormat::JSON;
644
37
        return Status::OK();
645
5
    case TFileFormatType::FORMAT_NATIVE:
646
5
        *file_format = format::FileFormat::NATIVE;
647
5
        return Status::OK();
648
1
    case TFileFormatType::FORMAT_ARROW:
649
1
        *file_format = format::FileFormat::ARROW;
650
1
        return Status::OK();
651
1
    default:
652
1
        return Status::NotSupported("FileScannerV2 does not support file format {}",
653
1
                                    to_string(format_type));
654
952
    }
655
952
}
656
657
469
Status FileScannerV2::_init_io_ctx() {
658
469
    _io_ctx = std::make_shared<io::IOContext>();
659
469
    _io_ctx->query_id = &_state->query_id();
660
469
    return Status::OK();
661
469
}
662
663
469
void FileScannerV2::_reset_adaptive_batch_size_state() {
664
469
    _block_size_predictor.reset();
665
469
    COUNTER_SET(_adaptive_batch_predicted_rows_counter, int64_t(0));
666
469
    COUNTER_SET(_adaptive_batch_actual_bytes_counter, int64_t(0));
667
469
}
668
669
469
void FileScannerV2::_init_adaptive_batch_size_state(TFileFormatType::type format_type) {
670
469
    _reset_adaptive_batch_size_state();
671
469
    if (!_should_enable_adaptive_batch_size(format_type)) {
672
2
        return;
673
2
    }
674
675
    // V2 native file readers do not have reliable row-width hints before the first batch. Start
676
    // every split with a small probe, then learn bytes-per-row from the materialized table block
677
    // and keep later batches close to RuntimeState::preferred_block_size_bytes().
678
467
    _block_size_predictor = std::make_unique<AdaptiveBlockSizePredictor>(
679
467
            _state->preferred_block_size_bytes(), 0.0, ADAPTIVE_BATCH_INITIAL_PROBE_ROWS,
680
467
            _state->batch_size());
681
467
}
682
683
469
bool FileScannerV2::_should_enable_adaptive_batch_size(TFileFormatType::type format_type) const {
684
469
    if (!config::enable_adaptive_batch_size) {
685
0
        return false;
686
0
    }
687
469
    switch (format_type) {
688
110
    case TFileFormatType::FORMAT_PARQUET:
689
110
    case TFileFormatType::FORMAT_ORC:
690
446
    case TFileFormatType::FORMAT_CSV_PLAIN:
691
446
    case TFileFormatType::FORMAT_CSV_GZ:
692
446
    case TFileFormatType::FORMAT_CSV_BZ2:
693
446
    case TFileFormatType::FORMAT_CSV_LZ4FRAME:
694
446
    case TFileFormatType::FORMAT_CSV_LZ4BLOCK:
695
446
    case TFileFormatType::FORMAT_CSV_LZOP:
696
446
    case TFileFormatType::FORMAT_CSV_DEFLATE:
697
446
    case TFileFormatType::FORMAT_CSV_SNAPPYBLOCK:
698
446
    case TFileFormatType::FORMAT_PROTO:
699
446
    case TFileFormatType::FORMAT_TEXT:
700
464
    case TFileFormatType::FORMAT_JSON:
701
466
    case TFileFormatType::FORMAT_JNI:
702
466
        return true;
703
2
    default:
704
2
        return false;
705
469
    }
706
469
}
707
708
1.78k
bool FileScannerV2::_should_run_adaptive_batch_size() const {
709
    // COUNT pushdown emits synthetic rows from file metadata and does not materialize file columns,
710
    // so there is no useful row-width sample to learn from.
711
1.78k
    return _block_size_predictor != nullptr &&
712
1.78k
           _local_state->get_push_down_agg_type() != TPushAggOp::type::COUNT;
713
1.78k
}
714
715
1.11k
size_t FileScannerV2::_predict_reader_batch_rows() {
716
1.11k
    DORIS_CHECK(_block_size_predictor != nullptr);
717
    // Before history exists this returns the probe row count; after update(), it returns roughly
718
    // preferred_block_size_bytes / EWMA(bytes_per_row), capped by RuntimeState::batch_size().
719
1.11k
    const size_t predicted_rows = _block_size_predictor->predict_next_rows();
720
1.11k
    COUNTER_SET(_adaptive_batch_predicted_rows_counter, static_cast<int64_t>(predicted_rows));
721
1.11k
    return predicted_rows;
722
1.11k
}
723
724
656
void FileScannerV2::_update_adaptive_batch_size(const Block& block) {
725
656
    if (!_should_run_adaptive_batch_size()) {
726
6
        return;
727
6
    }
728
650
    COUNTER_SET(_adaptive_batch_actual_bytes_counter, static_cast<int64_t>(block.bytes()));
729
650
    if (block.rows() == 0) {
730
0
        return;
731
0
    }
732
    // The sample is taken after TableReader has finalized file-local columns to table columns.
733
    // This matches the memory shape seen by upstream operators and catches very wide nested
734
    // columns, such as map/string payloads, after the first probe batch.
735
650
    if (!_block_size_predictor->has_history()) {
736
467
        COUNTER_UPDATE(_adaptive_batch_probe_count_counter, 1);
737
467
    }
738
650
    _block_size_predictor->update(block);
739
650
}
740
741
469
Status FileScannerV2::close(RuntimeState* state) {
742
469
    if (!_try_close()) {
743
0
        return Status::OK();
744
0
    }
745
469
    if (_table_reader != nullptr) {
746
467
        RETURN_IF_ERROR(_table_reader->close());
747
467
        _report_condition_cache_profile();
748
467
        _table_reader.reset();
749
467
    }
750
469
    return Scanner::close(state);
751
469
}
752
753
469
void FileScannerV2::try_stop() {
754
469
    Scanner::try_stop();
755
469
    if (_io_ctx) {
756
469
        _io_ctx->should_stop = true;
757
469
    }
758
469
}
759
760
0
void FileScannerV2::update_realtime_counters() {
761
0
    if (_file_reader_stats == nullptr) {
762
0
        return;
763
0
    }
764
0
    DORIS_CHECK(_file_cache_statistics != nullptr);
765
0
    const int64_t bytes_read = cast_set<int64_t>(_file_reader_stats->read_bytes);
766
0
    auto* local_state = static_cast<FileScanLocalState*>(_local_state);
767
0
    const auto file_type =
768
0
            _current_range.__isset.file_type
769
0
                    ? _current_range.file_type
770
0
                    : (_params != nullptr && _params->__isset.file_type ? _params->file_type
771
0
                                                                        : TFileType::FILE_LOCAL);
772
0
    const auto deltas = _collect_realtime_counter_deltas(
773
0
            *_file_reader_stats, *_file_cache_statistics, _uncached_reader_bytes_storage(file_type),
774
0
            &_last_read_bytes, &_last_read_rows, &_last_bytes_read_from_local,
775
0
            &_last_bytes_read_from_remote);
776
777
0
    COUNTER_UPDATE(local_state->_scan_bytes, deltas.scan_bytes);
778
0
    COUNTER_UPDATE(local_state->_scan_rows, deltas.scan_rows);
779
780
0
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_rows(deltas.scan_rows);
781
0
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes(deltas.scan_bytes);
782
0
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes_from_local_storage(
783
0
            deltas.scan_bytes_from_local_storage);
784
0
    _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes_from_remote_storage(
785
0
            deltas.scan_bytes_from_remote_storage);
786
787
0
    COUNTER_SET(_file_read_bytes_counter, bytes_read);
788
0
    COUNTER_SET(_file_read_calls_counter, cast_set<int64_t>(_file_reader_stats->read_calls));
789
0
    COUNTER_SET(_file_read_time_counter, cast_set<int64_t>(_file_reader_stats->read_time_ns));
790
791
0
    DorisMetrics::instance()->query_scan_bytes->increment(deltas.scan_bytes);
792
0
    DorisMetrics::instance()->query_scan_rows->increment(deltas.scan_rows);
793
0
    DorisMetrics::instance()->query_scan_bytes_from_local->increment(
794
0
            deltas.scan_bytes_from_local_storage);
795
0
    DorisMetrics::instance()->query_scan_bytes_from_remote->increment(
796
0
            deltas.scan_bytes_from_remote_storage);
797
0
}
798
799
FileScannerV2::RealtimeCounterDeltas FileScannerV2::_collect_realtime_counter_deltas(
800
        const io::FileReaderStats& file_reader_stats,
801
        const io::FileCacheStatistics& file_cache_statistics,
802
        UncachedReaderBytesStorage uncached_reader_bytes_storage, int64_t* last_read_bytes,
803
        int64_t* last_read_rows, int64_t* last_bytes_read_from_local,
804
7
        int64_t* last_bytes_read_from_remote) {
805
7
    DORIS_CHECK(last_read_bytes != nullptr);
806
7
    DORIS_CHECK(last_read_rows != nullptr);
807
7
    DORIS_CHECK(last_bytes_read_from_local != nullptr);
808
7
    DORIS_CHECK(last_bytes_read_from_remote != nullptr);
809
810
7
    const int64_t read_bytes = cast_set<int64_t>(file_reader_stats.read_bytes);
811
7
    const int64_t read_rows = cast_set<int64_t>(file_reader_stats.read_rows);
812
7
    const int64_t bytes_read_from_local = file_cache_statistics.bytes_read_from_local;
813
7
    const int64_t bytes_read_from_remote = file_cache_statistics.bytes_read_from_remote;
814
7
    DORIS_CHECK(read_bytes >= *last_read_bytes);
815
7
    DORIS_CHECK(read_rows >= *last_read_rows);
816
7
    DORIS_CHECK(bytes_read_from_local >= *last_bytes_read_from_local);
817
7
    DORIS_CHECK(bytes_read_from_remote >= *last_bytes_read_from_remote);
818
819
7
    RealtimeCounterDeltas deltas;
820
7
    deltas.scan_rows = read_rows - *last_read_rows;
821
7
    deltas.scan_bytes = read_bytes - *last_read_bytes;
822
    // Peer cache is a known cache source, but it is not remote object storage.
823
7
    const bool has_cache_source_stats = file_cache_statistics.num_local_io_total != 0 ||
824
7
                                        file_cache_statistics.num_remote_io_total != 0 ||
825
7
                                        file_cache_statistics.num_peer_io_total != 0 ||
826
7
                                        bytes_read_from_local != 0 || bytes_read_from_remote != 0 ||
827
7
                                        file_cache_statistics.bytes_read_from_peer != 0;
828
7
    if (!has_cache_source_stats) {
829
4
        switch (uncached_reader_bytes_storage) {
830
1
        case UncachedReaderBytesStorage::LOCAL:
831
1
            deltas.scan_bytes_from_local_storage = deltas.scan_bytes;
832
1
            break;
833
3
        case UncachedReaderBytesStorage::REMOTE:
834
3
            deltas.scan_bytes_from_remote_storage = deltas.scan_bytes;
835
3
            break;
836
0
        case UncachedReaderBytesStorage::NONE:
837
0
            break;
838
4
        }
839
4
    } else {
840
3
        deltas.scan_bytes_from_local_storage = bytes_read_from_local - *last_bytes_read_from_local;
841
3
        deltas.scan_bytes_from_remote_storage =
842
3
                bytes_read_from_remote - *last_bytes_read_from_remote;
843
3
    }
844
845
7
    *last_read_bytes = read_bytes;
846
7
    *last_read_rows = read_rows;
847
7
    *last_bytes_read_from_local = bytes_read_from_local;
848
7
    *last_bytes_read_from_remote = bytes_read_from_remote;
849
7
    return deltas;
850
7
}
851
852
FileScannerV2::UncachedReaderBytesStorage FileScannerV2::_uncached_reader_bytes_storage(
853
0
        TFileType::type file_type) {
854
0
    switch (file_type) {
855
0
    case TFileType::FILE_LOCAL:
856
0
        return UncachedReaderBytesStorage::LOCAL;
857
0
    case TFileType::FILE_STREAM:
858
0
        return UncachedReaderBytesStorage::NONE;
859
0
    case TFileType::FILE_BROKER:
860
0
    case TFileType::FILE_S3:
861
0
    case TFileType::FILE_HDFS:
862
0
    case TFileType::FILE_NET:
863
0
    case TFileType::FILE_HTTP:
864
0
        return UncachedReaderBytesStorage::REMOTE;
865
0
    }
866
0
    DORIS_CHECK(false) << "unknown file type: " << file_type;
867
0
    return UncachedReaderBytesStorage::NONE;
868
0
}
869
870
469
void FileScannerV2::_collect_profile_before_close() {
871
469
    _report_file_reader_predicate_filtered_rows();
872
469
    Scanner::_collect_profile_before_close();
873
469
    if (_file_reader_stats != nullptr) {
874
469
        COUNTER_SET(_file_read_bytes_counter, cast_set<int64_t>(_file_reader_stats->read_bytes));
875
469
        COUNTER_SET(_file_read_calls_counter, cast_set<int64_t>(_file_reader_stats->read_calls));
876
469
        COUNTER_SET(_file_read_time_counter, cast_set<int64_t>(_file_reader_stats->read_time_ns));
877
469
    }
878
    // Query profiles can be collected before Scanner::close() runs. Publish condition-cache
879
    // counters here as well, using deltas so this method and close() cannot double count.
880
469
    _report_condition_cache_profile();
881
469
}
882
883
469
bool FileScannerV2::_should_update_load_counters() const {
884
469
    if (_is_load) {
885
0
        return true;
886
0
    }
887
    // TVF based loads (e.g. http_stream, group commit relay) plan the load source as a
888
    // tvf query scan without src tuple desc, so _is_load is false. But rows filtered by
889
    // the load's WHERE clause still need to be reported as unselected rows. FILE_STREAM
890
    // is only reachable from such load entries, never from normal queries, so use it to
891
    // identify these scanners.
892
469
    return (_params != nullptr && _params->__isset.file_type &&
893
469
            _params->file_type == TFileType::FILE_STREAM) ||
894
469
           (_current_range.__isset.file_type && _current_range.file_type == TFileType::FILE_STREAM);
895
469
}
896
897
469
void FileScannerV2::_report_file_reader_predicate_filtered_rows() {
898
469
    const int64_t filtered_rows = _io_ctx != nullptr ? _io_ctx->predicate_filtered_rows : 0;
899
469
    const int64_t filtered_delta = filtered_rows - _reported_predicate_filtered_rows;
900
469
    if (filtered_delta > 0) {
901
        // File readers can evaluate localized conjuncts before a block reaches Scanner. Count
902
        // those rows as scanner-level unselected rows so load statistics stay identical no matter
903
        // whether a predicate is pushed down or evaluated by Scanner::_filter_output_block().
904
9
        _counter.num_rows_unselected += filtered_delta;
905
9
        _reported_predicate_filtered_rows = filtered_rows;
906
9
    }
907
469
}
908
909
936
void FileScannerV2::_report_condition_cache_profile() {
910
936
    auto* local_state = static_cast<FileScanLocalState*>(_local_state);
911
936
    const int64_t hit_count =
912
936
            _table_reader != nullptr ? _table_reader->condition_cache_hit_count() : 0;
913
936
    const int64_t hit_delta = hit_count - _reported_condition_cache_hit_count;
914
936
    if (hit_delta > 0) {
915
0
        COUNTER_UPDATE(local_state->_condition_cache_hit_counter, hit_delta);
916
0
        _reported_condition_cache_hit_count = hit_count;
917
0
    }
918
936
    const int64_t filtered_rows = _io_ctx != nullptr ? _io_ctx->condition_cache_filtered_rows : 0;
919
936
    const int64_t filtered_delta = filtered_rows - _reported_condition_cache_filtered_rows;
920
936
    if (filtered_delta > 0) {
921
0
        COUNTER_UPDATE(local_state->_condition_cache_filtered_rows_counter, filtered_delta);
922
0
        _reported_condition_cache_filtered_rows = filtered_rows;
923
0
    }
924
936
}
925
926
} // namespace doris