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 | 4 | void update_counter(RuntimeProfile::Counter* counter, int64_t value) { |
32 | 4 | if (counter != nullptr) { |
33 | 4 | COUNTER_UPDATE(counter, value); |
34 | 4 | } |
35 | 4 | } |
36 | | |
37 | | } // namespace |
38 | | |
39 | 4 | ColumnPtr make_column_nullable_if_needed(ColumnPtr column, const DataTypePtr& target_type) { |
40 | 4 | if (target_type != nullptr && target_type->is_nullable() && column.get() != nullptr && |
41 | 4 | !column->is_nullable()) { |
42 | 4 | return make_nullable(std::move(column)); |
43 | 4 | } |
44 | 0 | return column; |
45 | 4 | } |
46 | | |
47 | | Status apply_materialized_reader_filters(const FileScanRequest* request, io::IOContext* io_ctx, |
48 | | Block* file_block, size_t* rows, |
49 | 48 | const MaterializedReaderFilterProfile* profile) { |
50 | 48 | DORIS_CHECK(file_block != nullptr); |
51 | 48 | DORIS_CHECK(rows != nullptr); |
52 | 48 | const size_t rows_before_filter = *rows; |
53 | 48 | size_t rows_after_delete_filter = rows_before_filter; |
54 | 48 | if (request != nullptr && rows_before_filter > 0 && !request->delete_conjuncts.empty()) { |
55 | 1 | { |
56 | 1 | SCOPED_TIMER(profile == nullptr ? nullptr : profile->delete_conjunct_filter_time); |
57 | 1 | RETURN_IF_ERROR(VExprContext::filter_block(request->delete_conjuncts, file_block, |
58 | 1 | file_block->columns())); |
59 | 1 | } |
60 | 1 | rows_after_delete_filter = |
61 | 1 | file_block->columns() == 0 ? rows_before_filter : file_block->rows(); |
62 | 1 | 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 | 1 | } |
67 | | |
68 | 48 | size_t rows_after_filter = rows_after_delete_filter; |
69 | 48 | if (request != nullptr && rows_after_delete_filter > 0 && !request->conjuncts.empty()) { |
70 | 7 | { |
71 | 7 | SCOPED_TIMER(profile == nullptr ? nullptr : profile->conjunct_filter_time); |
72 | 7 | RETURN_IF_ERROR(VExprContext::filter_block(request->conjuncts, file_block, |
73 | 7 | file_block->columns())); |
74 | 7 | } |
75 | 7 | rows_after_filter = |
76 | 7 | file_block->columns() == 0 ? rows_after_delete_filter : file_block->rows(); |
77 | 7 | const auto rows_filtered_by_conjunct = rows_after_delete_filter - rows_after_filter; |
78 | 7 | if (profile != nullptr) { |
79 | 4 | update_counter(profile->rows_filtered_by_conjunct, rows_filtered_by_conjunct); |
80 | 4 | } |
81 | 7 | if (io_ctx != nullptr) { |
82 | 5 | io_ctx->predicate_filtered_rows += rows_filtered_by_conjunct; |
83 | 5 | } |
84 | 7 | } |
85 | 48 | *rows = rows_after_filter; |
86 | 48 | return Status::OK(); |
87 | 48 | } |
88 | | |
89 | | } // namespace doris::format |