be/src/format_v2/parquet/parquet_statistics.h
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 | | // http://www.apache.org/licenses/LICENSE-2.0 |
9 | | // Unless required by applicable law or agreed to in writing, |
10 | | // software distributed under the License is distributed on an |
11 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
12 | | // KIND, either express or implied. See the License for the |
13 | | // specific language governing permissions and limitations |
14 | | // under the License. |
15 | | |
16 | | #pragma once |
17 | | |
18 | | #include <cstddef> |
19 | | #include <cstdint> |
20 | | #include <map> |
21 | | #include <memory> |
22 | | #include <string> |
23 | | #include <vector> |
24 | | |
25 | | #include "common/status.h" |
26 | | #include "core/field.h" |
27 | | #include "core/string_ref.h" |
28 | | #include "exprs/vexpr_fwd.h" |
29 | | #include "format_v2/file_reader.h" |
30 | | #include "format_v2/parquet/selection_vector.h" |
31 | | |
32 | | namespace parquet { |
33 | | class BloomFilter; |
34 | | class ColumnIndex; |
35 | | class FileMetaData; |
36 | | class ParquetFileReader; |
37 | | class Statistics; |
38 | | } // namespace parquet |
39 | | |
40 | | namespace cctz { |
41 | | class time_zone; |
42 | | } // namespace cctz |
43 | | |
44 | | namespace doris { |
45 | | class RuntimeState; |
46 | | namespace segment_v2 { |
47 | | struct ZoneMap; |
48 | | } // namespace segment_v2 |
49 | | } // namespace doris |
50 | | |
51 | | namespace doris::format::parquet { |
52 | | |
53 | | struct ParquetColumnSchema; |
54 | | |
55 | | // ============================================================================ |
56 | | // ============================================================================ |
57 | | |
58 | | struct ParquetDictionaryWords { |
59 | | std::vector<std::string> values; |
60 | | std::vector<StringRef> refs; |
61 | | |
62 | 47 | void clear() { |
63 | 47 | values.clear(); |
64 | 47 | refs.clear(); |
65 | 47 | } |
66 | | |
67 | 47 | void build_refs() { |
68 | 47 | refs.clear(); |
69 | 47 | refs.reserve(values.size()); |
70 | 120 | for (const auto& value : values) { |
71 | 120 | refs.emplace_back(value.data(), value.size()); |
72 | 120 | } |
73 | 47 | } |
74 | | }; |
75 | | |
76 | | // Reads the PLAIN dictionary page for BYTE_ARRAY/FIXED_LEN_BYTE_ARRAY columns and owns copied |
77 | | // dictionary bytes in `values`. Both row-group pruning and row-level dictionary predicates use this |
78 | | // helper so they agree on dictionary id -> Doris string value mapping. |
79 | | bool read_dictionary_words(::parquet::ParquetFileReader* file_reader, int row_group_idx, |
80 | | int leaf_column_id, const ParquetColumnSchema& column_schema, |
81 | | ParquetDictionaryWords* dict_words); |
82 | | |
83 | | std::vector<Field> dictionary_fields_from_words(const ParquetDictionaryWords& dict_words); |
84 | | |
85 | | // ============================================================================ |
86 | | // ============================================================================ |
87 | | |
88 | | struct ParquetPruningStats { |
89 | | int64_t total_row_groups = 0; // total row groups in the file |
90 | | int64_t selected_row_groups = 0; // row groups selected after pruning |
91 | | int64_t filtered_row_groups_by_statistics = 0; // row groups pruned by ZoneMap statistics |
92 | | int64_t filtered_row_groups_by_dictionary = 0; // row groups pruned by dictionary |
93 | | int64_t filtered_row_groups_by_bloom_filter = 0; // row groups pruned by bloom filter |
94 | | int64_t filtered_row_groups_by_page_index = 0; // row groups fully pruned by page index |
95 | | int64_t filtered_group_rows = 0; // rows in pruned row groups |
96 | | int64_t filtered_page_rows = 0; // rows pruned by page index |
97 | | int64_t selected_row_ranges = 0; // selected row range count |
98 | | int64_t page_index_read_calls = 0; // Page Index read count |
99 | | int64_t bloom_filter_read_time = 0; // Bloom filter read time (ns) |
100 | | int64_t row_group_filter_time = 0; // row-group pruning time (ns) |
101 | | int64_t page_index_filter_time = 0; // page-index pruning time (ns) |
102 | | int64_t read_page_index_time = 0; // page-index read time (ns) |
103 | | int64_t expr_zonemap_unusable_evals = 0; // VExpr ZoneMap unusable evaluations |
104 | | int64_t in_zonemap_point_check_count = 0; // VExpr IN ZoneMap point checks |
105 | | int64_t in_zonemap_range_only_count = 0; // VExpr IN ZoneMap range-only checks |
106 | | }; |
107 | | |
108 | | struct ParquetColumnStatistics { |
109 | | Field min_value; // column minimum value converted to Doris type |
110 | | Field max_value; // column maximum value |
111 | | bool has_null = false; // whether NULL exists |
112 | | bool has_not_null = false; // whether non-NULL values exist |
113 | | bool has_null_count = false; // whether null_count is valid |
114 | | bool has_min_max = false; // whether min/max is valid after conversion |
115 | | |
116 | 0 | bool has_any_statistics() const { return has_null_count || has_min_max; } |
117 | | }; |
118 | | |
119 | | // ============================================================================ |
120 | | // ============================================================================ |
121 | | // VExpr ZoneMap(TransformColumnStatistics + evaluate_zonemap_filter) |
122 | | // -> page-index ZoneMap(evaluate_zonemap_filter) |
123 | | // dictionary(read_dictionary_words + evaluate_dictionary_filter) |
124 | | // -> bloom filter(evaluate_bloom_filter) |
125 | | // ============================================================================ |
126 | | struct ParquetStatisticsUtils { |
127 | | static std::shared_ptr<segment_v2::ZoneMap> MakeZoneMap( |
128 | | const ParquetColumnStatistics& statistics); |
129 | | |
130 | | static ParquetColumnStatistics TransformColumnStatistics( |
131 | | const ParquetColumnSchema& column_schema, |
132 | | const std::shared_ptr<::parquet::Statistics>& statistics, |
133 | | const cctz::time_zone* timezone = nullptr); |
134 | | |
135 | | static bool TransformColumnIndexStatistics( |
136 | | const std::shared_ptr<::parquet::ColumnIndex>& column_index, |
137 | | const ParquetColumnSchema& column_schema, size_t page_idx, |
138 | | ParquetColumnStatistics* page_statistics, const cctz::time_zone* timezone = nullptr); |
139 | | |
140 | | static bool BloomFilterExcludes(const ParquetColumnSchema& column_schema, int slot_index, |
141 | | const VExprContextSPtrs& conjuncts, |
142 | | const ::parquet::BloomFilter& bloom_filter); |
143 | | }; |
144 | | |
145 | | Status select_row_groups_by_metadata( |
146 | | const ::parquet::FileMetaData& metadata, ::parquet::ParquetFileReader* file_reader, |
147 | | const std::vector<std::unique_ptr<ParquetColumnSchema>>& file_schema, |
148 | | const format::FileScanRequest& request, const std::vector<int>* candidate_row_groups, |
149 | | std::vector<int>* selected_row_groups, bool enable_bloom_filter, |
150 | | ParquetPruningStats* pruning_stats, const cctz::time_zone* timezone = nullptr, |
151 | | const RuntimeState* runtime_state = nullptr); |
152 | | |
153 | | Status select_row_group_ranges_by_page_index( |
154 | | ::parquet::ParquetFileReader* file_reader, |
155 | | const std::vector<std::unique_ptr<ParquetColumnSchema>>& file_schema, |
156 | | const format::FileScanRequest& request, int row_group_idx, int64_t row_group_rows, |
157 | | std::vector<RowRange>* selected_ranges, std::map<int, ParquetPageSkipPlan>* page_skip_plans, |
158 | | ParquetPruningStats* pruning_stats, const cctz::time_zone* timezone = nullptr, |
159 | | const RuntimeState* runtime_state = nullptr); |
160 | | |
161 | | } // namespace doris::format::parquet |