File indexing completed on 2025-08-27 08:47:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <atomic>
0021 #include <climits>
0022 #include <cstdint>
0023 #include <iosfwd>
0024 #include <limits>
0025 #include <memory>
0026 #include <optional>
0027 #include <string>
0028 #include <utility>
0029 #include <variant>
0030 #include <vector>
0031
0032 #include "arrow/result.h"
0033 #include "arrow/type_fwd.h" // IWYU pragma: export
0034 #include "arrow/util/checked_cast.h"
0035 #include "arrow/util/endian.h"
0036 #include "arrow/util/macros.h"
0037 #include "arrow/util/visibility.h"
0038 #include "arrow/visitor.h" // IWYU pragma: keep
0039
0040 namespace arrow {
0041 namespace detail {
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 class ARROW_EXPORT Fingerprintable {
0060 public:
0061 virtual ~Fingerprintable();
0062
0063 const std::string& fingerprint() const {
0064 auto p = fingerprint_.load();
0065 if (ARROW_PREDICT_TRUE(p != NULLPTR)) {
0066 return *p;
0067 }
0068 return LoadFingerprintSlow();
0069 }
0070
0071 const std::string& metadata_fingerprint() const {
0072 auto p = metadata_fingerprint_.load();
0073 if (ARROW_PREDICT_TRUE(p != NULLPTR)) {
0074 return *p;
0075 }
0076 return LoadMetadataFingerprintSlow();
0077 }
0078
0079 protected:
0080 const std::string& LoadFingerprintSlow() const;
0081 const std::string& LoadMetadataFingerprintSlow() const;
0082
0083 virtual std::string ComputeFingerprint() const = 0;
0084 virtual std::string ComputeMetadataFingerprint() const = 0;
0085
0086 mutable std::atomic<std::string*> fingerprint_{NULLPTR};
0087 mutable std::atomic<std::string*> metadata_fingerprint_{NULLPTR};
0088 };
0089
0090 }
0091
0092
0093 struct ARROW_EXPORT DataTypeLayout {
0094 enum BufferKind { FIXED_WIDTH, VARIABLE_WIDTH, BITMAP, ALWAYS_NULL };
0095
0096
0097 struct BufferSpec {
0098 BufferKind kind;
0099 int64_t byte_width;
0100
0101 bool operator==(const BufferSpec& other) const {
0102 return kind == other.kind &&
0103 (kind != FIXED_WIDTH || byte_width == other.byte_width);
0104 }
0105 bool operator!=(const BufferSpec& other) const { return !(*this == other); }
0106 };
0107
0108 static BufferSpec FixedWidth(int64_t w) { return BufferSpec{FIXED_WIDTH, w}; }
0109 static BufferSpec VariableWidth() { return BufferSpec{VARIABLE_WIDTH, -1}; }
0110 static BufferSpec Bitmap() { return BufferSpec{BITMAP, -1}; }
0111 static BufferSpec AlwaysNull() { return BufferSpec{ALWAYS_NULL, -1}; }
0112
0113
0114 std::vector<BufferSpec> buffers;
0115
0116 bool has_dictionary = false;
0117
0118
0119
0120 std::optional<BufferSpec> variadic_spec;
0121
0122 explicit DataTypeLayout(std::vector<BufferSpec> buffers,
0123 std::optional<BufferSpec> variadic_spec = {})
0124 : buffers(std::move(buffers)), variadic_spec(variadic_spec) {}
0125 };
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 class ARROW_EXPORT DataType : public std::enable_shared_from_this<DataType>,
0137 public detail::Fingerprintable,
0138 public util::EqualityComparable<DataType> {
0139 public:
0140 explicit DataType(Type::type id) : detail::Fingerprintable(), id_(id) {}
0141 ~DataType() override;
0142
0143
0144
0145
0146
0147 bool Equals(const DataType& other, bool check_metadata = false) const;
0148
0149
0150 bool Equals(const std::shared_ptr<DataType>& other, bool check_metadata = false) const;
0151
0152
0153 const std::shared_ptr<Field>& field(int i) const { return children_[i]; }
0154
0155
0156 const FieldVector& fields() const { return children_; }
0157
0158
0159 int num_fields() const { return static_cast<int>(children_.size()); }
0160
0161
0162 Status Accept(TypeVisitor* visitor) const;
0163
0164
0165 virtual std::string ToString(bool show_metadata = false) const = 0;
0166
0167
0168 size_t Hash() const;
0169
0170
0171
0172
0173 virtual std::string name() const = 0;
0174
0175
0176
0177
0178 virtual DataTypeLayout layout() const = 0;
0179
0180
0181 Type::type id() const { return id_; }
0182
0183
0184 virtual Type::type storage_id() const { return id_; }
0185
0186
0187
0188
0189 virtual int32_t byte_width() const {
0190 int32_t num_bits = this->bit_width();
0191 return num_bits > 0 ? num_bits / 8 : -1;
0192 }
0193
0194
0195
0196
0197 virtual int bit_width() const { return -1; }
0198
0199
0200
0201 std::shared_ptr<DataType> GetSharedPtr() const {
0202 return const_cast<DataType*>(this)->shared_from_this();
0203 }
0204
0205 protected:
0206
0207
0208 std::string ComputeFingerprint() const override;
0209
0210
0211 std::string ComputeMetadataFingerprint() const override;
0212
0213 Type::type id_;
0214 FieldVector children_;
0215
0216 private:
0217 ARROW_DISALLOW_COPY_AND_ASSIGN(DataType);
0218 };
0219
0220
0221
0222 struct ARROW_EXPORT TypeHolder {
0223 const DataType* type = NULLPTR;
0224 std::shared_ptr<DataType> owned_type;
0225
0226 TypeHolder() = default;
0227 TypeHolder(const TypeHolder& other) = default;
0228 TypeHolder& operator=(const TypeHolder& other) = default;
0229 TypeHolder(TypeHolder&& other) = default;
0230 TypeHolder& operator=(TypeHolder&& other) = default;
0231
0232 TypeHolder(std::shared_ptr<DataType> owned_type)
0233 : type(owned_type.get()), owned_type(std::move(owned_type)) {}
0234
0235 TypeHolder(const DataType* type)
0236 : type(type) {}
0237
0238 Type::type id() const { return this->type->id(); }
0239
0240 std::shared_ptr<DataType> GetSharedPtr() const {
0241 return this->type != NULLPTR ? this->type->GetSharedPtr() : NULLPTR;
0242 }
0243
0244 const DataType& operator*() const { return *this->type; }
0245
0246 operator bool() const { return this->type != NULLPTR; }
0247
0248 bool operator==(const TypeHolder& other) const {
0249 if (type == other.type) return true;
0250 if (type == NULLPTR || other.type == NULLPTR) return false;
0251 return type->Equals(*other.type);
0252 }
0253
0254 bool operator==(decltype(NULLPTR)) const { return this->type == NULLPTR; }
0255
0256 bool operator==(const DataType& other) const {
0257 if (this->type == NULLPTR) return false;
0258 return other.Equals(*this->type);
0259 }
0260
0261 bool operator!=(const DataType& other) const { return !(*this == other); }
0262
0263 bool operator==(const std::shared_ptr<DataType>& other) const {
0264 return *this == *other;
0265 }
0266
0267 bool operator!=(const TypeHolder& other) const { return !(*this == other); }
0268
0269 std::string ToString(bool show_metadata = false) const {
0270 return this->type ? this->type->ToString(show_metadata) : "<NULLPTR>";
0271 }
0272
0273 static std::string ToString(const std::vector<TypeHolder>&, bool show_metadata = false);
0274
0275 static std::vector<TypeHolder> FromTypes(
0276 const std::vector<std::shared_ptr<DataType>>& types);
0277 };
0278
0279 ARROW_EXPORT
0280 std::ostream& operator<<(std::ostream& os, const DataType& type);
0281
0282 ARROW_EXPORT
0283 std::ostream& operator<<(std::ostream& os, const TypeHolder& type);
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295 std::shared_ptr<DataType> GetPhysicalType(const std::shared_ptr<DataType>& type);
0296
0297
0298 class ARROW_EXPORT FixedWidthType : public DataType {
0299 public:
0300 using DataType::DataType;
0301
0302
0303 ~FixedWidthType() override;
0304 };
0305
0306
0307 class ARROW_EXPORT PrimitiveCType : public FixedWidthType {
0308 public:
0309 using FixedWidthType::FixedWidthType;
0310
0311
0312 ~PrimitiveCType() override;
0313 };
0314
0315
0316 class ARROW_EXPORT NumberType : public PrimitiveCType {
0317 public:
0318 using PrimitiveCType::PrimitiveCType;
0319
0320
0321 ~NumberType() override;
0322 };
0323
0324
0325 class ARROW_EXPORT IntegerType : public NumberType {
0326 public:
0327 using NumberType::NumberType;
0328
0329
0330 ~IntegerType() override;
0331 virtual bool is_signed() const = 0;
0332 };
0333
0334
0335 class ARROW_EXPORT FloatingPointType : public NumberType {
0336 public:
0337 using NumberType::NumberType;
0338
0339
0340 ~FloatingPointType() override;
0341 enum Precision { HALF, SINGLE, DOUBLE };
0342 virtual Precision precision() const = 0;
0343 };
0344
0345
0346 class ParametricType {};
0347
0348 class ARROW_EXPORT NestedType : public DataType, public ParametricType {
0349 public:
0350 using DataType::DataType;
0351
0352
0353 ~NestedType() override;
0354 };
0355
0356
0357
0358
0359
0360
0361
0362
0363 class ARROW_EXPORT Field : public detail::Fingerprintable,
0364 public util::EqualityComparable<Field> {
0365 public:
0366 Field(std::string name, std::shared_ptr<DataType> type, bool nullable = true,
0367 std::shared_ptr<const KeyValueMetadata> metadata = NULLPTR)
0368 : detail::Fingerprintable(),
0369 name_(std::move(name)),
0370 type_(std::move(type)),
0371 nullable_(nullable),
0372 metadata_(std::move(metadata)) {}
0373
0374 ~Field() override;
0375
0376
0377 std::shared_ptr<const KeyValueMetadata> metadata() const { return metadata_; }
0378
0379
0380 bool HasMetadata() const;
0381
0382
0383 std::shared_ptr<Field> WithMetadata(
0384 const std::shared_ptr<const KeyValueMetadata>& metadata) const;
0385
0386
0387
0388
0389 std::shared_ptr<Field> WithMergedMetadata(
0390 const std::shared_ptr<const KeyValueMetadata>& metadata) const;
0391
0392
0393 std::shared_ptr<Field> RemoveMetadata() const;
0394
0395
0396 std::shared_ptr<Field> WithType(const std::shared_ptr<DataType>& type) const;
0397
0398
0399 std::shared_ptr<Field> WithName(const std::string& name) const;
0400
0401
0402 std::shared_ptr<Field> WithNullable(bool nullable) const;
0403
0404
0405
0406
0407 struct ARROW_EXPORT MergeOptions : public util::ToStringOstreamable<MergeOptions> {
0408
0409
0410
0411
0412 bool promote_nullability = true;
0413
0414
0415
0416
0417 bool promote_decimal = false;
0418
0419
0420
0421 bool promote_decimal_to_float = false;
0422
0423
0424
0425
0426
0427 bool promote_integer_to_decimal = false;
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437 bool promote_integer_to_float = false;
0438
0439
0440
0441
0442
0443
0444 bool promote_integer_sign = false;
0445
0446
0447
0448 bool promote_numeric_width = false;
0449
0450
0451
0452
0453 bool promote_binary = false;
0454
0455
0456 bool promote_temporal_unit = false;
0457
0458
0459
0460 bool promote_list = false;
0461
0462
0463 bool promote_dictionary = false;
0464
0465
0466
0467
0468 bool promote_dictionary_ordered = false;
0469
0470
0471 static MergeOptions Defaults() { return MergeOptions(); }
0472
0473
0474 static MergeOptions Permissive();
0475
0476 std::string ToString() const;
0477 };
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487 Result<std::shared_ptr<Field>> MergeWith(
0488 const Field& other, MergeOptions options = MergeOptions::Defaults()) const;
0489 Result<std::shared_ptr<Field>> MergeWith(
0490 const std::shared_ptr<Field>& other,
0491 MergeOptions options = MergeOptions::Defaults()) const;
0492
0493 FieldVector Flatten() const;
0494
0495
0496
0497
0498
0499
0500
0501
0502 bool Equals(const Field& other, bool check_metadata = false) const;
0503 bool Equals(const std::shared_ptr<Field>& other, bool check_metadata = false) const;
0504
0505
0506
0507
0508
0509
0510 bool IsCompatibleWith(const Field& other) const;
0511 bool IsCompatibleWith(const std::shared_ptr<Field>& other) const;
0512
0513
0514
0515
0516 std::string ToString(bool show_metadata = false) const;
0517
0518
0519 const std::string& name() const { return name_; }
0520
0521 const std::shared_ptr<DataType>& type() const { return type_; }
0522
0523 bool nullable() const { return nullable_; }
0524
0525 std::shared_ptr<Field> Copy() const;
0526
0527 private:
0528 std::string ComputeFingerprint() const override;
0529 std::string ComputeMetadataFingerprint() const override;
0530
0531
0532 std::string name_;
0533
0534
0535 std::shared_ptr<DataType> type_;
0536
0537
0538 bool nullable_;
0539
0540
0541 std::shared_ptr<const KeyValueMetadata> metadata_;
0542
0543 ARROW_DISALLOW_COPY_AND_ASSIGN(Field);
0544 };
0545
0546 ARROW_EXPORT void PrintTo(const Field& field, std::ostream* os);
0547
0548 namespace detail {
0549
0550 template <typename DERIVED, typename BASE, Type::type TYPE_ID, typename C_TYPE>
0551 class CTypeImpl : public BASE {
0552 public:
0553 static constexpr Type::type type_id = TYPE_ID;
0554 using c_type = C_TYPE;
0555 using PhysicalType = DERIVED;
0556
0557 CTypeImpl() : BASE(TYPE_ID) {}
0558
0559 int bit_width() const override { return static_cast<int>(sizeof(C_TYPE) * CHAR_BIT); }
0560
0561 DataTypeLayout layout() const override {
0562 return DataTypeLayout(
0563 {DataTypeLayout::Bitmap(), DataTypeLayout::FixedWidth(sizeof(C_TYPE))});
0564 }
0565
0566 std::string name() const override { return DERIVED::type_name(); }
0567
0568 std::string ToString(bool show_metadata = false) const override { return this->name(); }
0569 };
0570
0571 template <typename DERIVED, typename BASE, Type::type TYPE_ID, typename C_TYPE>
0572 constexpr Type::type CTypeImpl<DERIVED, BASE, TYPE_ID, C_TYPE>::type_id;
0573
0574 template <typename DERIVED, Type::type TYPE_ID, typename C_TYPE>
0575 class IntegerTypeImpl : public detail::CTypeImpl<DERIVED, IntegerType, TYPE_ID, C_TYPE> {
0576 bool is_signed() const override { return std::is_signed<C_TYPE>::value; }
0577 };
0578
0579 }
0580
0581
0582 class ARROW_EXPORT NullType : public DataType {
0583 public:
0584 static constexpr Type::type type_id = Type::NA;
0585
0586 static constexpr const char* type_name() { return "null"; }
0587
0588 NullType() : DataType(Type::NA) {}
0589
0590 std::string ToString(bool show_metadata = false) const override;
0591
0592 DataTypeLayout layout() const override {
0593 return DataTypeLayout({DataTypeLayout::AlwaysNull()});
0594 }
0595
0596 std::string name() const override { return "null"; }
0597
0598 protected:
0599 std::string ComputeFingerprint() const override;
0600 };
0601
0602
0603 class ARROW_EXPORT BooleanType
0604 : public detail::CTypeImpl<BooleanType, PrimitiveCType, Type::BOOL, bool> {
0605 public:
0606 static constexpr const char* type_name() { return "bool"; }
0607
0608
0609 int bit_width() const final { return 1; }
0610
0611 DataTypeLayout layout() const override {
0612 return DataTypeLayout({DataTypeLayout::Bitmap(), DataTypeLayout::Bitmap()});
0613 }
0614
0615 protected:
0616 std::string ComputeFingerprint() const override;
0617 };
0618
0619
0620
0621
0622
0623
0624 class ARROW_EXPORT UInt8Type
0625 : public detail::IntegerTypeImpl<UInt8Type, Type::UINT8, uint8_t> {
0626 public:
0627 static constexpr const char* type_name() { return "uint8"; }
0628
0629 protected:
0630 std::string ComputeFingerprint() const override;
0631 };
0632
0633
0634 class ARROW_EXPORT Int8Type
0635 : public detail::IntegerTypeImpl<Int8Type, Type::INT8, int8_t> {
0636 public:
0637 static constexpr const char* type_name() { return "int8"; }
0638
0639 protected:
0640 std::string ComputeFingerprint() const override;
0641 };
0642
0643
0644 class ARROW_EXPORT UInt16Type
0645 : public detail::IntegerTypeImpl<UInt16Type, Type::UINT16, uint16_t> {
0646 public:
0647 static constexpr const char* type_name() { return "uint16"; }
0648
0649 protected:
0650 std::string ComputeFingerprint() const override;
0651 };
0652
0653
0654 class ARROW_EXPORT Int16Type
0655 : public detail::IntegerTypeImpl<Int16Type, Type::INT16, int16_t> {
0656 public:
0657 static constexpr const char* type_name() { return "int16"; }
0658
0659 protected:
0660 std::string ComputeFingerprint() const override;
0661 };
0662
0663
0664 class ARROW_EXPORT UInt32Type
0665 : public detail::IntegerTypeImpl<UInt32Type, Type::UINT32, uint32_t> {
0666 public:
0667 static constexpr const char* type_name() { return "uint32"; }
0668
0669 protected:
0670 std::string ComputeFingerprint() const override;
0671 };
0672
0673
0674 class ARROW_EXPORT Int32Type
0675 : public detail::IntegerTypeImpl<Int32Type, Type::INT32, int32_t> {
0676 public:
0677 static constexpr const char* type_name() { return "int32"; }
0678
0679 protected:
0680 std::string ComputeFingerprint() const override;
0681 };
0682
0683
0684 class ARROW_EXPORT UInt64Type
0685 : public detail::IntegerTypeImpl<UInt64Type, Type::UINT64, uint64_t> {
0686 public:
0687 static constexpr const char* type_name() { return "uint64"; }
0688
0689 protected:
0690 std::string ComputeFingerprint() const override;
0691 };
0692
0693
0694 class ARROW_EXPORT Int64Type
0695 : public detail::IntegerTypeImpl<Int64Type, Type::INT64, int64_t> {
0696 public:
0697 static constexpr const char* type_name() { return "int64"; }
0698
0699 protected:
0700 std::string ComputeFingerprint() const override;
0701 };
0702
0703
0704 class ARROW_EXPORT HalfFloatType
0705 : public detail::CTypeImpl<HalfFloatType, FloatingPointType, Type::HALF_FLOAT,
0706 uint16_t> {
0707 public:
0708 Precision precision() const override;
0709 static constexpr const char* type_name() { return "halffloat"; }
0710
0711 protected:
0712 std::string ComputeFingerprint() const override;
0713 };
0714
0715
0716 class ARROW_EXPORT FloatType
0717 : public detail::CTypeImpl<FloatType, FloatingPointType, Type::FLOAT, float> {
0718 public:
0719 Precision precision() const override;
0720 static constexpr const char* type_name() { return "float"; }
0721
0722 protected:
0723 std::string ComputeFingerprint() const override;
0724 };
0725
0726
0727 class ARROW_EXPORT DoubleType
0728 : public detail::CTypeImpl<DoubleType, FloatingPointType, Type::DOUBLE, double> {
0729 public:
0730 Precision precision() const override;
0731 static constexpr const char* type_name() { return "double"; }
0732
0733 protected:
0734 std::string ComputeFingerprint() const override;
0735 };
0736
0737
0738
0739
0740 class ARROW_EXPORT BaseBinaryType : public DataType {
0741 public:
0742 using DataType::DataType;
0743
0744
0745 ~BaseBinaryType() override;
0746 };
0747
0748 constexpr int64_t kBinaryMemoryLimit = std::numeric_limits<int32_t>::max() - 1;
0749
0750
0751
0752
0753
0754
0755 class ARROW_EXPORT BinaryType : public BaseBinaryType {
0756 public:
0757 static constexpr Type::type type_id = Type::BINARY;
0758 static constexpr bool is_utf8 = false;
0759 using offset_type = int32_t;
0760 using PhysicalType = BinaryType;
0761
0762 static constexpr const char* type_name() { return "binary"; }
0763
0764 BinaryType() : BinaryType(Type::BINARY) {}
0765
0766 DataTypeLayout layout() const override {
0767 return DataTypeLayout({DataTypeLayout::Bitmap(),
0768 DataTypeLayout::FixedWidth(sizeof(offset_type)),
0769 DataTypeLayout::VariableWidth()});
0770 }
0771
0772 std::string ToString(bool show_metadata = false) const override;
0773 std::string name() const override { return "binary"; }
0774
0775 protected:
0776 std::string ComputeFingerprint() const override;
0777
0778
0779 explicit BinaryType(Type::type logical_type) : BaseBinaryType(logical_type) {}
0780 };
0781
0782
0783 class ARROW_EXPORT BinaryViewType : public DataType {
0784 public:
0785 static constexpr Type::type type_id = Type::BINARY_VIEW;
0786 static constexpr bool is_utf8 = false;
0787 using PhysicalType = BinaryViewType;
0788
0789 static constexpr int kSize = 16;
0790 static constexpr int kInlineSize = 12;
0791 static constexpr int kPrefixSize = 4;
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823 union alignas(int64_t) c_type {
0824 struct {
0825 int32_t size;
0826 std::array<uint8_t, kInlineSize> data;
0827 } inlined;
0828
0829 struct {
0830 int32_t size;
0831 std::array<uint8_t, kPrefixSize> prefix;
0832 int32_t buffer_index;
0833 int32_t offset;
0834 } ref;
0835
0836
0837 int32_t size() const {
0838
0839
0840 return inlined.size;
0841 }
0842
0843
0844 bool is_inline() const { return size() <= kInlineSize; }
0845
0846
0847
0848
0849
0850 const uint8_t* inline_data() const& {
0851
0852
0853 return is_inline() ? inlined.data.data() : ref.prefix.data();
0854 }
0855 const uint8_t* inline_data() && = delete;
0856 };
0857 static_assert(sizeof(c_type) == kSize);
0858 static_assert(std::is_trivial_v<c_type>);
0859
0860 static constexpr const char* type_name() { return "binary_view"; }
0861
0862 BinaryViewType() : BinaryViewType(Type::BINARY_VIEW) {}
0863
0864 DataTypeLayout layout() const override {
0865 return DataTypeLayout({DataTypeLayout::Bitmap(), DataTypeLayout::FixedWidth(kSize)},
0866 DataTypeLayout::VariableWidth());
0867 }
0868
0869 std::string ToString(bool show_metadata = false) const override;
0870 std::string name() const override { return "binary_view"; }
0871
0872 protected:
0873 std::string ComputeFingerprint() const override;
0874
0875
0876 explicit BinaryViewType(Type::type logical_type) : DataType(logical_type) {}
0877 };
0878
0879
0880 class ARROW_EXPORT LargeBinaryType : public BaseBinaryType {
0881 public:
0882 static constexpr Type::type type_id = Type::LARGE_BINARY;
0883 static constexpr bool is_utf8 = false;
0884 using offset_type = int64_t;
0885 using PhysicalType = LargeBinaryType;
0886
0887 static constexpr const char* type_name() { return "large_binary"; }
0888
0889 LargeBinaryType() : LargeBinaryType(Type::LARGE_BINARY) {}
0890
0891 DataTypeLayout layout() const override {
0892 return DataTypeLayout({DataTypeLayout::Bitmap(),
0893 DataTypeLayout::FixedWidth(sizeof(offset_type)),
0894 DataTypeLayout::VariableWidth()});
0895 }
0896
0897 std::string ToString(bool show_metadata = false) const override;
0898 std::string name() const override { return "large_binary"; }
0899
0900 protected:
0901 std::string ComputeFingerprint() const override;
0902
0903
0904 explicit LargeBinaryType(Type::type logical_type) : BaseBinaryType(logical_type) {}
0905 };
0906
0907
0908 class ARROW_EXPORT StringType : public BinaryType {
0909 public:
0910 static constexpr Type::type type_id = Type::STRING;
0911 static constexpr bool is_utf8 = true;
0912 using PhysicalType = BinaryType;
0913
0914 static constexpr const char* type_name() { return "utf8"; }
0915
0916 StringType() : BinaryType(Type::STRING) {}
0917
0918 std::string ToString(bool show_metadata = false) const override;
0919 std::string name() const override { return "utf8"; }
0920
0921 protected:
0922 std::string ComputeFingerprint() const override;
0923 };
0924
0925
0926 class ARROW_EXPORT StringViewType : public BinaryViewType {
0927 public:
0928 static constexpr Type::type type_id = Type::STRING_VIEW;
0929 static constexpr bool is_utf8 = true;
0930 using PhysicalType = BinaryViewType;
0931
0932 static constexpr const char* type_name() { return "utf8_view"; }
0933
0934 StringViewType() : BinaryViewType(Type::STRING_VIEW) {}
0935
0936 std::string ToString(bool show_metadata = false) const override;
0937 std::string name() const override { return "utf8_view"; }
0938
0939 protected:
0940 std::string ComputeFingerprint() const override;
0941 };
0942
0943
0944 class ARROW_EXPORT LargeStringType : public LargeBinaryType {
0945 public:
0946 static constexpr Type::type type_id = Type::LARGE_STRING;
0947 static constexpr bool is_utf8 = true;
0948 using PhysicalType = LargeBinaryType;
0949
0950 static constexpr const char* type_name() { return "large_utf8"; }
0951
0952 LargeStringType() : LargeBinaryType(Type::LARGE_STRING) {}
0953
0954 std::string ToString(bool show_metadata = false) const override;
0955 std::string name() const override { return "large_utf8"; }
0956
0957 protected:
0958 std::string ComputeFingerprint() const override;
0959 };
0960
0961
0962 class ARROW_EXPORT FixedSizeBinaryType : public FixedWidthType, public ParametricType {
0963 public:
0964 static constexpr Type::type type_id = Type::FIXED_SIZE_BINARY;
0965 static constexpr bool is_utf8 = false;
0966
0967 static constexpr const char* type_name() { return "fixed_size_binary"; }
0968
0969 explicit FixedSizeBinaryType(int32_t byte_width)
0970 : FixedWidthType(Type::FIXED_SIZE_BINARY), byte_width_(byte_width) {}
0971 explicit FixedSizeBinaryType(int32_t byte_width, Type::type override_type_id)
0972 : FixedWidthType(override_type_id), byte_width_(byte_width) {}
0973
0974 std::string ToString(bool show_metadata = false) const override;
0975 std::string name() const override { return "fixed_size_binary"; }
0976
0977 DataTypeLayout layout() const override {
0978 return DataTypeLayout(
0979 {DataTypeLayout::Bitmap(), DataTypeLayout::FixedWidth(byte_width())});
0980 }
0981
0982 int byte_width() const override { return byte_width_; }
0983
0984 int bit_width() const override;
0985
0986
0987 static Result<std::shared_ptr<DataType>> Make(int32_t byte_width);
0988
0989 protected:
0990 std::string ComputeFingerprint() const override;
0991
0992 int32_t byte_width_;
0993 };
0994
0995
0996
0997
0998
0999
1000
1001
1002 class ARROW_EXPORT DecimalType : public FixedSizeBinaryType {
1003 public:
1004 explicit DecimalType(Type::type type_id, int32_t byte_width, int32_t precision,
1005 int32_t scale)
1006 : FixedSizeBinaryType(byte_width, type_id), precision_(precision), scale_(scale) {}
1007
1008
1009 static Result<std::shared_ptr<DataType>> Make(Type::type type_id, int32_t precision,
1010 int32_t scale);
1011
1012 int32_t precision() const { return precision_; }
1013 int32_t scale() const { return scale_; }
1014
1015
1016
1017
1018 static int32_t DecimalSize(int32_t precision);
1019
1020 protected:
1021 std::string ComputeFingerprint() const override;
1022
1023 int32_t precision_;
1024 int32_t scale_;
1025 };
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042 class ARROW_EXPORT Decimal32Type : public DecimalType {
1043 public:
1044 static constexpr Type::type type_id = Type::DECIMAL32;
1045
1046 static constexpr const char* type_name() { return "decimal32"; }
1047
1048
1049 explicit Decimal32Type(int32_t precision, int32_t scale);
1050
1051
1052 static Result<std::shared_ptr<DataType>> Make(int32_t precision, int32_t scale);
1053
1054 std::string ToString(bool show_metadata = false) const override;
1055 std::string name() const override { return "decimal32"; }
1056
1057 static constexpr int32_t kMinPrecision = 1;
1058 static constexpr int32_t kMaxPrecision = 9;
1059 static constexpr int32_t kByteWidth = 4;
1060 };
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077 class ARROW_EXPORT Decimal64Type : public DecimalType {
1078 public:
1079 static constexpr Type::type type_id = Type::DECIMAL64;
1080
1081 static constexpr const char* type_name() { return "decimal64"; }
1082
1083
1084 explicit Decimal64Type(int32_t precision, int32_t scale);
1085
1086
1087 static Result<std::shared_ptr<DataType>> Make(int32_t precision, int32_t scale);
1088
1089 std::string ToString(bool show_metadata = false) const override;
1090 std::string name() const override { return "decimal64"; }
1091
1092 static constexpr int32_t kMinPrecision = 1;
1093 static constexpr int32_t kMaxPrecision = 18;
1094 static constexpr int32_t kByteWidth = 8;
1095 };
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111 class ARROW_EXPORT Decimal128Type : public DecimalType {
1112 public:
1113 static constexpr Type::type type_id = Type::DECIMAL128;
1114
1115 static constexpr const char* type_name() { return "decimal128"; }
1116
1117
1118 explicit Decimal128Type(int32_t precision, int32_t scale);
1119
1120
1121 static Result<std::shared_ptr<DataType>> Make(int32_t precision, int32_t scale);
1122
1123 std::string ToString(bool show_metadata = false) const override;
1124 std::string name() const override { return "decimal128"; }
1125
1126 static constexpr int32_t kMinPrecision = 1;
1127 static constexpr int32_t kMaxPrecision = 38;
1128 static constexpr int32_t kByteWidth = 16;
1129 };
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144 class ARROW_EXPORT Decimal256Type : public DecimalType {
1145 public:
1146 static constexpr Type::type type_id = Type::DECIMAL256;
1147
1148 static constexpr const char* type_name() { return "decimal256"; }
1149
1150
1151 explicit Decimal256Type(int32_t precision, int32_t scale);
1152
1153
1154 static Result<std::shared_ptr<DataType>> Make(int32_t precision, int32_t scale);
1155
1156 std::string ToString(bool show_metadata = false) const override;
1157 std::string name() const override { return "decimal256"; }
1158
1159 static constexpr int32_t kMinPrecision = 1;
1160 static constexpr int32_t kMaxPrecision = 76;
1161 static constexpr int32_t kByteWidth = 32;
1162 };
1163
1164
1165
1166
1167
1168
1169
1170
1171 class ARROW_EXPORT BaseListType : public NestedType {
1172 public:
1173 using NestedType::NestedType;
1174
1175
1176 ~BaseListType() override;
1177 const std::shared_ptr<Field>& value_field() const { return children_[0]; }
1178
1179 const std::shared_ptr<DataType>& value_type() const { return children_[0]->type(); }
1180 };
1181
1182
1183
1184
1185
1186
1187 class ARROW_EXPORT ListType : public BaseListType {
1188 public:
1189 static constexpr Type::type type_id = Type::LIST;
1190 using offset_type = int32_t;
1191
1192 static constexpr const char* type_name() { return "list"; }
1193
1194
1195 explicit ListType(std::shared_ptr<DataType> value_type)
1196 : ListType(std::make_shared<Field>("item", std::move(value_type))) {}
1197
1198 explicit ListType(std::shared_ptr<Field> value_field) : BaseListType(type_id) {
1199 children_ = {std::move(value_field)};
1200 }
1201
1202 DataTypeLayout layout() const override {
1203 return DataTypeLayout(
1204 {DataTypeLayout::Bitmap(), DataTypeLayout::FixedWidth(sizeof(offset_type))});
1205 }
1206
1207 std::string ToString(bool show_metadata = false) const override;
1208
1209 std::string name() const override { return "list"; }
1210
1211 protected:
1212 std::string ComputeFingerprint() const override;
1213 };
1214
1215
1216
1217
1218 class ARROW_EXPORT LargeListType : public BaseListType {
1219 public:
1220 static constexpr Type::type type_id = Type::LARGE_LIST;
1221 using offset_type = int64_t;
1222
1223 static constexpr const char* type_name() { return "large_list"; }
1224
1225
1226 explicit LargeListType(std::shared_ptr<DataType> value_type)
1227 : LargeListType(std::make_shared<Field>("item", std::move(value_type))) {}
1228
1229 explicit LargeListType(std::shared_ptr<Field> value_field) : BaseListType(type_id) {
1230 children_ = {std::move(value_field)};
1231 }
1232
1233 DataTypeLayout layout() const override {
1234 return DataTypeLayout(
1235 {DataTypeLayout::Bitmap(), DataTypeLayout::FixedWidth(sizeof(offset_type))});
1236 }
1237
1238 std::string ToString(bool show_metadata = false) const override;
1239
1240 std::string name() const override { return "large_list"; }
1241
1242 protected:
1243 std::string ComputeFingerprint() const override;
1244 };
1245
1246
1247 class ARROW_EXPORT ListViewType : public BaseListType {
1248 public:
1249 static constexpr Type::type type_id = Type::LIST_VIEW;
1250 using offset_type = int32_t;
1251
1252 static constexpr const char* type_name() { return "list_view"; }
1253
1254
1255 explicit ListViewType(const std::shared_ptr<DataType>& value_type)
1256 : ListViewType(std::make_shared<Field>("item", value_type)) {}
1257
1258 explicit ListViewType(const std::shared_ptr<Field>& value_field)
1259 : BaseListType(type_id) {
1260 children_ = {value_field};
1261 }
1262
1263 DataTypeLayout layout() const override {
1264 return DataTypeLayout({DataTypeLayout::Bitmap(),
1265 DataTypeLayout::FixedWidth(sizeof(offset_type)),
1266 DataTypeLayout::FixedWidth(sizeof(offset_type))});
1267 }
1268
1269 std::string ToString(bool show_metadata = false) const override;
1270
1271 std::string name() const override { return "list_view"; }
1272
1273 protected:
1274 std::string ComputeFingerprint() const override;
1275 };
1276
1277
1278
1279
1280
1281 class ARROW_EXPORT LargeListViewType : public BaseListType {
1282 public:
1283 static constexpr Type::type type_id = Type::LARGE_LIST_VIEW;
1284 using offset_type = int64_t;
1285
1286 static constexpr const char* type_name() { return "large_list_view"; }
1287
1288
1289 explicit LargeListViewType(const std::shared_ptr<DataType>& value_type)
1290 : LargeListViewType(std::make_shared<Field>("item", value_type)) {}
1291
1292 explicit LargeListViewType(const std::shared_ptr<Field>& value_field)
1293 : BaseListType(type_id) {
1294 children_ = {value_field};
1295 }
1296
1297 DataTypeLayout layout() const override {
1298 return DataTypeLayout({DataTypeLayout::Bitmap(),
1299 DataTypeLayout::FixedWidth(sizeof(offset_type)),
1300 DataTypeLayout::FixedWidth(sizeof(offset_type))});
1301 }
1302
1303 std::string ToString(bool show_metadata = false) const override;
1304
1305 std::string name() const override { return "large_list_view"; }
1306
1307 protected:
1308 std::string ComputeFingerprint() const override;
1309 };
1310
1311
1312
1313
1314
1315
1316
1317
1318 class ARROW_EXPORT MapType : public ListType {
1319 public:
1320 static constexpr Type::type type_id = Type::MAP;
1321
1322 static constexpr const char* type_name() { return "map"; }
1323
1324 MapType(std::shared_ptr<DataType> key_type, std::shared_ptr<DataType> item_type,
1325 bool keys_sorted = false);
1326
1327 MapType(std::shared_ptr<DataType> key_type, std::shared_ptr<Field> item_field,
1328 bool keys_sorted = false);
1329
1330 MapType(std::shared_ptr<Field> key_field, std::shared_ptr<Field> item_field,
1331 bool keys_sorted = false);
1332
1333 explicit MapType(std::shared_ptr<Field> value_field, bool keys_sorted = false);
1334
1335
1336 static Result<std::shared_ptr<DataType>> Make(std::shared_ptr<Field> value_field,
1337 bool keys_sorted = false);
1338
1339 std::shared_ptr<Field> key_field() const { return value_type()->field(0); }
1340 std::shared_ptr<DataType> key_type() const { return key_field()->type(); }
1341
1342 std::shared_ptr<Field> item_field() const { return value_type()->field(1); }
1343 std::shared_ptr<DataType> item_type() const { return item_field()->type(); }
1344
1345 std::string ToString(bool show_metadata = false) const override;
1346
1347 std::string name() const override { return "map"; }
1348
1349 bool keys_sorted() const { return keys_sorted_; }
1350
1351 private:
1352 std::string ComputeFingerprint() const override;
1353
1354 bool keys_sorted_;
1355 };
1356
1357
1358 class ARROW_EXPORT FixedSizeListType : public BaseListType {
1359 public:
1360 static constexpr Type::type type_id = Type::FIXED_SIZE_LIST;
1361
1362
1363 using offset_type = int64_t;
1364
1365 static constexpr const char* type_name() { return "fixed_size_list"; }
1366
1367
1368 FixedSizeListType(std::shared_ptr<DataType> value_type, int32_t list_size)
1369 : FixedSizeListType(std::make_shared<Field>("item", std::move(value_type)),
1370 list_size) {}
1371
1372 FixedSizeListType(std::shared_ptr<Field> value_field, int32_t list_size)
1373 : BaseListType(type_id), list_size_(list_size) {
1374 children_ = {std::move(value_field)};
1375 }
1376
1377 DataTypeLayout layout() const override {
1378 return DataTypeLayout({DataTypeLayout::Bitmap()});
1379 }
1380
1381 std::string ToString(bool show_metadata = false) const override;
1382
1383 std::string name() const override { return "fixed_size_list"; }
1384
1385 int32_t list_size() const { return list_size_; }
1386
1387 protected:
1388 std::string ComputeFingerprint() const override;
1389
1390 int32_t list_size_;
1391 };
1392
1393
1394 class ARROW_EXPORT StructType : public NestedType {
1395 public:
1396 static constexpr Type::type type_id = Type::STRUCT;
1397
1398 static constexpr const char* type_name() { return "struct"; }
1399
1400 explicit StructType(const FieldVector& fields);
1401
1402 ~StructType() override;
1403
1404 DataTypeLayout layout() const override {
1405 return DataTypeLayout({DataTypeLayout::Bitmap()});
1406 }
1407
1408 std::string ToString(bool show_metadata = false) const override;
1409 std::string name() const override { return "struct"; }
1410
1411
1412 std::shared_ptr<Field> GetFieldByName(const std::string& name) const;
1413
1414
1415 FieldVector GetAllFieldsByName(const std::string& name) const;
1416
1417
1418
1419 int GetFieldIndex(const std::string& name) const;
1420
1421
1422 std::vector<int> GetAllFieldIndices(const std::string& name) const;
1423
1424
1425 Result<std::shared_ptr<StructType>> AddField(int i,
1426 const std::shared_ptr<Field>& field) const;
1427
1428 Result<std::shared_ptr<StructType>> RemoveField(int i) const;
1429
1430 Result<std::shared_ptr<StructType>> SetField(int i,
1431 const std::shared_ptr<Field>& field) const;
1432
1433 private:
1434 std::string ComputeFingerprint() const override;
1435
1436 class Impl;
1437 std::unique_ptr<Impl> impl_;
1438 };
1439
1440
1441 class ARROW_EXPORT UnionType : public NestedType {
1442 public:
1443 static constexpr int8_t kMaxTypeCode = 127;
1444 static constexpr int kInvalidChildId = -1;
1445
1446 static Result<std::shared_ptr<DataType>> Make(
1447 const FieldVector& fields, const std::vector<int8_t>& type_codes,
1448 UnionMode::type mode = UnionMode::SPARSE) {
1449 if (mode == UnionMode::SPARSE) {
1450 return sparse_union(fields, type_codes);
1451 } else {
1452 return dense_union(fields, type_codes);
1453 }
1454 }
1455
1456 DataTypeLayout layout() const override;
1457
1458 std::string ToString(bool show_metadata = false) const override;
1459
1460
1461
1462
1463
1464 const std::vector<int8_t>& type_codes() const { return type_codes_; }
1465
1466
1467 const std::vector<int>& child_ids() const { return child_ids_; }
1468
1469 uint8_t max_type_code() const;
1470
1471 UnionMode::type mode() const;
1472
1473 protected:
1474 UnionType(FieldVector fields, std::vector<int8_t> type_codes, Type::type id);
1475
1476 static Status ValidateParameters(const FieldVector& fields,
1477 const std::vector<int8_t>& type_codes,
1478 UnionMode::type mode);
1479
1480 private:
1481 std::string ComputeFingerprint() const override;
1482
1483 std::vector<int8_t> type_codes_;
1484 std::vector<int> child_ids_;
1485 };
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498 class ARROW_EXPORT SparseUnionType : public UnionType {
1499 public:
1500 static constexpr Type::type type_id = Type::SPARSE_UNION;
1501
1502 static constexpr const char* type_name() { return "sparse_union"; }
1503
1504 SparseUnionType(FieldVector fields, std::vector<int8_t> type_codes);
1505
1506
1507 static Result<std::shared_ptr<DataType>> Make(FieldVector fields,
1508 std::vector<int8_t> type_codes);
1509
1510 std::string name() const override { return "sparse_union"; }
1511 };
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527 class ARROW_EXPORT DenseUnionType : public UnionType {
1528 public:
1529 static constexpr Type::type type_id = Type::DENSE_UNION;
1530
1531 static constexpr const char* type_name() { return "dense_union"; }
1532
1533 DenseUnionType(FieldVector fields, std::vector<int8_t> type_codes);
1534
1535
1536 static Result<std::shared_ptr<DataType>> Make(FieldVector fields,
1537 std::vector<int8_t> type_codes);
1538
1539 std::string name() const override { return "dense_union"; }
1540 };
1541
1542
1543 class ARROW_EXPORT RunEndEncodedType : public NestedType {
1544 public:
1545 static constexpr Type::type type_id = Type::RUN_END_ENCODED;
1546
1547 static constexpr const char* type_name() { return "run_end_encoded"; }
1548
1549 explicit RunEndEncodedType(std::shared_ptr<DataType> run_end_type,
1550 std::shared_ptr<DataType> value_type);
1551 ~RunEndEncodedType() override;
1552
1553 DataTypeLayout layout() const override {
1554
1555 return DataTypeLayout({DataTypeLayout::AlwaysNull()});
1556 }
1557
1558 const std::shared_ptr<DataType>& run_end_type() const { return fields()[0]->type(); }
1559 const std::shared_ptr<DataType>& value_type() const { return fields()[1]->type(); }
1560
1561 std::string ToString(bool show_metadata = false) const override;
1562
1563 std::string name() const override { return "run_end_encoded"; }
1564
1565 static bool RunEndTypeValid(const DataType& run_end_type);
1566
1567 private:
1568 std::string ComputeFingerprint() const override;
1569 };
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581 class ARROW_EXPORT TemporalType : public FixedWidthType {
1582 public:
1583 using FixedWidthType::FixedWidthType;
1584
1585
1586 ~TemporalType() override;
1587
1588 DataTypeLayout layout() const override {
1589 return DataTypeLayout(
1590 {DataTypeLayout::Bitmap(), DataTypeLayout::FixedWidth(bit_width() / 8)});
1591 }
1592 };
1593
1594
1595 class ARROW_EXPORT DateType : public TemporalType {
1596 public:
1597 virtual DateUnit unit() const = 0;
1598
1599 protected:
1600 explicit DateType(Type::type type_id);
1601 };
1602
1603
1604 class ARROW_EXPORT Date32Type : public DateType {
1605 public:
1606 static constexpr Type::type type_id = Type::DATE32;
1607 static constexpr DateUnit UNIT = DateUnit::DAY;
1608 using c_type = int32_t;
1609 using PhysicalType = Int32Type;
1610
1611 static constexpr const char* type_name() { return "date32"; }
1612
1613 Date32Type();
1614
1615 int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
1616
1617 std::string ToString(bool show_metadata = false) const override;
1618
1619 std::string name() const override { return "date32"; }
1620 DateUnit unit() const override { return UNIT; }
1621
1622 protected:
1623 std::string ComputeFingerprint() const override;
1624 };
1625
1626
1627 class ARROW_EXPORT Date64Type : public DateType {
1628 public:
1629 static constexpr Type::type type_id = Type::DATE64;
1630 static constexpr DateUnit UNIT = DateUnit::MILLI;
1631 using c_type = int64_t;
1632 using PhysicalType = Int64Type;
1633
1634 static constexpr const char* type_name() { return "date64"; }
1635
1636 Date64Type();
1637
1638 int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
1639
1640 std::string ToString(bool show_metadata = false) const override;
1641
1642 std::string name() const override { return "date64"; }
1643 DateUnit unit() const override { return UNIT; }
1644
1645 protected:
1646 std::string ComputeFingerprint() const override;
1647 };
1648
1649 ARROW_EXPORT
1650 std::ostream& operator<<(std::ostream& os, TimeUnit::type unit);
1651
1652
1653 class ARROW_EXPORT TimeType : public TemporalType, public ParametricType {
1654 public:
1655 TimeUnit::type unit() const { return unit_; }
1656
1657 protected:
1658 TimeType(Type::type type_id, TimeUnit::type unit);
1659 std::string ComputeFingerprint() const override;
1660
1661 TimeUnit::type unit_;
1662 };
1663
1664
1665
1666 class ARROW_EXPORT Time32Type : public TimeType {
1667 public:
1668 static constexpr Type::type type_id = Type::TIME32;
1669 using c_type = int32_t;
1670 using PhysicalType = Int32Type;
1671
1672 static constexpr const char* type_name() { return "time32"; }
1673
1674 int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
1675
1676 explicit Time32Type(TimeUnit::type unit = TimeUnit::MILLI);
1677
1678 std::string ToString(bool show_metadata = false) const override;
1679
1680 std::string name() const override { return "time32"; }
1681 };
1682
1683
1684
1685 class ARROW_EXPORT Time64Type : public TimeType {
1686 public:
1687 static constexpr Type::type type_id = Type::TIME64;
1688 using c_type = int64_t;
1689 using PhysicalType = Int64Type;
1690
1691 static constexpr const char* type_name() { return "time64"; }
1692
1693 int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
1694
1695 explicit Time64Type(TimeUnit::type unit = TimeUnit::NANO);
1696
1697 std::string ToString(bool show_metadata = false) const override;
1698
1699 std::string name() const override { return "time64"; }
1700 };
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734 class ARROW_EXPORT TimestampType : public TemporalType, public ParametricType {
1735 public:
1736 using Unit = TimeUnit;
1737
1738 static constexpr Type::type type_id = Type::TIMESTAMP;
1739 using c_type = int64_t;
1740 using PhysicalType = Int64Type;
1741
1742 static constexpr const char* type_name() { return "timestamp"; }
1743
1744 int bit_width() const override { return static_cast<int>(sizeof(int64_t) * CHAR_BIT); }
1745
1746 explicit TimestampType(TimeUnit::type unit = TimeUnit::MILLI)
1747 : TemporalType(Type::TIMESTAMP), unit_(unit) {}
1748
1749 explicit TimestampType(TimeUnit::type unit, const std::string& timezone)
1750 : TemporalType(Type::TIMESTAMP), unit_(unit), timezone_(timezone) {}
1751
1752 std::string ToString(bool show_metadata = false) const override;
1753 std::string name() const override { return "timestamp"; }
1754
1755 TimeUnit::type unit() const { return unit_; }
1756 const std::string& timezone() const { return timezone_; }
1757
1758 protected:
1759 std::string ComputeFingerprint() const override;
1760
1761 private:
1762 TimeUnit::type unit_;
1763 std::string timezone_;
1764 };
1765
1766
1767 class ARROW_EXPORT IntervalType : public TemporalType, public ParametricType {
1768 public:
1769 enum type { MONTHS, DAY_TIME, MONTH_DAY_NANO };
1770
1771 virtual type interval_type() const = 0;
1772
1773 protected:
1774 explicit IntervalType(Type::type subtype) : TemporalType(subtype) {}
1775 std::string ComputeFingerprint() const override;
1776 };
1777
1778
1779
1780
1781
1782 class ARROW_EXPORT MonthIntervalType : public IntervalType {
1783 public:
1784 static constexpr Type::type type_id = Type::INTERVAL_MONTHS;
1785 using c_type = int32_t;
1786 using PhysicalType = Int32Type;
1787
1788 static constexpr const char* type_name() { return "month_interval"; }
1789
1790 IntervalType::type interval_type() const override { return IntervalType::MONTHS; }
1791
1792 int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
1793
1794 MonthIntervalType() : IntervalType(type_id) {}
1795
1796 std::string ToString(bool ARROW_ARG_UNUSED(show_metadata) = false) const override {
1797 return name();
1798 }
1799 std::string name() const override { return "month_interval"; }
1800 };
1801
1802
1803 class ARROW_EXPORT DayTimeIntervalType : public IntervalType {
1804 public:
1805 struct DayMilliseconds {
1806 int32_t days = 0;
1807 int32_t milliseconds = 0;
1808 constexpr DayMilliseconds() = default;
1809 constexpr DayMilliseconds(int32_t days, int32_t milliseconds)
1810 : days(days), milliseconds(milliseconds) {}
1811 bool operator==(DayMilliseconds other) const {
1812 return this->days == other.days && this->milliseconds == other.milliseconds;
1813 }
1814 bool operator!=(DayMilliseconds other) const { return !(*this == other); }
1815 bool operator<(DayMilliseconds other) const {
1816 return this->days < other.days || this->milliseconds < other.milliseconds;
1817 }
1818 };
1819 using c_type = DayMilliseconds;
1820 using PhysicalType = DayTimeIntervalType;
1821
1822 static_assert(sizeof(DayMilliseconds) == 8,
1823 "DayMilliseconds struct assumed to be of size 8 bytes");
1824 static constexpr Type::type type_id = Type::INTERVAL_DAY_TIME;
1825
1826 static constexpr const char* type_name() { return "day_time_interval"; }
1827
1828 IntervalType::type interval_type() const override { return IntervalType::DAY_TIME; }
1829
1830 DayTimeIntervalType() : IntervalType(type_id) {}
1831
1832 int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
1833
1834 std::string ToString(bool ARROW_ARG_UNUSED(show_metadata) = false) const override {
1835 return name();
1836 }
1837 std::string name() const override { return "day_time_interval"; }
1838 };
1839
1840 ARROW_EXPORT
1841 std::ostream& operator<<(std::ostream& os, DayTimeIntervalType::DayMilliseconds interval);
1842
1843
1844
1845
1846
1847 class ARROW_EXPORT MonthDayNanoIntervalType : public IntervalType {
1848 public:
1849 struct MonthDayNanos {
1850 int32_t months;
1851 int32_t days;
1852 int64_t nanoseconds;
1853 bool operator==(MonthDayNanos other) const {
1854 return this->months == other.months && this->days == other.days &&
1855 this->nanoseconds == other.nanoseconds;
1856 }
1857 bool operator!=(MonthDayNanos other) const { return !(*this == other); }
1858 };
1859 using c_type = MonthDayNanos;
1860 using PhysicalType = MonthDayNanoIntervalType;
1861
1862 static_assert(sizeof(MonthDayNanos) == 16,
1863 "MonthDayNanos struct assumed to be of size 16 bytes");
1864 static constexpr Type::type type_id = Type::INTERVAL_MONTH_DAY_NANO;
1865
1866 static constexpr const char* type_name() { return "month_day_nano_interval"; }
1867
1868 IntervalType::type interval_type() const override {
1869 return IntervalType::MONTH_DAY_NANO;
1870 }
1871
1872 MonthDayNanoIntervalType() : IntervalType(type_id) {}
1873
1874 int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
1875
1876 std::string ToString(bool ARROW_ARG_UNUSED(show_metadata) = false) const override {
1877 return name();
1878 }
1879 std::string name() const override { return "month_day_nano_interval"; }
1880 };
1881
1882 ARROW_EXPORT
1883 std::ostream& operator<<(std::ostream& os,
1884 MonthDayNanoIntervalType::MonthDayNanos interval);
1885
1886
1887 class ARROW_EXPORT DurationType : public TemporalType, public ParametricType {
1888 public:
1889 using Unit = TimeUnit;
1890
1891 static constexpr Type::type type_id = Type::DURATION;
1892 using c_type = int64_t;
1893 using PhysicalType = Int64Type;
1894
1895 static constexpr const char* type_name() { return "duration"; }
1896
1897 int bit_width() const override { return static_cast<int>(sizeof(int64_t) * CHAR_BIT); }
1898
1899 explicit DurationType(TimeUnit::type unit = TimeUnit::MILLI)
1900 : TemporalType(Type::DURATION), unit_(unit) {}
1901
1902 std::string ToString(bool show_metadata = false) const override;
1903 std::string name() const override { return "duration"; }
1904
1905 TimeUnit::type unit() const { return unit_; }
1906
1907 protected:
1908 std::string ComputeFingerprint() const override;
1909
1910 private:
1911 TimeUnit::type unit_;
1912 };
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922 class ARROW_EXPORT DictionaryType : public FixedWidthType {
1923 public:
1924 static constexpr Type::type type_id = Type::DICTIONARY;
1925
1926 static constexpr const char* type_name() { return "dictionary"; }
1927
1928 DictionaryType(const std::shared_ptr<DataType>& index_type,
1929 const std::shared_ptr<DataType>& value_type, bool ordered = false);
1930
1931
1932 static Result<std::shared_ptr<DataType>> Make(
1933 const std::shared_ptr<DataType>& index_type,
1934 const std::shared_ptr<DataType>& value_type, bool ordered = false);
1935
1936 std::string ToString(bool show_metadata = false) const override;
1937 std::string name() const override { return "dictionary"; }
1938
1939 int bit_width() const override;
1940
1941 DataTypeLayout layout() const override;
1942
1943 const std::shared_ptr<DataType>& index_type() const { return index_type_; }
1944 const std::shared_ptr<DataType>& value_type() const { return value_type_; }
1945
1946 bool ordered() const { return ordered_; }
1947
1948 protected:
1949 static Status ValidateParameters(const DataType& index_type,
1950 const DataType& value_type);
1951
1952 std::string ComputeFingerprint() const override;
1953
1954
1955 std::shared_ptr<DataType> index_type_;
1956 std::shared_ptr<DataType> value_type_;
1957 bool ordered_;
1958 };
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978 class ARROW_EXPORT FieldPath {
1979 public:
1980 FieldPath() = default;
1981
1982 FieldPath(std::vector<int> indices)
1983 : indices_(std::move(indices)) {}
1984
1985 FieldPath(std::initializer_list<int> indices)
1986 : indices_(std::move(indices)) {}
1987
1988 std::string ToString() const;
1989
1990 size_t hash() const;
1991 struct Hash {
1992 size_t operator()(const FieldPath& path) const { return path.hash(); }
1993 };
1994
1995 bool empty() const { return indices_.empty(); }
1996 bool operator==(const FieldPath& other) const { return indices() == other.indices(); }
1997 bool operator!=(const FieldPath& other) const { return indices() != other.indices(); }
1998
1999 const std::vector<int>& indices() const { return indices_; }
2000 int operator[](size_t i) const { return indices_[i]; }
2001 std::vector<int>::const_iterator begin() const { return indices_.begin(); }
2002 std::vector<int>::const_iterator end() const { return indices_.end(); }
2003
2004
2005 Result<std::shared_ptr<Field>> Get(const Schema& schema) const;
2006 Result<std::shared_ptr<Field>> Get(const Field& field) const;
2007 Result<std::shared_ptr<Field>> Get(const DataType& type) const;
2008 Result<std::shared_ptr<Field>> Get(const FieldVector& fields) const;
2009
2010 static Result<std::shared_ptr<Schema>> GetAll(const Schema& schema,
2011 const std::vector<FieldPath>& paths);
2012
2013
2014 Result<std::shared_ptr<Array>> Get(const RecordBatch& batch) const;
2015 Result<std::shared_ptr<ChunkedArray>> Get(const Table& table) const;
2016
2017
2018 Result<std::shared_ptr<Array>> Get(const Array& array) const;
2019 Result<std::shared_ptr<ArrayData>> Get(const ArrayData& data) const;
2020
2021
2022 Result<std::shared_ptr<ChunkedArray>> Get(const ChunkedArray& chunked_array) const;
2023
2024
2025
2026
2027
2028
2029 Result<std::shared_ptr<Array>> GetFlattened(const Array& array,
2030 MemoryPool* pool = NULLPTR) const;
2031 Result<std::shared_ptr<ArrayData>> GetFlattened(const ArrayData& data,
2032 MemoryPool* pool = NULLPTR) const;
2033 Result<std::shared_ptr<ChunkedArray>> GetFlattened(const ChunkedArray& chunked_array,
2034 MemoryPool* pool = NULLPTR) const;
2035 Result<std::shared_ptr<Array>> GetFlattened(const RecordBatch& batch,
2036 MemoryPool* pool = NULLPTR) const;
2037 Result<std::shared_ptr<ChunkedArray>> GetFlattened(const Table& table,
2038 MemoryPool* pool = NULLPTR) const;
2039
2040 private:
2041 std::vector<int> indices_;
2042 };
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077 class ARROW_EXPORT FieldRef : public util::EqualityComparable<FieldRef> {
2078 public:
2079 FieldRef() = default;
2080
2081
2082
2083
2084
2085 FieldRef(FieldPath indices);
2086
2087
2088
2089 FieldRef(std::string name) : impl_(std::move(name)) {}
2090 FieldRef(const char* name) : impl_(std::string(name)) {}
2091
2092
2093 FieldRef(int index) : impl_(FieldPath({index})) {}
2094
2095
2096 explicit FieldRef(std::vector<FieldRef> refs) { Flatten(std::move(refs)); }
2097
2098
2099
2100 template <typename A0, typename A1, typename... A>
2101 FieldRef(A0&& a0, A1&& a1, A&&... a) {
2102 Flatten({
2103 FieldRef(std::forward<A0>(a0)),
2104 FieldRef(std::forward<A1>(a1)),
2105 FieldRef(std::forward<A>(a))...});
2106 }
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125 static Result<FieldRef> FromDotPath(const std::string& dot_path);
2126 std::string ToDotPath() const;
2127
2128 bool Equals(const FieldRef& other) const { return impl_ == other.impl_; }
2129
2130 std::string ToString() const;
2131
2132 size_t hash() const;
2133 struct Hash {
2134 size_t operator()(const FieldRef& ref) const { return ref.hash(); }
2135 };
2136
2137 explicit operator bool() const { return Equals(FieldPath{}); }
2138 bool operator!() const { return !Equals(FieldPath{}); }
2139
2140 bool IsFieldPath() const { return std::holds_alternative<FieldPath>(impl_); }
2141 bool IsName() const { return std::holds_alternative<std::string>(impl_); }
2142 bool IsNested() const {
2143 if (IsName()) return false;
2144 if (IsFieldPath()) return std::get<FieldPath>(impl_).indices().size() > 1;
2145 return true;
2146 }
2147
2148
2149
2150
2151 bool IsNameSequence() const {
2152 if (IsName()) return true;
2153 if (const auto* nested = nested_refs()) {
2154 for (const auto& ref : *nested) {
2155 if (!ref.IsName()) return false;
2156 }
2157 return !nested->empty();
2158 }
2159 return false;
2160 }
2161
2162 const FieldPath* field_path() const {
2163 return IsFieldPath() ? &std::get<FieldPath>(impl_) : NULLPTR;
2164 }
2165 const std::string* name() const {
2166 return IsName() ? &std::get<std::string>(impl_) : NULLPTR;
2167 }
2168 const std::vector<FieldRef>* nested_refs() const {
2169 return std::holds_alternative<std::vector<FieldRef>>(impl_)
2170 ? &std::get<std::vector<FieldRef>>(impl_)
2171 : NULLPTR;
2172 }
2173
2174
2175 std::vector<FieldPath> FindAll(const Schema& schema) const;
2176 std::vector<FieldPath> FindAll(const Field& field) const;
2177 std::vector<FieldPath> FindAll(const DataType& type) const;
2178 std::vector<FieldPath> FindAll(const FieldVector& fields) const;
2179
2180
2181 std::vector<FieldPath> FindAll(const ArrayData& array) const;
2182 std::vector<FieldPath> FindAll(const Array& array) const;
2183 std::vector<FieldPath> FindAll(const ChunkedArray& chunked_array) const;
2184 std::vector<FieldPath> FindAll(const RecordBatch& batch) const;
2185 std::vector<FieldPath> FindAll(const Table& table) const;
2186
2187
2188 template <typename T>
2189 Status CheckNonEmpty(const std::vector<FieldPath>& matches, const T& root) const {
2190 if (matches.empty()) {
2191 return Status::Invalid("No match for ", ToString(), " in ", root.ToString());
2192 }
2193 return Status::OK();
2194 }
2195
2196
2197 template <typename T>
2198 Status CheckNonMultiple(const std::vector<FieldPath>& matches, const T& root) const {
2199 if (matches.size() > 1) {
2200 return Status::Invalid("Multiple matches for ", ToString(), " in ",
2201 root.ToString());
2202 }
2203 return Status::OK();
2204 }
2205
2206
2207
2208 template <typename T>
2209 Result<FieldPath> FindOne(const T& root) const {
2210 auto matches = FindAll(root);
2211 ARROW_RETURN_NOT_OK(CheckNonEmpty(matches, root));
2212 ARROW_RETURN_NOT_OK(CheckNonMultiple(matches, root));
2213 return std::move(matches[0]);
2214 }
2215
2216
2217
2218
2219 template <typename T>
2220 Result<FieldPath> FindOneOrNone(const T& root) const {
2221 auto matches = FindAll(root);
2222 ARROW_RETURN_NOT_OK(CheckNonMultiple(matches, root));
2223 if (matches.empty()) {
2224 return FieldPath();
2225 }
2226 return std::move(matches[0]);
2227 }
2228
2229 template <typename T>
2230 using GetType = decltype(std::declval<FieldPath>().Get(std::declval<T>()).ValueOrDie());
2231
2232
2233 template <typename T>
2234 std::vector<GetType<T>> GetAll(const T& root) const {
2235 std::vector<GetType<T>> out;
2236 for (const auto& match : FindAll(root)) {
2237 out.push_back(match.Get(root).ValueOrDie());
2238 }
2239 return out;
2240 }
2241
2242
2243
2244
2245 template <typename T>
2246 Result<std::vector<GetType<T>>> GetAllFlattened(const T& root,
2247 MemoryPool* pool = NULLPTR) const {
2248 std::vector<GetType<T>> out;
2249 for (const auto& match : FindAll(root)) {
2250 ARROW_ASSIGN_OR_RAISE(auto child, match.GetFlattened(root, pool));
2251 out.push_back(std::move(child));
2252 }
2253 return out;
2254 }
2255
2256
2257
2258 template <typename T>
2259 Result<GetType<T>> GetOne(const T& root) const {
2260 ARROW_ASSIGN_OR_RAISE(auto match, FindOne(root));
2261 return match.Get(root).ValueOrDie();
2262 }
2263
2264
2265
2266
2267 template <typename T>
2268 Result<GetType<T>> GetOneFlattened(const T& root, MemoryPool* pool = NULLPTR) const {
2269 ARROW_ASSIGN_OR_RAISE(auto match, FindOne(root));
2270 return match.GetFlattened(root, pool);
2271 }
2272
2273
2274
2275 template <typename T>
2276 Result<GetType<T>> GetOneOrNone(const T& root) const {
2277 ARROW_ASSIGN_OR_RAISE(auto match, FindOneOrNone(root));
2278 if (match.empty()) {
2279 return static_cast<GetType<T>>(NULLPTR);
2280 }
2281 return match.Get(root).ValueOrDie();
2282 }
2283
2284
2285
2286
2287
2288 template <typename T>
2289 Result<GetType<T>> GetOneOrNoneFlattened(const T& root,
2290 MemoryPool* pool = NULLPTR) const {
2291 ARROW_ASSIGN_OR_RAISE(auto match, FindOneOrNone(root));
2292 if (match.empty()) {
2293 return static_cast<GetType<T>>(NULLPTR);
2294 }
2295 return match.GetFlattened(root, pool);
2296 }
2297
2298 private:
2299 void Flatten(std::vector<FieldRef> children);
2300
2301 std::variant<FieldPath, std::string, std::vector<FieldRef>> impl_;
2302 };
2303
2304 ARROW_EXPORT void PrintTo(const FieldRef& ref, std::ostream* os);
2305
2306 ARROW_EXPORT
2307 std::ostream& operator<<(std::ostream& os, const FieldRef&);
2308
2309
2310
2311
2312 enum class Endianness {
2313 Little = 0,
2314 Big = 1,
2315 #if ARROW_LITTLE_ENDIAN
2316 Native = Little
2317 #else
2318 Native = Big
2319 #endif
2320 };
2321
2322
2323
2324
2325 class ARROW_EXPORT Schema : public detail::Fingerprintable,
2326 public util::EqualityComparable<Schema>,
2327 public util::ToStringOstreamable<Schema> {
2328 public:
2329 explicit Schema(FieldVector fields, Endianness endianness,
2330 std::shared_ptr<const KeyValueMetadata> metadata = NULLPTR);
2331
2332 explicit Schema(FieldVector fields,
2333 std::shared_ptr<const KeyValueMetadata> metadata = NULLPTR);
2334
2335 Schema(const Schema&);
2336
2337 ~Schema() override;
2338
2339
2340 bool Equals(const Schema& other, bool check_metadata = false) const;
2341 bool Equals(const std::shared_ptr<Schema>& other, bool check_metadata = false) const;
2342
2343
2344
2345
2346 std::shared_ptr<Schema> WithEndianness(Endianness endianness) const;
2347
2348
2349 Endianness endianness() const;
2350
2351
2352 bool is_native_endian() const;
2353
2354
2355 int num_fields() const;
2356
2357
2358 const std::shared_ptr<Field>& field(int i) const;
2359
2360 const FieldVector& fields() const;
2361
2362 std::vector<std::string> field_names() const;
2363
2364
2365 std::shared_ptr<Field> GetFieldByName(const std::string& name) const;
2366
2367
2368 FieldVector GetAllFieldsByName(const std::string& name) const;
2369
2370
2371 int GetFieldIndex(const std::string& name) const;
2372
2373
2374 std::vector<int> GetAllFieldIndices(const std::string& name) const;
2375
2376
2377 Status CanReferenceFieldByName(const std::string& name) const;
2378
2379
2380 Status CanReferenceFieldsByNames(const std::vector<std::string>& names) const;
2381
2382
2383
2384
2385 const std::shared_ptr<const KeyValueMetadata>& metadata() const;
2386
2387
2388
2389
2390 std::string ToString(bool show_metadata = false) const;
2391
2392 Result<std::shared_ptr<Schema>> AddField(int i,
2393 const std::shared_ptr<Field>& field) const;
2394 Result<std::shared_ptr<Schema>> RemoveField(int i) const;
2395 Result<std::shared_ptr<Schema>> SetField(int i,
2396 const std::shared_ptr<Field>& field) const;
2397
2398
2399
2400
2401
2402 Result<std::shared_ptr<Schema>> WithNames(const std::vector<std::string>& names) const;
2403
2404
2405
2406
2407
2408 std::shared_ptr<Schema> WithMetadata(
2409 const std::shared_ptr<const KeyValueMetadata>& metadata) const;
2410
2411
2412 std::shared_ptr<Schema> RemoveMetadata() const;
2413
2414
2415 bool HasMetadata() const;
2416
2417
2418 bool HasDistinctFieldNames() const;
2419
2420 protected:
2421 std::string ComputeFingerprint() const override;
2422 std::string ComputeMetadataFingerprint() const override;
2423
2424 private:
2425 class Impl;
2426 std::unique_ptr<Impl> impl_;
2427 };
2428
2429 ARROW_EXPORT void PrintTo(const Schema& s, std::ostream* os);
2430
2431 ARROW_EXPORT
2432 std::string EndiannessToString(Endianness endianness);
2433
2434
2435
2436
2437
2438
2439
2440
2441 class ARROW_EXPORT SchemaBuilder {
2442 public:
2443
2444
2445
2446 enum ConflictPolicy {
2447
2448
2449 CONFLICT_APPEND = 0,
2450
2451 CONFLICT_IGNORE,
2452
2453 CONFLICT_REPLACE,
2454
2455
2456 CONFLICT_MERGE,
2457
2458 CONFLICT_ERROR
2459 };
2460
2461
2462
2463 SchemaBuilder(
2464 ConflictPolicy conflict_policy = CONFLICT_APPEND,
2465 Field::MergeOptions field_merge_options = Field::MergeOptions::Defaults());
2466
2467
2468 SchemaBuilder(
2469 FieldVector fields, ConflictPolicy conflict_policy = CONFLICT_APPEND,
2470 Field::MergeOptions field_merge_options = Field::MergeOptions::Defaults());
2471
2472
2473 SchemaBuilder(
2474 const std::shared_ptr<Schema>& schema,
2475 ConflictPolicy conflict_policy = CONFLICT_APPEND,
2476 Field::MergeOptions field_merge_options = Field::MergeOptions::Defaults());
2477
2478
2479 ConflictPolicy policy() const;
2480
2481
2482 void SetPolicy(ConflictPolicy resolution);
2483
2484
2485
2486
2487
2488 Status AddField(const std::shared_ptr<Field>& field);
2489
2490
2491
2492
2493
2494 Status AddFields(const FieldVector& fields);
2495
2496
2497
2498
2499
2500 Status AddSchema(const std::shared_ptr<Schema>& schema);
2501
2502
2503
2504
2505
2506 Status AddSchemas(const std::vector<std::shared_ptr<Schema>>& schemas);
2507
2508 Status AddMetadata(const KeyValueMetadata& metadata);
2509
2510
2511
2512
2513
2514
2515
2516 Result<std::shared_ptr<Schema>> Finish() const;
2517
2518
2519 static Result<std::shared_ptr<Schema>> Merge(
2520 const std::vector<std::shared_ptr<Schema>>& schemas,
2521 ConflictPolicy policy = CONFLICT_MERGE);
2522
2523
2524 static Status AreCompatible(const std::vector<std::shared_ptr<Schema>>& schemas,
2525 ConflictPolicy policy = CONFLICT_MERGE);
2526
2527
2528 void Reset();
2529
2530 ~SchemaBuilder();
2531
2532 private:
2533 class Impl;
2534 std::unique_ptr<Impl> impl_;
2535
2536 Status AppendField(const std::shared_ptr<Field>& field);
2537 };
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554 ARROW_EXPORT
2555 Result<std::shared_ptr<Schema>> UnifySchemas(
2556 const std::vector<std::shared_ptr<Schema>>& schemas,
2557 Field::MergeOptions field_merge_options = Field::MergeOptions::Defaults());
2558
2559 namespace internal {
2560
2561 constexpr bool may_have_validity_bitmap(Type::type id) {
2562 switch (id) {
2563 case Type::NA:
2564 case Type::DENSE_UNION:
2565 case Type::SPARSE_UNION:
2566 case Type::RUN_END_ENCODED:
2567 return false;
2568 default:
2569 return true;
2570 }
2571 }
2572
2573 ARROW_DEPRECATED("Deprecated in 17.0.0. Use may_have_validity_bitmap() instead.")
2574 constexpr bool HasValidityBitmap(Type::type id) { return may_have_validity_bitmap(id); }
2575
2576 ARROW_EXPORT
2577 std::string ToString(Type::type id);
2578
2579 ARROW_EXPORT
2580 std::string ToTypeName(Type::type id);
2581
2582 ARROW_EXPORT
2583 std::string ToString(TimeUnit::type unit);
2584
2585 }
2586
2587
2588
2589
2590 ARROW_EXPORT
2591 const std::vector<std::shared_ptr<DataType>>& SignedIntTypes();
2592
2593 ARROW_EXPORT
2594 const std::vector<std::shared_ptr<DataType>>& UnsignedIntTypes();
2595
2596 ARROW_EXPORT
2597 const std::vector<std::shared_ptr<DataType>>& IntTypes();
2598
2599 ARROW_EXPORT
2600 const std::vector<std::shared_ptr<DataType>>& FloatingPointTypes();
2601
2602 ARROW_EXPORT
2603 const std::vector<std::shared_ptr<DataType>>& NumericTypes();
2604
2605 ARROW_EXPORT
2606 const std::vector<std::shared_ptr<DataType>>& BaseBinaryTypes();
2607
2608 ARROW_EXPORT
2609 const std::vector<std::shared_ptr<DataType>>& BinaryTypes();
2610
2611 ARROW_EXPORT
2612 const std::vector<std::shared_ptr<DataType>>& StringTypes();
2613
2614 ARROW_EXPORT
2615 const std::vector<std::shared_ptr<DataType>>& BinaryViewTypes();
2616
2617 ARROW_EXPORT
2618 const std::vector<std::shared_ptr<DataType>>& TemporalTypes();
2619
2620 ARROW_EXPORT
2621 const std::vector<std::shared_ptr<DataType>>& IntervalTypes();
2622
2623 ARROW_EXPORT
2624 const std::vector<std::shared_ptr<DataType>>& DurationTypes();
2625
2626 ARROW_EXPORT
2627 const std::vector<std::shared_ptr<DataType>>& PrimitiveTypes();
2628
2629 }