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 <cstdint> |
19 | | #include <map> |
20 | | #include <memory> |
21 | | #include <vector> |
22 | | |
23 | | #include "common/status.h" |
24 | | #include "core/field.h" |
25 | | #include "exprs/vexpr_fwd.h" |
26 | | #include "format_v2/file_reader.h" |
27 | | #include "format_v2/parquet/selection_vector.h" |
28 | | |
29 | | namespace parquet { |
30 | | class BloomFilter; |
31 | | class FileMetaData; |
32 | | class ParquetFileReader; |
33 | | class Statistics; |
34 | | } // namespace parquet |
35 | | |
36 | | namespace cctz { |
37 | | class time_zone; |
38 | | } // namespace cctz |
39 | | |
40 | | namespace doris { |
41 | | class RuntimeState; |
42 | | } // namespace doris |
43 | | |
44 | | namespace doris::format::parquet { |
45 | | |
46 | | struct ParquetColumnSchema; |
47 | | |
48 | | // ============================================================================ |
49 | | // ============================================================================ |
50 | | |
51 | | struct ParquetPruningStats { |
52 | | int64_t total_row_groups = 0; // total row groups in the file |
53 | | int64_t selected_row_groups = 0; // row groups selected after pruning |
54 | | int64_t filtered_row_groups_by_statistics = 0; // row groups pruned by ZoneMap statistics |
55 | | int64_t filtered_row_groups_by_dictionary = 0; // row groups pruned by dictionary |
56 | | int64_t filtered_row_groups_by_bloom_filter = 0; // row groups pruned by bloom filter |
57 | | int64_t filtered_row_groups_by_page_index = 0; // row groups fully pruned by page index |
58 | | int64_t filtered_group_rows = 0; // rows in pruned row groups |
59 | | int64_t filtered_page_rows = 0; // rows pruned by page index |
60 | | int64_t selected_row_ranges = 0; // selected row range count |
61 | | int64_t page_index_read_calls = 0; // Page Index read count |
62 | | int64_t bloom_filter_read_time = 0; // Bloom filter read time (ns) |
63 | | int64_t row_group_filter_time = 0; // row-group pruning time (ns) |
64 | | int64_t page_index_filter_time = 0; // page-index pruning time (ns) |
65 | | int64_t read_page_index_time = 0; // page-index read time (ns) |
66 | | int64_t expr_zonemap_unusable_evals = 0; // VExpr ZoneMap unusable evaluations |
67 | | int64_t in_zonemap_point_check_count = 0; // VExpr IN ZoneMap point checks |
68 | | int64_t in_zonemap_range_only_count = 0; // VExpr IN ZoneMap range-only checks |
69 | | }; |
70 | | |
71 | | struct ParquetColumnStatistics { |
72 | | Field min_value; // column minimum value converted to Doris type |
73 | | Field max_value; // column maximum value |
74 | | bool has_null = false; // whether NULL exists |
75 | | bool has_not_null = false; // whether non-NULL values exist |
76 | | bool has_null_count = false; // whether null_count is valid |
77 | | bool has_min_max = false; // whether min/max is valid after conversion |
78 | | |
79 | 0 | bool has_any_statistics() const { return has_null_count || has_min_max; } |
80 | | }; |
81 | | |
82 | | // ============================================================================ |
83 | | // ============================================================================ |
84 | | // VExpr ZoneMap(TransformColumnStatistics + evaluate_zonemap_filter) |
85 | | // -> page-index ZoneMap(evaluate_zonemap_filter) |
86 | | // dictionary(read_dictionary_words + evaluate_dictionary_filter) |
87 | | // -> bloom filter(evaluate_bloom_filter) |
88 | | // ============================================================================ |
89 | | struct ParquetStatisticsUtils { |
90 | | static ParquetColumnStatistics TransformColumnStatistics( |
91 | | const ParquetColumnSchema& column_schema, |
92 | | const std::shared_ptr<::parquet::Statistics>& statistics, |
93 | | const cctz::time_zone* timezone = nullptr); |
94 | | |
95 | | static bool BloomFilterExcludes(const ParquetColumnSchema& column_schema, int slot_index, |
96 | | const VExprContextSPtrs& conjuncts, |
97 | | const ::parquet::BloomFilter& bloom_filter); |
98 | | }; |
99 | | |
100 | | Status select_row_groups_by_metadata( |
101 | | const ::parquet::FileMetaData& metadata, ::parquet::ParquetFileReader* file_reader, |
102 | | const std::vector<std::unique_ptr<ParquetColumnSchema>>& file_schema, |
103 | | const format::FileScanRequest& request, const std::vector<int>* candidate_row_groups, |
104 | | std::vector<int>* selected_row_groups, bool enable_bloom_filter, |
105 | | ParquetPruningStats* pruning_stats, const cctz::time_zone* timezone = nullptr, |
106 | | const RuntimeState* runtime_state = nullptr); |
107 | | |
108 | | Status select_row_group_ranges_by_page_index( |
109 | | ::parquet::ParquetFileReader* file_reader, |
110 | | const std::vector<std::unique_ptr<ParquetColumnSchema>>& file_schema, |
111 | | const format::FileScanRequest& request, int row_group_idx, int64_t row_group_rows, |
112 | | std::vector<RowRange>* selected_ranges, std::map<int, ParquetPageSkipPlan>* page_skip_plans, |
113 | | ParquetPruningStats* pruning_stats, const cctz::time_zone* timezone = nullptr, |
114 | | const RuntimeState* runtime_state = nullptr); |
115 | | |
116 | | } // namespace doris::format::parquet |