Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:26:54

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <memory>
0021 
0022 #include "arrow/array/array_decimal.h"
0023 #include "arrow/array/builder_base.h"
0024 #include "arrow/array/builder_binary.h"
0025 #include "arrow/array/data.h"
0026 #include "arrow/status.h"
0027 #include "arrow/type.h"
0028 #include "arrow/util/visibility.h"
0029 
0030 namespace arrow {
0031 
0032 /// \addtogroup numeric-builders
0033 ///
0034 /// @{
0035 
0036 class ARROW_EXPORT Decimal32Builder : public FixedSizeBinaryBuilder {
0037  public:
0038   using TypeClass = Decimal32Type;
0039   using ValueType = Decimal32;
0040 
0041   explicit Decimal32Builder(const std::shared_ptr<DataType>& type,
0042                             MemoryPool* pool = default_memory_pool(),
0043                             int64_t alignment = kDefaultBufferAlignment);
0044 
0045   using FixedSizeBinaryBuilder::Append;
0046   using FixedSizeBinaryBuilder::AppendValues;
0047   using FixedSizeBinaryBuilder::Reset;
0048 
0049   Status Append(Decimal32 val);
0050   void UnsafeAppend(Decimal32 val);
0051   void UnsafeAppend(std::string_view val);
0052 
0053   Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
0054 
0055   /// \cond FALSE
0056   using ArrayBuilder::Finish;
0057   /// \endcond
0058 
0059   Status Finish(std::shared_ptr<Decimal32Array>* out) { return FinishTyped(out); }
0060 
0061   std::shared_ptr<DataType> type() const override { return decimal_type_; }
0062 
0063  protected:
0064   std::shared_ptr<Decimal32Type> decimal_type_;
0065 };
0066 
0067 class ARROW_EXPORT Decimal64Builder : public FixedSizeBinaryBuilder {
0068  public:
0069   using TypeClass = Decimal64Type;
0070   using ValueType = Decimal64;
0071 
0072   explicit Decimal64Builder(const std::shared_ptr<DataType>& type,
0073                             MemoryPool* pool = default_memory_pool(),
0074                             int64_t alignment = kDefaultBufferAlignment);
0075 
0076   using FixedSizeBinaryBuilder::Append;
0077   using FixedSizeBinaryBuilder::AppendValues;
0078   using FixedSizeBinaryBuilder::Reset;
0079 
0080   Status Append(Decimal64 val);
0081   void UnsafeAppend(Decimal64 val);
0082   void UnsafeAppend(std::string_view val);
0083 
0084   Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
0085 
0086   /// \cond FALSE
0087   using ArrayBuilder::Finish;
0088   /// \endcond
0089 
0090   Status Finish(std::shared_ptr<Decimal64Array>* out) { return FinishTyped(out); }
0091 
0092   std::shared_ptr<DataType> type() const override { return decimal_type_; }
0093 
0094  protected:
0095   std::shared_ptr<Decimal64Type> decimal_type_;
0096 };
0097 
0098 class ARROW_EXPORT Decimal128Builder : public FixedSizeBinaryBuilder {
0099  public:
0100   using TypeClass = Decimal128Type;
0101   using ValueType = Decimal128;
0102 
0103   explicit Decimal128Builder(const std::shared_ptr<DataType>& type,
0104                              MemoryPool* pool = default_memory_pool(),
0105                              int64_t alignment = kDefaultBufferAlignment);
0106 
0107   using FixedSizeBinaryBuilder::Append;
0108   using FixedSizeBinaryBuilder::AppendValues;
0109   using FixedSizeBinaryBuilder::Reset;
0110 
0111   Status Append(Decimal128 val);
0112   void UnsafeAppend(Decimal128 val);
0113   void UnsafeAppend(std::string_view val);
0114 
0115   Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
0116 
0117   /// \cond FALSE
0118   using ArrayBuilder::Finish;
0119   /// \endcond
0120 
0121   Status Finish(std::shared_ptr<Decimal128Array>* out) { return FinishTyped(out); }
0122 
0123   std::shared_ptr<DataType> type() const override { return decimal_type_; }
0124 
0125  protected:
0126   std::shared_ptr<Decimal128Type> decimal_type_;
0127 };
0128 
0129 class ARROW_EXPORT Decimal256Builder : public FixedSizeBinaryBuilder {
0130  public:
0131   using TypeClass = Decimal256Type;
0132   using ValueType = Decimal256;
0133 
0134   explicit Decimal256Builder(const std::shared_ptr<DataType>& type,
0135                              MemoryPool* pool = default_memory_pool(),
0136                              int64_t alignment = kDefaultBufferAlignment);
0137 
0138   using FixedSizeBinaryBuilder::Append;
0139   using FixedSizeBinaryBuilder::AppendValues;
0140   using FixedSizeBinaryBuilder::Reset;
0141 
0142   Status Append(const Decimal256& val);
0143   void UnsafeAppend(const Decimal256& val);
0144   void UnsafeAppend(std::string_view val);
0145 
0146   Status FinishInternal(std::shared_ptr<ArrayData>* out) override;
0147 
0148   /// \cond FALSE
0149   using ArrayBuilder::Finish;
0150   /// \endcond
0151 
0152   Status Finish(std::shared_ptr<Decimal256Array>* out) { return FinishTyped(out); }
0153 
0154   std::shared_ptr<DataType> type() const override { return decimal_type_; }
0155 
0156  protected:
0157   std::shared_ptr<Decimal256Type> decimal_type_;
0158 };
0159 
0160 using DecimalBuilder = Decimal128Builder;
0161 
0162 /// @}
0163 
0164 }  // namespace arrow