]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/cpp/src/gandiva/local_bitmaps_holder.h
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / gandiva / local_bitmaps_holder.h
CommitLineData
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 <memory>
21#include <utility>
22#include <vector>
23
24#include <arrow/util/logging.h>
25#include "gandiva/arrow.h"
26#include "gandiva/gandiva_aliases.h"
27
28namespace gandiva {
29
30/// \brief The buffers corresponding to one batch of records, used for
31/// expression evaluation.
32class LocalBitMapsHolder {
33 public:
34 LocalBitMapsHolder(int64_t num_records, int num_local_bitmaps);
35
36 int GetNumLocalBitMaps() const { return static_cast<int>(local_bitmaps_vec_.size()); }
37
38 int64_t GetLocalBitMapSize() const { return local_bitmap_size_; }
39
40 uint8_t** GetLocalBitMapArray() const { return local_bitmaps_array_.get(); }
41
42 uint8_t* GetLocalBitMap(int idx) const {
43 DCHECK(idx <= GetNumLocalBitMaps());
44 return local_bitmaps_array_.get()[idx];
45 }
46
47 private:
48 /// number of records in the current batch.
49 int64_t num_records_;
50
51 /// A container of 'local_bitmaps_', each sized to accommodate 'num_records'.
52 std::vector<std::unique_ptr<uint8_t[]>> local_bitmaps_vec_;
53
54 /// An array of the local bitmaps.
55 std::unique_ptr<uint8_t*[]> local_bitmaps_array_;
56
57 int64_t local_bitmap_size_;
58};
59
60inline LocalBitMapsHolder::LocalBitMapsHolder(int64_t num_records, int num_local_bitmaps)
61 : num_records_(num_records) {
62 // alloc an array for the pointers to the bitmaps.
63 if (num_local_bitmaps > 0) {
64 local_bitmaps_array_.reset(new uint8_t*[num_local_bitmaps]);
65 }
66
67 // 64-bit aligned bitmaps.
68 int64_t roundUp64Multiple = (num_records_ + 63) >> 6;
69 local_bitmap_size_ = roundUp64Multiple * 8;
70
71 // Alloc 'num_local_bitmaps_' number of bitmaps, each of capacity 'num_records_'.
72 for (int i = 0; i < num_local_bitmaps; ++i) {
73 // TODO : round-up to a slab friendly multiple.
74 std::unique_ptr<uint8_t[]> bitmap(new uint8_t[local_bitmap_size_]);
75
76 // keep pointer to the bitmap in the array.
77 (local_bitmaps_array_.get())[i] = bitmap.get();
78
79 // pre-fill with 1s (assuming that the probability of is_valid is higher).
80 memset(bitmap.get(), 0xff, local_bitmap_size_);
81 local_bitmaps_vec_.push_back(std::move(bitmap));
82 }
83}
84
85} // namespace gandiva