be/src/exec/scan/scan_key_bucket_pruner.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/scan_key_bucket_pruner.h" |
19 | | |
20 | | #include "storage/olap_utils.h" |
21 | | #include "util/hash_util.hpp" |
22 | | |
23 | | namespace doris { |
24 | | |
25 | | bool ScanKeyBucketPruner::init(const std::vector<std::unique_ptr<OlapScanRange>>& ranges, |
26 | 18 | int32_t bucket_num) { |
27 | 18 | DORIS_CHECK_GT(bucket_num, 0); |
28 | 18 | _bucket_ranges.clear(); |
29 | 31 | for (const auto& range : ranges) { |
30 | 31 | if (!range->has_lower_bound || !range->has_upper_bound || !range->begin_include || |
31 | 31 | !range->end_include || range->begin_scan_range.size() != 1 || |
32 | 31 | range->end_scan_range.size() != 1) { |
33 | 5 | return false; |
34 | 5 | } |
35 | 26 | const auto& begin = range->begin_scan_range.get_field(0); |
36 | 26 | const auto& end = range->end_scan_range.get_field(0); |
37 | 26 | if (begin.get_type() != TYPE_VARCHAR || end.get_type() != TYPE_VARCHAR || begin != end) { |
38 | 3 | return false; |
39 | 3 | } |
40 | 26 | } |
41 | 10 | _bucket_ranges.resize(bucket_num); |
42 | 15 | for (const auto& range : ranges) { |
43 | 15 | const auto& value = range->begin_scan_range.get_field(0).get<TYPE_VARCHAR>(); |
44 | | // Identical to ColumnString::update_crcs_with_value for a single non-null |
45 | | // VARCHAR distribution column: raw bytes, seed zero, and the full bucket count. |
46 | 15 | const uint32_t hash = |
47 | 15 | HashUtil::zlib_crc_hash(value.data(), static_cast<uint32_t>(value.size()), 0); |
48 | 15 | _bucket_ranges[hash % bucket_num].push_back(range.get()); |
49 | 15 | } |
50 | 10 | return true; |
51 | 18 | } |
52 | | |
53 | | const std::vector<OlapScanRange*>& ScanKeyBucketPruner::ranges_for_bucket( |
54 | 135 | int32_t bucket_seq) const { |
55 | 135 | DCHECK_GE(bucket_seq, 0); |
56 | | DCHECK_LT(bucket_seq, _bucket_ranges.size()); |
57 | 135 | return _bucket_ranges[bucket_seq]; |
58 | 135 | } |
59 | | |
60 | | } // namespace doris |