File indexing completed on 2025-08-28 08:26:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #pragma once
0022
0023 #include <cstdint>
0024 #include <memory>
0025
0026 #include "arrow/array/array_base.h"
0027 #include "arrow/array/data.h"
0028 #include "arrow/stl_iterator.h"
0029 #include "arrow/type.h"
0030 #include "arrow/type_fwd.h" // IWYU pragma: export
0031 #include "arrow/type_traits.h"
0032 #include "arrow/util/bit_util.h"
0033 #include "arrow/util/macros.h"
0034 #include "arrow/util/visibility.h"
0035
0036 namespace arrow {
0037
0038
0039 class ARROW_EXPORT BooleanArray : public PrimitiveArray {
0040 public:
0041 using TypeClass = BooleanType;
0042 using IteratorType = stl::ArrayIterator<BooleanArray>;
0043
0044 explicit BooleanArray(const std::shared_ptr<ArrayData>& data);
0045
0046 BooleanArray(int64_t length, const std::shared_ptr<Buffer>& data,
0047 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
0048 int64_t null_count = kUnknownNullCount, int64_t offset = 0);
0049
0050 bool Value(int64_t i) const {
0051 return bit_util::GetBit(reinterpret_cast<const uint8_t*>(raw_values_),
0052 i + data_->offset);
0053 }
0054
0055 bool GetView(int64_t i) const { return Value(i); }
0056
0057 std::optional<bool> operator[](int64_t i) const { return *IteratorType(*this, i); }
0058
0059
0060
0061 int64_t false_count() const;
0062
0063
0064
0065 int64_t true_count() const;
0066
0067 IteratorType begin() const { return IteratorType(*this); }
0068
0069 IteratorType end() const { return IteratorType(*this, length()); }
0070
0071 protected:
0072 using PrimitiveArray::PrimitiveArray;
0073 };
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 template <typename TYPE>
0087 class NumericArray : public PrimitiveArray {
0088 public:
0089 using TypeClass = TYPE;
0090 using value_type = typename TypeClass::c_type;
0091 using IteratorType = stl::ArrayIterator<NumericArray<TYPE>>;
0092
0093 explicit NumericArray(const std::shared_ptr<ArrayData>& data) {
0094 NumericArray::SetData(data);
0095 }
0096
0097
0098
0099 template <typename T1 = TYPE>
0100 NumericArray(enable_if_parameter_free<T1, int64_t> length,
0101 const std::shared_ptr<Buffer>& data,
0102 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
0103 int64_t null_count = kUnknownNullCount, int64_t offset = 0) {
0104 NumericArray::SetData(ArrayData::Make(TypeTraits<T1>::type_singleton(), length,
0105 {null_bitmap, data}, null_count, offset));
0106 }
0107
0108 NumericArray(std::shared_ptr<DataType> type, int64_t length,
0109 const std::shared_ptr<Buffer>& data,
0110 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
0111 int64_t null_count = kUnknownNullCount, int64_t offset = 0) {
0112 NumericArray::SetData(ArrayData::Make(std::move(type), length, {null_bitmap, data},
0113 null_count, offset));
0114 }
0115
0116 const value_type* raw_values() const { return values_; }
0117
0118 value_type Value(int64_t i) const { return values_[i]; }
0119
0120
0121 value_type GetView(int64_t i) const { return values_[i]; }
0122
0123 std::optional<value_type> operator[](int64_t i) const {
0124 return *IteratorType(*this, i);
0125 }
0126
0127 IteratorType begin() const { return IteratorType(*this); }
0128
0129 IteratorType end() const { return IteratorType(*this, length()); }
0130
0131 protected:
0132 NumericArray() : values_(NULLPTR) {}
0133
0134 void SetData(const std::shared_ptr<ArrayData>& data) {
0135 this->PrimitiveArray::SetData(data);
0136 values_ = raw_values_
0137 ? (reinterpret_cast<const value_type*>(raw_values_) + data_->offset)
0138 : NULLPTR;
0139 }
0140
0141 const value_type* values_;
0142 };
0143
0144
0145
0146
0147 class ARROW_EXPORT DayTimeIntervalArray : public PrimitiveArray {
0148 public:
0149 using TypeClass = DayTimeIntervalType;
0150 using IteratorType = stl::ArrayIterator<DayTimeIntervalArray>;
0151
0152 explicit DayTimeIntervalArray(const std::shared_ptr<ArrayData>& data);
0153
0154 DayTimeIntervalArray(const std::shared_ptr<DataType>& type, int64_t length,
0155 const std::shared_ptr<Buffer>& data,
0156 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
0157 int64_t null_count = kUnknownNullCount, int64_t offset = 0);
0158
0159 DayTimeIntervalArray(int64_t length, const std::shared_ptr<Buffer>& data,
0160 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
0161 int64_t null_count = kUnknownNullCount, int64_t offset = 0);
0162
0163 TypeClass::DayMilliseconds GetValue(int64_t i) const;
0164 TypeClass::DayMilliseconds Value(int64_t i) const { return GetValue(i); }
0165
0166
0167 TypeClass::DayMilliseconds GetView(int64_t i) const { return GetValue(i); }
0168
0169 IteratorType begin() const { return IteratorType(*this); }
0170
0171 IteratorType end() const { return IteratorType(*this, length()); }
0172
0173 std::optional<TypeClass::DayMilliseconds> operator[](int64_t i) const {
0174 return *IteratorType(*this, i);
0175 }
0176
0177 int32_t byte_width() const { return sizeof(TypeClass::DayMilliseconds); }
0178
0179 const uint8_t* raw_values() const { return raw_values_ + data_->offset * byte_width(); }
0180 };
0181
0182
0183 class ARROW_EXPORT MonthDayNanoIntervalArray : public PrimitiveArray {
0184 public:
0185 using TypeClass = MonthDayNanoIntervalType;
0186 using IteratorType = stl::ArrayIterator<MonthDayNanoIntervalArray>;
0187
0188 explicit MonthDayNanoIntervalArray(const std::shared_ptr<ArrayData>& data);
0189
0190 MonthDayNanoIntervalArray(const std::shared_ptr<DataType>& type, int64_t length,
0191 const std::shared_ptr<Buffer>& data,
0192 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
0193 int64_t null_count = kUnknownNullCount, int64_t offset = 0);
0194
0195 MonthDayNanoIntervalArray(int64_t length, const std::shared_ptr<Buffer>& data,
0196 const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
0197 int64_t null_count = kUnknownNullCount, int64_t offset = 0);
0198
0199 TypeClass::MonthDayNanos GetValue(int64_t i) const;
0200 TypeClass::MonthDayNanos Value(int64_t i) const { return GetValue(i); }
0201
0202
0203 TypeClass::MonthDayNanos GetView(int64_t i) const { return GetValue(i); }
0204
0205 IteratorType begin() const { return IteratorType(*this); }
0206
0207 IteratorType end() const { return IteratorType(*this, length()); }
0208
0209 std::optional<TypeClass::MonthDayNanos> operator[](int64_t i) const {
0210 return *IteratorType(*this, i);
0211 }
0212
0213 int32_t byte_width() const { return sizeof(TypeClass::MonthDayNanos); }
0214
0215 const uint8_t* raw_values() const { return raw_values_ + data_->offset * byte_width(); }
0216 };
0217
0218
0219
0220 }