| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| |
|
|
| #pragma once |
|
|
| #include <cstdint> |
| #include <memory> |
| #include <optional> |
| #include <string> |
| #include <string_view> |
| #include <vector> |
|
|
| #include "arrow/array/array_base.h" |
| #include "arrow/array/data.h" |
| #include "arrow/buffer.h" |
| #include "arrow/stl_iterator.h" |
| #include "arrow/type.h" |
| #include "arrow/util/checked_cast.h" |
| #include "arrow/util/macros.h" |
| #include "arrow/util/visibility.h" |
|
|
| namespace arrow { |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| |
| |
| template <typename TYPE> |
| class BaseBinaryArray : public FlatArray { |
| public: |
| using TypeClass = TYPE; |
| using offset_type = typename TypeClass::offset_type; |
| using IteratorType = stl::ArrayIterator<BaseBinaryArray<TYPE>>; |
|
|
| |
| |
| const uint8_t* GetValue(int64_t i, offset_type* out_length) const { |
| const offset_type pos = raw_value_offsets_[i]; |
| *out_length = raw_value_offsets_[i + 1] - pos; |
| return raw_data_ + pos; |
| } |
|
|
| |
| |
| |
| |
| std::string_view GetView(int64_t i) const { |
| const offset_type pos = raw_value_offsets_[i]; |
| return std::string_view(reinterpret_cast<const char*>(raw_data_ + pos), |
| raw_value_offsets_[i + 1] - pos); |
| } |
|
|
| std::optional<std::string_view> operator[](int64_t i) const { |
| return *IteratorType(*this, i); |
| } |
|
|
| |
| |
| |
| |
| |
| std::string_view Value(int64_t i) const { return GetView(i); } |
|
|
| |
| |
| |
| |
| std::string GetString(int64_t i) const { return std::string(GetView(i)); } |
|
|
| |
| std::shared_ptr<Buffer> value_offsets() const { return data_->buffers[1]; } |
|
|
| |
| std::shared_ptr<Buffer> value_data() const { return data_->buffers[2]; } |
|
|
| const offset_type* raw_value_offsets() const { return raw_value_offsets_; } |
|
|
| const uint8_t* raw_data() const { return raw_data_; } |
|
|
| |
| |
| |
| |
| offset_type value_offset(int64_t i) const { return raw_value_offsets_[i]; } |
|
|
| |
| |
| |
| offset_type value_length(int64_t i) const { |
| return raw_value_offsets_[i + 1] - raw_value_offsets_[i]; |
| } |
|
|
| |
| |
| |
| offset_type total_values_length() const { |
| if (data_->length > 0) { |
| return raw_value_offsets_[data_->length] - raw_value_offsets_[0]; |
| } else { |
| return 0; |
| } |
| } |
|
|
| IteratorType begin() const { return IteratorType(*this); } |
|
|
| IteratorType end() const { return IteratorType(*this, length()); } |
|
|
| protected: |
| |
| BaseBinaryArray() = default; |
|
|
| |
| void SetData(const std::shared_ptr<ArrayData>& data) { |
| this->Array::SetData(data); |
| raw_value_offsets_ = data->GetValuesSafe<offset_type>(1); |
| raw_data_ = data->GetValuesSafe<uint8_t>(2, 0); |
| } |
|
|
| const offset_type* raw_value_offsets_ = NULLPTR; |
| const uint8_t* raw_data_ = NULLPTR; |
| }; |
|
|
| |
| class ARROW_EXPORT BinaryArray : public BaseBinaryArray<BinaryType> { |
| public: |
| explicit BinaryArray(const std::shared_ptr<ArrayData>& data); |
|
|
| BinaryArray(int64_t length, const std::shared_ptr<Buffer>& value_offsets, |
| const std::shared_ptr<Buffer>& data, |
| const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, |
| int64_t null_count = kUnknownNullCount, int64_t offset = 0); |
|
|
| protected: |
| |
| BinaryArray() : BaseBinaryArray() {} |
| }; |
|
|
| |
| class ARROW_EXPORT StringArray : public BinaryArray { |
| public: |
| using TypeClass = StringType; |
|
|
| explicit StringArray(const std::shared_ptr<ArrayData>& data); |
|
|
| StringArray(int64_t length, const std::shared_ptr<Buffer>& value_offsets, |
| const std::shared_ptr<Buffer>& data, |
| const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, |
| int64_t null_count = kUnknownNullCount, int64_t offset = 0); |
|
|
| |
| |
| |
| Status ValidateUTF8() const; |
| }; |
|
|
| |
| class ARROW_EXPORT LargeBinaryArray : public BaseBinaryArray<LargeBinaryType> { |
| public: |
| explicit LargeBinaryArray(const std::shared_ptr<ArrayData>& data); |
|
|
| LargeBinaryArray(int64_t length, const std::shared_ptr<Buffer>& value_offsets, |
| const std::shared_ptr<Buffer>& data, |
| const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, |
| int64_t null_count = kUnknownNullCount, int64_t offset = 0); |
|
|
| protected: |
| |
| LargeBinaryArray() : BaseBinaryArray() {} |
| }; |
|
|
| |
| class ARROW_EXPORT LargeStringArray : public LargeBinaryArray { |
| public: |
| using TypeClass = LargeStringType; |
|
|
| explicit LargeStringArray(const std::shared_ptr<ArrayData>& data); |
|
|
| LargeStringArray(int64_t length, const std::shared_ptr<Buffer>& value_offsets, |
| const std::shared_ptr<Buffer>& data, |
| const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, |
| int64_t null_count = kUnknownNullCount, int64_t offset = 0); |
|
|
| |
| |
| |
| Status ValidateUTF8() const; |
| }; |
|
|
| |
| |
|
|
| |
| |
| class ARROW_EXPORT BinaryViewArray : public FlatArray { |
| public: |
| using TypeClass = BinaryViewType; |
| using IteratorType = stl::ArrayIterator<BinaryViewArray>; |
| using c_type = BinaryViewType::c_type; |
|
|
| explicit BinaryViewArray(std::shared_ptr<ArrayData> data); |
|
|
| BinaryViewArray(std::shared_ptr<DataType> type, int64_t length, |
| std::shared_ptr<Buffer> views, BufferVector data_buffers, |
| std::shared_ptr<Buffer> null_bitmap = NULLPTR, |
| int64_t null_count = kUnknownNullCount, int64_t offset = 0); |
|
|
| |
| std::string_view GetView(int64_t i) const; |
| std::string GetString(int64_t i) const { return std::string{GetView(i)}; } |
|
|
| const auto& values() const { return data_->buffers[1]; } |
| const c_type* raw_values() const { return raw_values_; } |
|
|
| std::optional<std::string_view> operator[](int64_t i) const { |
| return *IteratorType(*this, i); |
| } |
|
|
| IteratorType begin() const { return IteratorType(*this); } |
| IteratorType end() const { return IteratorType(*this, length()); } |
|
|
| protected: |
| using FlatArray::FlatArray; |
|
|
| void SetData(std::shared_ptr<ArrayData> data) { |
| FlatArray::SetData(std::move(data)); |
| raw_values_ = data_->GetValuesSafe<c_type>(1); |
| } |
|
|
| const c_type* raw_values_; |
| }; |
|
|
| |
| |
| class ARROW_EXPORT StringViewArray : public BinaryViewArray { |
| public: |
| using TypeClass = StringViewType; |
|
|
| explicit StringViewArray(std::shared_ptr<ArrayData> data); |
|
|
| using BinaryViewArray::BinaryViewArray; |
|
|
| |
| |
| |
| Status ValidateUTF8() const; |
| }; |
|
|
| |
| |
|
|
| |
| class ARROW_EXPORT FixedSizeBinaryArray : public PrimitiveArray { |
| public: |
| using TypeClass = FixedSizeBinaryType; |
| using IteratorType = stl::ArrayIterator<FixedSizeBinaryArray>; |
|
|
| explicit FixedSizeBinaryArray(const std::shared_ptr<ArrayData>& data); |
|
|
| FixedSizeBinaryArray(const std::shared_ptr<DataType>& type, int64_t length, |
| const std::shared_ptr<Buffer>& data, |
| const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, |
| int64_t null_count = kUnknownNullCount, int64_t offset = 0); |
|
|
| const uint8_t* GetValue(int64_t i) const { return values_ + i * byte_width_; } |
| const uint8_t* Value(int64_t i) const { return GetValue(i); } |
|
|
| std::string_view GetView(int64_t i) const { |
| return std::string_view(reinterpret_cast<const char*>(GetValue(i)), byte_width_); |
| } |
|
|
| std::optional<std::string_view> operator[](int64_t i) const { |
| return *IteratorType(*this, i); |
| } |
|
|
| std::string GetString(int64_t i) const { return std::string(GetView(i)); } |
|
|
| int32_t byte_width() const { return byte_width_; } |
|
|
| const uint8_t* raw_values() const { return values_; } |
|
|
| IteratorType begin() const { return IteratorType(*this); } |
|
|
| IteratorType end() const { return IteratorType(*this, length()); } |
|
|
| protected: |
| void SetData(const std::shared_ptr<ArrayData>& data) { |
| this->PrimitiveArray::SetData(data); |
| byte_width_ = |
| internal::checked_cast<const FixedSizeBinaryType&>(*type()).byte_width(); |
| values_ = raw_values_ + data_->offset * byte_width_; |
| } |
|
|
| const uint8_t* values_; |
| int32_t byte_width_; |
| }; |
|
|
| |
|
|
| } |
|
|