Coverage Report

Created: 2026-07-07 17:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format_v2/materialized_reader_util.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "format_v2/materialized_reader_util.h"
19
20
#include <utility>
21
22
#include "core/block/block.h"
23
#include "core/data_type/data_type_nullable.h"
24
#include "exprs/vexpr_context.h"
25
#include "format_v2/file_reader.h"
26
#include "io/io_common.h"
27
28
namespace doris::format {
29
namespace {
30
31
8
void update_counter(RuntimeProfile::Counter* counter, int64_t value) {
32
8
    if (counter != nullptr) {
33
8
        COUNTER_UPDATE(counter, value);
34
8
    }
35
8
}
36
37
} // namespace
38
39
8
ColumnPtr make_column_nullable_if_needed(ColumnPtr column, const DataTypePtr& target_type) {
40
8
    if (target_type != nullptr && target_type->is_nullable() && column.get() != nullptr &&
41
8
        !column->is_nullable()) {
42
8
        return make_nullable(std::move(column));
43
8
    }
44
0
    return column;
45
8
}
46
47
Status apply_materialized_reader_filters(const FileScanRequest* request, io::IOContext* io_ctx,
48
                                         Block* file_block, size_t* rows,
49
96
                                         const MaterializedReaderFilterProfile* profile) {
50
96
    DORIS_CHECK(file_block != nullptr);
51
96
    DORIS_CHECK(rows != nullptr);
52
96
    const size_t rows_before_filter = *rows;
53
96
    size_t rows_after_delete_filter = rows_before_filter;
54
96
    if (request != nullptr && rows_before_filter > 0 && !request->delete_conjuncts.empty()) {
55
2
        {
56
2
            SCOPED_TIMER(profile == nullptr ? nullptr : profile->delete_conjunct_filter_time);
57
2
            RETURN_IF_ERROR(VExprContext::filter_block(request->delete_conjuncts, file_block,
58
2
                                                       file_block->columns()));
59
2
        }
60
2
        rows_after_delete_filter =
61
2
                file_block->columns() == 0 ? rows_before_filter : file_block->rows();
62
2
        if (profile != nullptr) {
63
0
            update_counter(profile->rows_filtered_by_delete_conjunct,
64
0
                           rows_before_filter - rows_after_delete_filter);
65
0
        }
66
2
    }
67
68
96
    size_t rows_after_filter = rows_after_delete_filter;
69
96
    if (request != nullptr && rows_after_delete_filter > 0 && !request->conjuncts.empty()) {
70
14
        {
71
14
            SCOPED_TIMER(profile == nullptr ? nullptr : profile->conjunct_filter_time);
72
14
            RETURN_IF_ERROR(VExprContext::filter_block(request->conjuncts, file_block,
73
14
                                                       file_block->columns()));
74
14
        }
75
14
        rows_after_filter =
76
14
                file_block->columns() == 0 ? rows_after_delete_filter : file_block->rows();
77
14
        const auto rows_filtered_by_conjunct = rows_after_delete_filter - rows_after_filter;
78
14
        if (profile != nullptr) {
79
8
            update_counter(profile->rows_filtered_by_conjunct, rows_filtered_by_conjunct);
80
8
        }
81
14
        if (io_ctx != nullptr) {
82
10
            io_ctx->predicate_filtered_rows += rows_filtered_by_conjunct;
83
10
        }
84
14
    }
85
96
    *rows = rows_after_filter;
86
96
    return Status::OK();
87
96
}
88
89
} // namespace doris::format