Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
type.h
Go to the documentation of this file.
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 #ifndef ARROW_TYPE_H
19 #define ARROW_TYPE_H
20 
21 #include <climits>
22 #include <cstdint>
23 #include <memory>
24 #include <ostream>
25 #include <string>
26 #include <type_traits>
27 #include <unordered_map>
28 #include <vector>
29 
30 #include "arrow/status.h"
31 #include "arrow/type_fwd.h" // IWYU pragma: export
33 #include "arrow/util/key_value_metadata.h" // IWYU pragma: export
34 #include "arrow/util/macros.h"
35 #include "arrow/util/visibility.h"
36 #include "arrow/visitor.h" // IWYU pragma: keep
37 
38 namespace arrow {
39 
40 class Array;
41 class Field;
42 
47 struct Type {
48  enum type {
50  NA,
51 
54 
57 
60 
63 
66 
69 
72 
75 
78 
81 
84 
87 
90 
93 
96 
99 
102 
106 
110 
114 
117 
121 
124 
127 
130 
133 
136  };
137 };
138 
148 class ARROW_EXPORT DataType {
149  public:
150  explicit DataType(Type::type id) : id_(id) {}
151  virtual ~DataType();
152 
153  // Return whether the types are equal
154  //
155  // Types that are logically convertible from one to another (e.g. List<UInt8>
156  // and Binary) are NOT equal.
157  virtual bool Equals(const DataType& other) const;
158  bool Equals(const std::shared_ptr<DataType>& other) const;
159 
160  std::shared_ptr<Field> child(int i) const { return children_[i]; }
161 
162  const std::vector<std::shared_ptr<Field>>& children() const { return children_; }
163 
164  int num_children() const { return static_cast<int>(children_.size()); }
165 
166  virtual Status Accept(TypeVisitor* visitor) const = 0;
167 
169  virtual std::string ToString() const = 0;
170 
175  virtual std::string name() const = 0;
176 
177  Type::type id() const { return id_; }
178 
179  protected:
181  std::vector<std::shared_ptr<Field>> children_;
182 
183  private:
185 };
186 
187 inline std::ostream& operator<<(std::ostream& os, const DataType& type) {
188  os << type.ToString();
189  return os;
190 }
191 
193 class ARROW_EXPORT FixedWidthType : public DataType {
194  public:
195  using DataType::DataType;
196 
197  virtual int bit_width() const = 0;
198 };
199 
201 class ARROW_EXPORT PrimitiveCType : public FixedWidthType {
202  public:
203  using FixedWidthType::FixedWidthType;
204 };
205 
207 class ARROW_EXPORT Number : public PrimitiveCType {
208  public:
209  using PrimitiveCType::PrimitiveCType;
210 };
211 
213 class ARROW_EXPORT Integer : public Number {
214  public:
215  using Number::Number;
216  virtual bool is_signed() const = 0;
217 };
218 
220 class ARROW_EXPORT FloatingPoint : public Number {
221  public:
222  using Number::Number;
223  enum Precision { HALF, SINGLE, DOUBLE };
224  virtual Precision precision() const = 0;
225 };
226 
228 class ParametricType {};
229 
230 class ARROW_EXPORT NestedType : public DataType, public ParametricType {
231  public:
232  using DataType::DataType;
233 };
234 
235 class NoExtraMeta {};
236 
244 class ARROW_EXPORT Field {
245  public:
246  Field(const std::string& name, const std::shared_ptr<DataType>& type,
247  bool nullable = true,
248  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR)
249  : name_(name), type_(type), nullable_(nullable), metadata_(metadata) {}
250 
251  std::shared_ptr<const KeyValueMetadata> metadata() const { return metadata_; }
252 
253  bool HasMetadata() const;
254 
255  std::shared_ptr<Field> AddMetadata(
256  const std::shared_ptr<const KeyValueMetadata>& metadata) const;
257  std::shared_ptr<Field> RemoveMetadata() const;
258 
259  std::vector<std::shared_ptr<Field>> Flatten() const;
260 
261  bool Equals(const Field& other) const;
262  bool Equals(const std::shared_ptr<Field>& other) const;
263 
264  std::string ToString() const;
265 
266  const std::string& name() const { return name_; }
267  std::shared_ptr<DataType> type() const { return type_; }
268  bool nullable() const { return nullable_; }
269 
270  private:
271  // Field name
272  std::string name_;
273 
274  // The field's data type
275  std::shared_ptr<DataType> type_;
276 
277  // Fields can be nullable
278  bool nullable_;
279 
280  // The field's metadata, if any
281  std::shared_ptr<const KeyValueMetadata> metadata_;
282 };
283 
284 namespace detail {
285 
286 template <typename DERIVED, typename BASE, Type::type TYPE_ID, typename C_TYPE>
287 class ARROW_EXPORT CTypeImpl : public BASE {
288  public:
289  using c_type = C_TYPE;
290  static constexpr Type::type type_id = TYPE_ID;
291 
292  CTypeImpl() : BASE(TYPE_ID) {}
293 
294  int bit_width() const override { return static_cast<int>(sizeof(C_TYPE) * CHAR_BIT); }
295 
296  Status Accept(TypeVisitor* visitor) const override {
297  return visitor->Visit(internal::checked_cast<const DERIVED&>(*this));
298  }
299 
300  std::string ToString() const override { return this->name(); }
301 };
302 
303 template <typename DERIVED, Type::type TYPE_ID, typename C_TYPE>
304 class IntegerTypeImpl : public detail::CTypeImpl<DERIVED, Integer, TYPE_ID, C_TYPE> {
305  bool is_signed() const override { return std::is_signed<C_TYPE>::value; }
306 };
307 
308 } // namespace detail
309 
311 class ARROW_EXPORT NullType : public DataType, public NoExtraMeta {
312  public:
313  static constexpr Type::type type_id = Type::NA;
314 
315  NullType() : DataType(Type::NA) {}
316 
317  Status Accept(TypeVisitor* visitor) const override;
318  std::string ToString() const override;
319 
320  std::string name() const override { return "null"; }
321 };
322 
324 class ARROW_EXPORT BooleanType : public FixedWidthType, public NoExtraMeta {
325  public:
326  static constexpr Type::type type_id = Type::BOOL;
327 
329 
330  Status Accept(TypeVisitor* visitor) const override;
331  std::string ToString() const override;
332 
333  int bit_width() const override { return 1; }
334  std::string name() const override { return "bool"; }
335 };
336 
338 class ARROW_EXPORT UInt8Type
339  : public detail::IntegerTypeImpl<UInt8Type, Type::UINT8, uint8_t> {
340  public:
341  std::string name() const override { return "uint8"; }
342 };
343 
345 class ARROW_EXPORT Int8Type
346  : public detail::IntegerTypeImpl<Int8Type, Type::INT8, int8_t> {
347  public:
348  std::string name() const override { return "int8"; }
349 };
350 
352 class ARROW_EXPORT UInt16Type
353  : public detail::IntegerTypeImpl<UInt16Type, Type::UINT16, uint16_t> {
354  public:
355  std::string name() const override { return "uint16"; }
356 };
357 
359 class ARROW_EXPORT Int16Type
360  : public detail::IntegerTypeImpl<Int16Type, Type::INT16, int16_t> {
361  public:
362  std::string name() const override { return "int16"; }
363 };
364 
366 class ARROW_EXPORT UInt32Type
367  : public detail::IntegerTypeImpl<UInt32Type, Type::UINT32, uint32_t> {
368  public:
369  std::string name() const override { return "uint32"; }
370 };
371 
373 class ARROW_EXPORT Int32Type
374  : public detail::IntegerTypeImpl<Int32Type, Type::INT32, int32_t> {
375  public:
376  std::string name() const override { return "int32"; }
377 };
378 
380 class ARROW_EXPORT UInt64Type
381  : public detail::IntegerTypeImpl<UInt64Type, Type::UINT64, uint64_t> {
382  public:
383  std::string name() const override { return "uint64"; }
384 };
385 
387 class ARROW_EXPORT Int64Type
388  : public detail::IntegerTypeImpl<Int64Type, Type::INT64, int64_t> {
389  public:
390  std::string name() const override { return "int64"; }
391 };
392 
394 class ARROW_EXPORT HalfFloatType
395  : public detail::CTypeImpl<HalfFloatType, FloatingPoint, Type::HALF_FLOAT, uint16_t> {
396  public:
397  Precision precision() const override;
398  std::string name() const override { return "halffloat"; }
399 };
400 
402 class ARROW_EXPORT FloatType
403  : public detail::CTypeImpl<FloatType, FloatingPoint, Type::FLOAT, float> {
404  public:
405  Precision precision() const override;
406  std::string name() const override { return "float"; }
407 };
408 
410 class ARROW_EXPORT DoubleType
411  : public detail::CTypeImpl<DoubleType, FloatingPoint, Type::DOUBLE, double> {
412  public:
413  Precision precision() const override;
414  std::string name() const override { return "double"; }
415 };
416 
422 class ARROW_EXPORT ListType : public NestedType {
423  public:
424  static constexpr Type::type type_id = Type::LIST;
425 
426  // List can contain any other logical value type
427  explicit ListType(const std::shared_ptr<DataType>& value_type)
428  : ListType(std::make_shared<Field>("item", value_type)) {}
429 
430  explicit ListType(const std::shared_ptr<Field>& value_field) : NestedType(Type::LIST) {
431  children_ = {value_field};
432  }
433 
434  std::shared_ptr<Field> value_field() const { return children_[0]; }
435 
436  std::shared_ptr<DataType> value_type() const { return children_[0]->type(); }
437 
438  Status Accept(TypeVisitor* visitor) const override;
439  std::string ToString() const override;
440 
441  std::string name() const override { return "list"; }
442 };
443 
445 class ARROW_EXPORT BinaryType : public DataType, public NoExtraMeta {
446  public:
447  static constexpr Type::type type_id = Type::BINARY;
448 
449  BinaryType() : BinaryType(Type::BINARY) {}
450 
451  Status Accept(TypeVisitor* visitor) const override;
452  std::string ToString() const override;
453  std::string name() const override { return "binary"; }
454 
455  protected:
456  // Allow subclasses to change the logical type.
457  explicit BinaryType(Type::type logical_type) : DataType(logical_type) {}
458 };
459 
461 class ARROW_EXPORT FixedSizeBinaryType : public FixedWidthType, public ParametricType {
462  public:
463  static constexpr Type::type type_id = Type::FIXED_SIZE_BINARY;
464 
465  explicit FixedSizeBinaryType(int32_t byte_width)
466  : FixedWidthType(Type::FIXED_SIZE_BINARY), byte_width_(byte_width) {}
467  explicit FixedSizeBinaryType(int32_t byte_width, Type::type override_type_id)
468  : FixedWidthType(override_type_id), byte_width_(byte_width) {}
469 
470  Status Accept(TypeVisitor* visitor) const override;
471  std::string ToString() const override;
472  std::string name() const override { return "fixed_size_binary"; }
473 
474  int32_t byte_width() const { return byte_width_; }
475  int bit_width() const override;
476 
477  protected:
478  int32_t byte_width_;
479 };
480 
482 class ARROW_EXPORT StringType : public BinaryType {
483  public:
484  static constexpr Type::type type_id = Type::STRING;
485 
486  StringType() : BinaryType(Type::STRING) {}
487 
488  Status Accept(TypeVisitor* visitor) const override;
489  std::string ToString() const override;
490  std::string name() const override { return "utf8"; }
491 };
492 
494 class ARROW_EXPORT StructType : public NestedType {
495  public:
496  static constexpr Type::type type_id = Type::STRUCT;
497 
498  explicit StructType(const std::vector<std::shared_ptr<Field>>& fields)
499  : NestedType(Type::STRUCT) {
500  children_ = fields;
501  }
502 
503  Status Accept(TypeVisitor* visitor) const override;
504  std::string ToString() const override;
505  std::string name() const override { return "struct"; }
506 
508  std::shared_ptr<Field> GetChildByName(const std::string& name) const;
509 
511  int GetChildIndex(const std::string& name) const;
512 
513  private:
515  mutable std::unordered_map<std::string, int> name_to_index_;
516 };
517 
519 class ARROW_EXPORT DecimalType : public FixedSizeBinaryType {
520  public:
521  explicit DecimalType(int32_t byte_width, int32_t precision, int32_t scale)
522  : FixedSizeBinaryType(byte_width, Type::DECIMAL),
523  precision_(precision),
524  scale_(scale) {}
525 
526  int32_t precision() const { return precision_; }
527  int32_t scale() const { return scale_; }
528 
529  protected:
530  int32_t precision_;
531  int32_t scale_;
532 };
533 
535 class ARROW_EXPORT Decimal128Type : public DecimalType {
536  public:
537  static constexpr Type::type type_id = Type::DECIMAL;
538 
539  explicit Decimal128Type(int32_t precision, int32_t scale)
540  : DecimalType(16, precision, scale) {}
541 
542  Status Accept(TypeVisitor* visitor) const override;
543  std::string ToString() const override;
544  std::string name() const override { return "decimal"; }
545 };
546 
547 struct UnionMode {
548  enum type { SPARSE, DENSE };
549 };
550 
552 class ARROW_EXPORT UnionType : public NestedType {
553  public:
554  static constexpr Type::type type_id = Type::UNION;
555 
556  UnionType(const std::vector<std::shared_ptr<Field>>& fields,
557  const std::vector<uint8_t>& type_codes,
559 
560  std::string ToString() const override;
561  std::string name() const override { return "union"; }
562  Status Accept(TypeVisitor* visitor) const override;
563 
564  const std::vector<uint8_t>& type_codes() const { return type_codes_; }
565 
566  UnionMode::type mode() const { return mode_; }
567 
568  private:
569  UnionMode::type mode_;
570 
571  // The type id used in the data to indicate each data type in the union. For
572  // example, the first type in the union might be denoted by the id 5 (instead
573  // of 0).
574  std::vector<uint8_t> type_codes_;
575 };
576 
577 // ----------------------------------------------------------------------
578 // Date and time types
579 
580 enum class DateUnit : char { DAY = 0, MILLI = 1 };
581 
583 class ARROW_EXPORT DateType : public FixedWidthType {
584  public:
585  DateUnit unit() const { return unit_; }
586 
587  protected:
588  DateType(Type::type type_id, DateUnit unit);
590 };
591 
593 class ARROW_EXPORT Date32Type : public DateType {
594  public:
595  static constexpr Type::type type_id = Type::DATE32;
596 
597  using c_type = int32_t;
598 
599  Date32Type();
600 
601  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
602 
603  Status Accept(TypeVisitor* visitor) const override;
604  std::string ToString() const override;
605 
606  std::string name() const override { return "date32"; }
607 };
608 
610 class ARROW_EXPORT Date64Type : public DateType {
611  public:
612  static constexpr Type::type type_id = Type::DATE64;
613 
614  using c_type = int64_t;
615 
616  Date64Type();
617 
618  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
619 
620  Status Accept(TypeVisitor* visitor) const override;
621  std::string ToString() const override;
622 
623  std::string name() const override { return "date64"; }
624 };
625 
626 struct TimeUnit {
627  enum type { SECOND = 0, MILLI = 1, MICRO = 2, NANO = 3 };
628 };
629 
630 static inline std::ostream& operator<<(std::ostream& os, TimeUnit::type unit) {
631  switch (unit) {
632  case TimeUnit::SECOND:
633  os << "s";
634  break;
635  case TimeUnit::MILLI:
636  os << "ms";
637  break;
638  case TimeUnit::MICRO:
639  os << "us";
640  break;
641  case TimeUnit::NANO:
642  os << "ns";
643  break;
644  }
645  return os;
646 }
647 
649 class ARROW_EXPORT TimeType : public FixedWidthType, public ParametricType {
650  public:
651  TimeUnit::type unit() const { return unit_; }
652 
653  protected:
654  TimeType(Type::type type_id, TimeUnit::type unit);
656 };
657 
658 class ARROW_EXPORT Time32Type : public TimeType {
659  public:
660  static constexpr Type::type type_id = Type::TIME32;
661  using c_type = int32_t;
662 
663  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
664 
665  explicit Time32Type(TimeUnit::type unit = TimeUnit::MILLI);
666 
667  Status Accept(TypeVisitor* visitor) const override;
668  std::string ToString() const override;
669 
670  std::string name() const override { return "time32"; }
671 };
672 
673 class ARROW_EXPORT Time64Type : public TimeType {
674  public:
675  static constexpr Type::type type_id = Type::TIME64;
676  using c_type = int64_t;
677 
678  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
679 
680  explicit Time64Type(TimeUnit::type unit = TimeUnit::MILLI);
681 
682  Status Accept(TypeVisitor* visitor) const override;
683  std::string ToString() const override;
684 
685  std::string name() const override { return "time64"; }
686 };
687 
688 class ARROW_EXPORT TimestampType : public FixedWidthType, public ParametricType {
689  public:
690  using Unit = TimeUnit;
691 
692  typedef int64_t c_type;
693  static constexpr Type::type type_id = Type::TIMESTAMP;
694 
695  int bit_width() const override { return static_cast<int>(sizeof(int64_t) * CHAR_BIT); }
696 
698  : FixedWidthType(Type::TIMESTAMP), unit_(unit) {}
699 
700  explicit TimestampType(TimeUnit::type unit, const std::string& timezone)
701  : FixedWidthType(Type::TIMESTAMP), unit_(unit), timezone_(timezone) {}
702 
703  Status Accept(TypeVisitor* visitor) const override;
704  std::string ToString() const override;
705  std::string name() const override { return "timestamp"; }
706 
707  TimeUnit::type unit() const { return unit_; }
708  const std::string& timezone() const { return timezone_; }
709 
710  private:
711  TimeUnit::type unit_;
712  std::string timezone_;
713 };
714 
715 class ARROW_EXPORT IntervalType : public FixedWidthType {
716  public:
717  enum class Unit : char { YEAR_MONTH = 0, DAY_TIME = 1 };
718 
719  using c_type = int64_t;
720  static constexpr Type::type type_id = Type::INTERVAL;
721 
722  int bit_width() const override { return static_cast<int>(sizeof(int64_t) * CHAR_BIT); }
723 
724  explicit IntervalType(Unit unit = Unit::YEAR_MONTH)
725  : FixedWidthType(Type::INTERVAL), unit_(unit) {}
726 
727  Status Accept(TypeVisitor* visitor) const override;
728  std::string ToString() const override { return name(); }
729  std::string name() const override { return "date"; }
730 
731  Unit unit() const { return unit_; }
732 
733  private:
734  Unit unit_;
735 };
736 
737 // ----------------------------------------------------------------------
738 // DictionaryType (for categorical or dictionary-encoded data)
739 
741 class ARROW_EXPORT DictionaryType : public FixedWidthType {
742  public:
743  static constexpr Type::type type_id = Type::DICTIONARY;
744 
745  DictionaryType(const std::shared_ptr<DataType>& index_type,
746  const std::shared_ptr<Array>& dictionary, bool ordered = false);
747 
748  int bit_width() const override;
749 
750  std::shared_ptr<DataType> index_type() const { return index_type_; }
751 
752  std::shared_ptr<Array> dictionary() const;
753 
754  Status Accept(TypeVisitor* visitor) const override;
755  std::string ToString() const override;
756  std::string name() const override { return "dictionary"; }
757 
758  bool ordered() const { return ordered_; }
759 
760  private:
761  // Must be an integer type (not currently checked)
762  std::shared_ptr<DataType> index_type_;
763  std::shared_ptr<Array> dictionary_;
764  bool ordered_;
765 };
766 
767 // ----------------------------------------------------------------------
768 // Schema
769 
773 class ARROW_EXPORT Schema {
774  public:
775  explicit Schema(const std::vector<std::shared_ptr<Field>>& fields,
776  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
777 
778  explicit Schema(std::vector<std::shared_ptr<Field>>&& fields,
779  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
780 
781  virtual ~Schema() = default;
782 
784  bool Equals(const Schema& other, bool check_metadata = true) const;
785 
787  std::shared_ptr<Field> field(int i) const { return fields_[i]; }
788 
790  std::shared_ptr<Field> GetFieldByName(const std::string& name) const;
791 
793  int64_t GetFieldIndex(const std::string& name) const;
794 
795  const std::vector<std::shared_ptr<Field>>& fields() const { return fields_; }
796 
800  std::shared_ptr<const KeyValueMetadata> metadata() const;
801 
803  std::string ToString() const;
804 
805  Status AddField(int i, const std::shared_ptr<Field>& field,
806  std::shared_ptr<Schema>* out) const;
807  Status RemoveField(int i, std::shared_ptr<Schema>* out) const;
808  Status SetField(int i, const std::shared_ptr<Field>& field,
809  std::shared_ptr<Schema>* out) const;
810 
815  std::shared_ptr<Schema> AddMetadata(
816  const std::shared_ptr<const KeyValueMetadata>& metadata) const;
817 
819  std::shared_ptr<Schema> RemoveMetadata() const;
820 
822  bool HasMetadata() const;
823 
825  int num_fields() const { return static_cast<int>(fields_.size()); }
826 
827  private:
828  std::vector<std::shared_ptr<Field>> fields_;
829 
831  mutable std::unordered_map<std::string, int> name_to_index_;
832 
833  std::shared_ptr<const KeyValueMetadata> metadata_;
834 };
835 
836 // ----------------------------------------------------------------------
837 // Parametric factory functions
838 // Other factory functions are in type_fwd.h
839 
841 ARROW_EXPORT
842 std::shared_ptr<DataType> fixed_size_binary(int32_t byte_width);
843 
845 ARROW_EXPORT
846 std::shared_ptr<DataType> decimal(int32_t precision, int32_t scale);
847 
849 ARROW_EXPORT
850 std::shared_ptr<DataType> list(const std::shared_ptr<Field>& value_type);
851 
853 ARROW_EXPORT
854 std::shared_ptr<DataType> list(const std::shared_ptr<DataType>& value_type);
855 
857 ARROW_EXPORT
858 std::shared_ptr<DataType> timestamp(TimeUnit::type unit);
859 
861 ARROW_EXPORT
862 std::shared_ptr<DataType> timestamp(TimeUnit::type unit, const std::string& timezone);
863 
867 std::shared_ptr<DataType> ARROW_EXPORT time32(TimeUnit::type unit);
868 
872 std::shared_ptr<DataType> ARROW_EXPORT time64(TimeUnit::type unit);
873 
875 std::shared_ptr<DataType> ARROW_EXPORT
876 struct_(const std::vector<std::shared_ptr<Field>>& fields);
877 
879 std::shared_ptr<DataType> ARROW_EXPORT
880 union_(const std::vector<std::shared_ptr<Field>>& child_fields,
881  const std::vector<uint8_t>& type_codes, UnionMode::type mode = UnionMode::SPARSE);
882 
884 std::shared_ptr<DataType> ARROW_EXPORT
885 union_(const std::vector<std::shared_ptr<Array>>& children,
887 
889 std::shared_ptr<DataType> ARROW_EXPORT
890 dictionary(const std::shared_ptr<DataType>& index_type,
891  const std::shared_ptr<Array>& values, bool ordered = false);
892 
899 std::shared_ptr<Field> ARROW_EXPORT field(
900  const std::string& name, const std::shared_ptr<DataType>& type, bool nullable = true,
901  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
902 
908 ARROW_EXPORT
909 std::shared_ptr<Schema> schema(
910  const std::vector<std::shared_ptr<Field>>& fields,
911  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
912 
918 ARROW_EXPORT
919 std::shared_ptr<Schema> schema(
920  std::vector<std::shared_ptr<Field>>&& fields,
921  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
922 
923 } // namespace arrow
924 
925 #endif // ARROW_TYPE_H
Concrete type class for struct data.
Definition: type.h:494
int bit_width() const override
Definition: type.h:678
std::string ToString() const override
A string representation of the type, including any children.
Definition: type.h:728
std::shared_ptr< const KeyValueMetadata > metadata() const
Definition: type.h:251
Definition: type.h:626
Definition: type.h:547
A NULL type having no physical storage.
Definition: type.h:50
int bit_width() const override
Definition: type.h:333
const std::string & name() const
Definition: type.h:266
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:606
Base class for all floating-point data types.
Definition: type.h:220
Concrete type class for 16-bit floating-point data.
Definition: type.h:394
FixedSizeBinaryType(int32_t byte_width, Type::type override_type_id)
Definition: type.h:467
int32_t byte_width_
Definition: type.h:478
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:406
#define NULLPTR
Definition: macros.h:69
DateUnit unit() const
Definition: type.h:585
int32_t precision() const
Definition: type.h:526
Concrete type class for unsigned 8-bit integer data.
Definition: type.h:338
Base class for all parametric data types.
Definition: type.h:228
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:376
type
Definition: type.h:48
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:705
Unsigned 16-bit little-endian integer.
Definition: type.h:62
Base class for all numeric data types.
Definition: type.h:207
IntervalType(Unit unit=Unit::YEAR_MONTH)
Definition: type.h:724
BinaryType()
Definition: type.h:449
Main data type enumeration.
Definition: type.h:47
Concrete type class for 64-bit floating-point data (C "double")
Definition: type.h:410
const std::vector< std::shared_ptr< Field > > & fields() const
Definition: type.h:795
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:441
std::shared_ptr< Field > child(int i) const
Definition: type.h:160
Unsigned 32-bit little-endian integer.
Definition: type.h:68
int32_t c_type
Definition: type.h:597
std::shared_ptr< DataType > index_type() const
Definition: type.h:750
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:623
Unsigned 8-bit little-endian integer.
Definition: type.h:56
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:383
int64_t c_type
Definition: type.h:614
#define ARROW_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:23
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:369
Definition: type.h:627
Signed 8-bit little-endian integer.
Definition: type.h:59
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:320
NullType()
Definition: type.h:315
Concrete type class for 64-bit date data (as number of milliseconds since UNIX epoch) ...
Definition: type.h:610
std::shared_ptr< DataType > list(const std::shared_ptr< Field > &value_type)
Create a ListType instance from its child Field type.
A list of some logical data type.
Definition: type.h:123
Definition: common.h:148
Definition: type.h:548
std::shared_ptr< DataType > value_type() const
Definition: type.h:436
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:544
DateUnit
Definition: type.h:580
Dictionary aka Category type.
Definition: type.h:132
Time as signed 64-bit integer, representing either microseconds or nanoseconds since midnight...
Definition: type.h:113
virtual std::string ToString() const =0
A string representation of the type, including any children.
TimeUnit::type unit() const
Definition: type.h:707
Signed 32-bit little-endian integer.
Definition: type.h:71
Map, a repeated struct logical type.
Definition: type.h:135
Type::type id() const
Definition: type.h:177
DataType(Type::type id)
Definition: type.h:150
Time as signed 32-bit integer, representing either seconds or milliseconds since midnight.
Definition: type.h:109
std::shared_ptr< DataType > time32(TimeUnit::type unit)
Create a 32-bit time type instance.
Definition: status.h:95
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:334
type
Definition: type.h:627
Type::type id_
Definition: type.h:180
bool nullable() const
Definition: type.h:268
int32_t days since the UNIX epoch
Definition: type.h:98
std::shared_ptr< DataType > decimal(int32_t precision, int32_t scale)
Create a Decimal128Type instance.
std::shared_ptr< DataType > dictionary(const std::shared_ptr< DataType > &index_type, const std::shared_ptr< Array > &values, bool ordered=false)
Create a DictionaryType instance.
int64_t c_type
Definition: type.h:676
std::shared_ptr< DataType > fixed_size_binary(int32_t byte_width)
Create a FixedSizeBinaryType instance.
int32_t scale_
Definition: type.h:531
type
Definition: type.h:548
int64_t c_type
Definition: type.h:719
Definition: type.h:627
ListType(const std::shared_ptr< Field > &value_field)
Definition: type.h:430
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:472
4-byte floating point value
Definition: type.h:83
Unit unit() const
Definition: type.h:731
Signed 16-bit little-endian integer.
Definition: type.h:65
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:756
const std::vector< uint8_t > & type_codes() const
Definition: type.h:564
DateUnit unit_
Definition: type.h:589
Concrete type class for unsigned 16-bit integer data.
Definition: type.h:352
Definition: type.h:688
Base class for all fixed-width data types.
Definition: type.h:193
Boolean as 1 bit, LSB bit-packed ordering.
Definition: type.h:53
Signed 64-bit little-endian integer.
Definition: type.h:77
Concrete type class for unsigned 32-bit integer data.
Definition: type.h:366
Struct of logical types.
Definition: type.h:126
Variable-length bytes (no guarantee of UTF8-ness)
Definition: type.h:92
Concrete type class for always-null data.
Definition: type.h:311
int bit_width() const override
Definition: type.h:663
int bit_width() const override
Definition: type.h:618
Concrete type class for variable-size binary data.
Definition: type.h:445
std::shared_ptr< Field > field(const std::string &name, const std::shared_ptr< DataType > &type, bool nullable=true, const std::shared_ptr< const KeyValueMetadata > &metadata=NULLPTR)
Create a Field instance.
Definition: visitor.h:60
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:490
std::shared_ptr< DataType > type() const
Definition: type.h:267
Concrete type class for boolean data.
Definition: type.h:324
TimestampType(TimeUnit::type unit, const std::string &timezone)
Definition: type.h:700
ListType(const std::shared_ptr< DataType > &value_type)
Definition: type.h:427
Definition: type.h:715
Concrete type class for list data.
Definition: type.h:422
StringType()
Definition: type.h:486
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:670
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:355
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:341
Definition: type.h:627
Exact timestamp encoded with int64 since UNIX epoch Default unit millisecond.
Definition: type.h:105
Concrete type class for variable-size string data, utf8-encoded.
Definition: type.h:482
Unit
Definition: type.h:717
int bit_width() const override
Definition: type.h:722
Fixed-size binary. Each value occupies the same number of bytes.
Definition: type.h:95
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:453
std::vector< std::shared_ptr< Field > > children_
Definition: type.h:181
Base type class for (fixed-size) decimal data.
Definition: type.h:519
Base class for all integral data types.
Definition: type.h:213
TimeUnit::type unit() const
Definition: type.h:651
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:414
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:729
TimestampType(TimeUnit::type unit=TimeUnit::MILLI)
Definition: type.h:697
std::shared_ptr< Field > value_field() const
Definition: type.h:434
const std::vector< std::shared_ptr< Field > > & children() const
Definition: type.h:162
Definition: type.h:230
Sequence of arrow::Field objects describing the columns of a record batch or table data structure...
Definition: type.h:773
Definition: type.h:627
std::ostream & operator<<(std::ostream &os, const DataType &type)
Definition: type.h:187
The combination of a field name and data type, with optional metadata.
Definition: type.h:244
Top-level namespace for Apache Arrow C++ API.
Definition: adapter.h:32
Base type class for time data.
Definition: type.h:649
Concrete type class for 128-bit decimal data.
Definition: type.h:535
int32_t precision_
Definition: type.h:530
Concrete type class for 32-bit floating-point data (C "float")
Definition: type.h:402
FixedSizeBinaryType(int32_t byte_width)
Definition: type.h:465
Concrete type class for signed 16-bit integer data.
Definition: type.h:359
int bit_width() const override
Definition: type.h:695
8-byte floating point value
Definition: type.h:86
int32_t scale() const
Definition: type.h:527
Concrete type class for signed 32-bit integer data.
Definition: type.h:373
Concrete type class for 32-bit date data (as number of days since UNIX epoch)
Definition: type.h:593
DecimalType(int32_t byte_width, int32_t precision, int32_t scale)
Definition: type.h:521
Base type class for date data.
Definition: type.h:583
int32_t byte_width() const
Definition: type.h:474
int64_t milliseconds since the UNIX epoch
Definition: type.h:101
std::shared_ptr< DataType > union_(const std::vector< std::shared_ptr< Field >> &child_fields, const std::vector< uint8_t > &type_codes, UnionMode::type mode=UnionMode::SPARSE)
Create a UnionType instance.
Definition: type.h:223
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:398
Definition: type.h:548
int32_t c_type
Definition: type.h:661
std::shared_ptr< DataType > time64(TimeUnit::type unit)
Create a 64-bit time type instance.
UTF8 variable-length string as List<Char>
Definition: type.h:89
Precision
Definition: type.h:223
Unsigned 64-bit little-endian integer.
Definition: type.h:74
std::shared_ptr< DataType > struct_(const std::vector< std::shared_ptr< Field >> &fields)
Create a StructType instance.
std::shared_ptr< Schema > schema(const std::vector< std::shared_ptr< Field >> &fields, const std::shared_ptr< const KeyValueMetadata > &metadata=NULLPTR)
Create a Schema instance.
Definition: type.h:235
BooleanType()
Definition: type.h:328
Field(const std::string &name, const std::shared_ptr< DataType > &type, bool nullable=true, const std::shared_ptr< const KeyValueMetadata > &metadata=NULLPTR)
Definition: type.h:246
Concrete type class for dictionary data.
Definition: type.h:741
int bit_width() const override
Definition: type.h:601
Definition: type.h:673
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:561
Concrete type class for unsigned 64-bit integer data.
Definition: type.h:380
std::shared_ptr< Field > field(int i) const
Return the ith schema element. Does not boundscheck.
Definition: type.h:787
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:505
int num_children() const
Definition: type.h:164
Concrete type class for signed 8-bit integer data.
Definition: type.h:345
int64_t c_type
Definition: type.h:692
virtual bool is_signed() const =0
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:685
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:362
2-byte floating point value
Definition: type.h:80
Definition: type.h:658
Unions of logical types.
Definition: type.h:129
Base class for all data types.
Definition: type.h:148
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:348
bool ordered() const
Definition: type.h:758
Concrete type class for union data.
Definition: type.h:552
YEAR_MONTH or DAY_TIME interval in SQL style.
Definition: type.h:116
const std::string & timezone() const
Definition: type.h:708
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:390
Precision- and scale-based decimal type.
Definition: type.h:120
BinaryType(Type::type logical_type)
Definition: type.h:457
Decimal128Type(int32_t precision, int32_t scale)
Definition: type.h:539
Base class for all data types representing primitive values.
Definition: type.h:201
Concrete type class for signed 64-bit integer data.
Definition: type.h:387
UnionMode::type mode() const
Definition: type.h:566
std::shared_ptr< DataType > timestamp(TimeUnit::type unit)
Create a TimestampType instance from its unit.
TimeUnit::type unit_
Definition: type.h:655
Concrete type class for fixed-size binary data.
Definition: type.h:461
StructType(const std::vector< std::shared_ptr< Field >> &fields)
Definition: type.h:498
int num_fields() const
Return the number of fields (columns) in the schema.
Definition: type.h:825