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 "arrow/array/builder_decimal.h" |
19 | |
20 | #include <algorithm> |
21 | #include <cstddef> |
22 | #include <cstdint> |
23 | #include <cstring> |
24 | #include <memory> |
25 | #include <numeric> |
26 | #include <sstream> |
27 | #include <string> |
28 | #include <utility> |
29 | #include <vector> |
30 | |
31 | #include "arrow/array.h" |
32 | #include "arrow/buffer.h" |
33 | #include "arrow/status.h" |
34 | #include "arrow/type.h" |
35 | #include "arrow/type_traits.h" |
36 | #include "arrow/util/bit-util.h" |
37 | #include "arrow/util/checked_cast.h" |
38 | #include "arrow/util/decimal.h" |
39 | #include "arrow/util/logging.h" |
40 | |
41 | namespace arrow { |
42 | |
43 | // ---------------------------------------------------------------------- |
44 | // Decimal128Builder |
45 | |
46 | Decimal128Builder::Decimal128Builder(const std::shared_ptr<DataType>& type, |
47 | MemoryPool* pool) |
48 | : FixedSizeBinaryBuilder(type, pool) {} |
49 | |
50 | Status Decimal128Builder::Append(const Decimal128& value) { |
51 | RETURN_NOT_OK(FixedSizeBinaryBuilder::Reserve(1)); |
52 | return FixedSizeBinaryBuilder::Append(value.ToBytes()); |
53 | } |
54 | |
55 | Status Decimal128Builder::FinishInternal(std::shared_ptr<ArrayData>* out) { |
56 | std::shared_ptr<Buffer> data; |
57 | RETURN_NOT_OK(byte_builder_.Finish(&data)); |
58 | std::shared_ptr<Buffer> null_bitmap; |
59 | RETURN_NOT_OK(null_bitmap_builder_.Finish(&null_bitmap)); |
60 | |
61 | *out = ArrayData::Make(type_, length_, {null_bitmap, data}, null_count_); |
62 | |
63 | return Status::OK(); |
64 | } |
65 | |
66 | } // namespace arrow |
67 | |