]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
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 | #pragma once | |
19 | ||
20 | #include <vector> | |
21 | ||
22 | #include "arrow/util/macros.h" | |
23 | #include "gandiva/dex.h" | |
24 | #include "gandiva/dex_visitor.h" | |
25 | #include "gandiva/eval_batch.h" | |
26 | #include "gandiva/visibility.h" | |
27 | ||
28 | namespace gandiva { | |
29 | ||
30 | /// \brief Extract bitmap buffer from either the input/buffer vectors or the | |
31 | /// local validity bitmap, and accumulates them to do the final computation. | |
32 | class GANDIVA_EXPORT BitMapAccumulator : public DexDefaultVisitor { | |
33 | public: | |
34 | explicit BitMapAccumulator(const EvalBatch& eval_batch) | |
35 | : eval_batch_(eval_batch), all_invalid_(false) {} | |
36 | ||
37 | void Visit(const VectorReadValidityDex& dex) { | |
38 | int idx = dex.ValidityIdx(); | |
39 | auto bitmap = eval_batch_.GetBuffer(idx); | |
40 | // The bitmap could be null. Ignore it in this case. | |
41 | if (bitmap != NULLPTR) { | |
42 | src_maps_.push_back(bitmap); | |
43 | src_map_offsets_.push_back(eval_batch_.GetBufferOffset(idx)); | |
44 | } | |
45 | } | |
46 | ||
47 | void Visit(const LocalBitMapValidityDex& dex) { | |
48 | int idx = dex.local_bitmap_idx(); | |
49 | auto bitmap = eval_batch_.GetLocalBitMap(idx); | |
50 | src_maps_.push_back(bitmap); | |
51 | src_map_offsets_.push_back(0); // local bitmap has offset 0 | |
52 | } | |
53 | ||
54 | void Visit(const TrueDex& dex) { | |
55 | // bitwise-and with 1 is always 1. so, ignore. | |
56 | } | |
57 | ||
58 | void Visit(const FalseDex& dex) { | |
59 | // The final result is "all 0s". | |
60 | all_invalid_ = true; | |
61 | } | |
62 | ||
63 | /// Compute the dst_bmap based on the contents and type of the accumulated bitmap dex. | |
64 | void ComputeResult(uint8_t* dst_bitmap); | |
65 | ||
66 | /// Compute the intersection of the accumulated bitmaps (with offsets) and save the | |
67 | /// result in dst_bmap. | |
68 | static void IntersectBitMaps(uint8_t* dst_map, const std::vector<uint8_t*>& src_maps, | |
69 | const std::vector<int64_t>& src_maps_offsets, | |
70 | int64_t num_records); | |
71 | ||
72 | private: | |
73 | const EvalBatch& eval_batch_; | |
74 | std::vector<uint8_t*> src_maps_; | |
75 | std::vector<int64_t> src_map_offsets_; | |
76 | bool all_invalid_; | |
77 | }; | |
78 | ||
79 | } // namespace gandiva |