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 <unordered_map>
27 #include <vector>
28 
29 #include "arrow/status.h"
30 #include "arrow/type_fwd.h" // IWYU pragma: export
33 #include "arrow/util/macros.h"
34 #include "arrow/util/visibility.h"
35 #include "arrow/visitor.h"
36 
37 namespace arrow {
38 
45 struct Type {
46  enum type {
48  NA,
49 
52 
55 
58 
61 
64 
67 
70 
73 
76 
79 
82 
85 
88 
91 
94 
97 
100 
104 
108 
112 
115 
119 
122 
125 
128 
131 
134  };
135 };
136 
137 class ARROW_EXPORT DataType {
138  public:
139  explicit DataType(Type::type id) : id_(id) {}
140  virtual ~DataType();
141 
142  // Return whether the types are equal
143  //
144  // Types that are logically convertible from one to another (e.g. List<UInt8>
145  // and Binary) are NOT equal.
146  virtual bool Equals(const DataType& other) const;
147  bool Equals(const std::shared_ptr<DataType>& other) const;
148 
149  std::shared_ptr<Field> child(int i) const { return children_[i]; }
150 
151  const std::vector<std::shared_ptr<Field>>& children() const { return children_; }
152 
153  int num_children() const { return static_cast<int>(children_.size()); }
154 
155  virtual Status Accept(TypeVisitor* visitor) const = 0;
156 
158  virtual std::string ToString() const = 0;
159 
164  virtual std::string name() const = 0;
165 
166  Type::type id() const { return id_; }
167 
168  protected:
170  std::vector<std::shared_ptr<Field>> children_;
171 
172  private:
174 };
175 
176 inline std::ostream& operator<<(std::ostream& os, const DataType& type) {
177  os << type.ToString();
178  return os;
179 }
180 
181 // TODO(wesm): Remove this from parquet-cpp
182 using TypePtr = std::shared_ptr<DataType>;
183 
184 class ARROW_EXPORT FixedWidthType : public DataType {
185  public:
186  using DataType::DataType;
187 
188  virtual int bit_width() const = 0;
189 };
190 
191 class ARROW_EXPORT PrimitiveCType : public FixedWidthType {
192  public:
193  using FixedWidthType::FixedWidthType;
194 };
195 
196 class ARROW_EXPORT Number : public PrimitiveCType {
197  public:
198  using PrimitiveCType::PrimitiveCType;
199 };
200 
201 class ARROW_EXPORT Integer : public Number {
202  public:
203  using Number::Number;
204  virtual bool is_signed() const = 0;
205 };
206 
207 class ARROW_EXPORT FloatingPoint : public Number {
208  public:
209  using Number::Number;
210  enum Precision { HALF, SINGLE, DOUBLE };
211  virtual Precision precision() const = 0;
212 };
213 
216 class ParametricType {};
217 
218 class ARROW_EXPORT NestedType : public DataType, public ParametricType {
219  public:
220  using DataType::DataType;
221 };
222 
223 class NoExtraMeta {};
224 
225 // A field is a piece of metadata that includes (for now) a name and a data
226 // type
227 class ARROW_EXPORT Field {
228  public:
229  Field(const std::string& name, const std::shared_ptr<DataType>& type,
230  bool nullable = true,
231  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR)
232  : name_(name), type_(type), nullable_(nullable), metadata_(metadata) {}
233 
234  std::shared_ptr<const KeyValueMetadata> metadata() const { return metadata_; }
235 
236  std::shared_ptr<Field> AddMetadata(
237  const std::shared_ptr<const KeyValueMetadata>& metadata) const;
238  std::shared_ptr<Field> RemoveMetadata() const;
239 
240  std::vector<std::shared_ptr<Field>> Flatten() const;
241 
242  bool Equals(const Field& other) const;
243  bool Equals(const std::shared_ptr<Field>& other) const;
244 
245  std::string ToString() const;
246 
247  const std::string& name() const { return name_; }
248  std::shared_ptr<DataType> type() const { return type_; }
249  bool nullable() const { return nullable_; }
250 
251  private:
252  // Field name
253  std::string name_;
254 
255  // The field's data type
256  std::shared_ptr<DataType> type_;
257 
258  // Fields can be nullable
259  bool nullable_;
260 
261  // The field's metadata, if any
262  std::shared_ptr<const KeyValueMetadata> metadata_;
263 };
264 
265 namespace detail {
266 
267 template <typename DERIVED, typename BASE, Type::type TYPE_ID, typename C_TYPE>
268 class ARROW_EXPORT CTypeImpl : public BASE {
269  public:
270  using c_type = C_TYPE;
271  static constexpr Type::type type_id = TYPE_ID;
272 
273  CTypeImpl() : BASE(TYPE_ID) {}
274 
275  int bit_width() const override { return static_cast<int>(sizeof(C_TYPE) * CHAR_BIT); }
276 
277  Status Accept(TypeVisitor* visitor) const override {
278  return visitor->Visit(checked_cast<const DERIVED&>(*this));
279  }
280 
281  std::string ToString() const override { return this->name(); }
282 };
283 
284 template <typename DERIVED, Type::type TYPE_ID, typename C_TYPE>
285 class IntegerTypeImpl : public detail::CTypeImpl<DERIVED, Integer, TYPE_ID, C_TYPE> {
286  bool is_signed() const override { return std::is_signed<C_TYPE>::value; }
287 };
288 
289 } // namespace detail
290 
291 class ARROW_EXPORT NullType : public DataType, public NoExtraMeta {
292  public:
293  static constexpr Type::type type_id = Type::NA;
294 
295  NullType() : DataType(Type::NA) {}
296 
297  Status Accept(TypeVisitor* visitor) const override;
298  std::string ToString() const override;
299 
300  std::string name() const override { return "null"; }
301 };
302 
303 class ARROW_EXPORT BooleanType : public FixedWidthType, public NoExtraMeta {
304  public:
305  static constexpr Type::type type_id = Type::BOOL;
306 
308 
309  Status Accept(TypeVisitor* visitor) const override;
310  std::string ToString() const override;
311 
312  int bit_width() const override { return 1; }
313  std::string name() const override { return "bool"; }
314 };
315 
316 class ARROW_EXPORT UInt8Type
317  : public detail::IntegerTypeImpl<UInt8Type, Type::UINT8, uint8_t> {
318  public:
319  std::string name() const override { return "uint8"; }
320 };
321 
322 class ARROW_EXPORT Int8Type
323  : public detail::IntegerTypeImpl<Int8Type, Type::INT8, int8_t> {
324  public:
325  std::string name() const override { return "int8"; }
326 };
327 
328 class ARROW_EXPORT UInt16Type
329  : public detail::IntegerTypeImpl<UInt16Type, Type::UINT16, uint16_t> {
330  public:
331  std::string name() const override { return "uint16"; }
332 };
333 
334 class ARROW_EXPORT Int16Type
335  : public detail::IntegerTypeImpl<Int16Type, Type::INT16, int16_t> {
336  public:
337  std::string name() const override { return "int16"; }
338 };
339 
340 class ARROW_EXPORT UInt32Type
341  : public detail::IntegerTypeImpl<UInt32Type, Type::UINT32, uint32_t> {
342  public:
343  std::string name() const override { return "uint32"; }
344 };
345 
346 class ARROW_EXPORT Int32Type
347  : public detail::IntegerTypeImpl<Int32Type, Type::INT32, int32_t> {
348  public:
349  std::string name() const override { return "int32"; }
350 };
351 
352 class ARROW_EXPORT UInt64Type
353  : public detail::IntegerTypeImpl<UInt64Type, Type::UINT64, uint64_t> {
354  public:
355  std::string name() const override { return "uint64"; }
356 };
357 
358 class ARROW_EXPORT Int64Type
359  : public detail::IntegerTypeImpl<Int64Type, Type::INT64, int64_t> {
360  public:
361  std::string name() const override { return "int64"; }
362 };
363 
364 class ARROW_EXPORT HalfFloatType
365  : public detail::CTypeImpl<HalfFloatType, FloatingPoint, Type::HALF_FLOAT, uint16_t> {
366  public:
367  Precision precision() const override;
368  std::string name() const override { return "halffloat"; }
369 };
370 
371 class ARROW_EXPORT FloatType
372  : public detail::CTypeImpl<FloatType, FloatingPoint, Type::FLOAT, float> {
373  public:
374  Precision precision() const override;
375  std::string name() const override { return "float"; }
376 };
377 
378 class ARROW_EXPORT DoubleType
379  : public detail::CTypeImpl<DoubleType, FloatingPoint, Type::DOUBLE, double> {
380  public:
381  Precision precision() const override;
382  std::string name() const override { return "double"; }
383 };
384 
385 class ARROW_EXPORT ListType : public NestedType {
386  public:
387  static constexpr Type::type type_id = Type::LIST;
388 
389  // List can contain any other logical value type
390  explicit ListType(const std::shared_ptr<DataType>& value_type)
391  : ListType(std::make_shared<Field>("item", value_type)) {}
392 
393  explicit ListType(const std::shared_ptr<Field>& value_field) : NestedType(Type::LIST) {
394  children_ = {value_field};
395  }
396 
397  std::shared_ptr<Field> value_field() const { return children_[0]; }
398 
399  std::shared_ptr<DataType> value_type() const { return children_[0]->type(); }
400 
401  Status Accept(TypeVisitor* visitor) const override;
402  std::string ToString() const override;
403 
404  std::string name() const override { return "list"; }
405 };
406 
407 namespace meta {
408 
410 template <typename T>
411 class ARROW_EXPORT ListType : public ::arrow::ListType {
412  public:
413  using ValueType = T;
414 
415  ListType() : ::arrow::ListType(std::make_shared<T>()) {}
416 };
417 
418 } // namespace meta
419 
420 // BinaryType type is represents lists of 1-byte values.
421 class ARROW_EXPORT BinaryType : public DataType, public NoExtraMeta {
422  public:
423  static constexpr Type::type type_id = Type::BINARY;
424 
425  BinaryType() : BinaryType(Type::BINARY) {}
426 
427  Status Accept(TypeVisitor* visitor) const override;
428  std::string ToString() const override;
429  std::string name() const override { return "binary"; }
430 
431  protected:
432  // Allow subclasses to change the logical type.
433  explicit BinaryType(Type::type logical_type) : DataType(logical_type) {}
434 };
435 
436 // BinaryType type is represents lists of 1-byte values.
437 class ARROW_EXPORT FixedSizeBinaryType : public FixedWidthType, public ParametricType {
438  public:
439  static constexpr Type::type type_id = Type::FIXED_SIZE_BINARY;
440 
441  explicit FixedSizeBinaryType(int32_t byte_width)
442  : FixedWidthType(Type::FIXED_SIZE_BINARY), byte_width_(byte_width) {}
443  explicit FixedSizeBinaryType(int32_t byte_width, Type::type override_type_id)
444  : FixedWidthType(override_type_id), byte_width_(byte_width) {}
445 
446  Status Accept(TypeVisitor* visitor) const override;
447  std::string ToString() const override;
448  std::string name() const override { return "fixed_size_binary"; }
449 
450  int32_t byte_width() const { return byte_width_; }
451  int bit_width() const override;
452 
453  protected:
454  int32_t byte_width_;
455 };
456 
457 // UTF-8 encoded strings
458 class ARROW_EXPORT StringType : public BinaryType {
459  public:
460  static constexpr Type::type type_id = Type::STRING;
461 
462  StringType() : BinaryType(Type::STRING) {}
463 
464  Status Accept(TypeVisitor* visitor) const override;
465  std::string ToString() const override;
466  std::string name() const override { return "utf8"; }
467 };
468 
469 class ARROW_EXPORT StructType : public NestedType {
470  public:
471  static constexpr Type::type type_id = Type::STRUCT;
472 
473  explicit StructType(const std::vector<std::shared_ptr<Field>>& fields)
474  : NestedType(Type::STRUCT) {
475  children_ = fields;
476  }
477 
478  Status Accept(TypeVisitor* visitor) const override;
479  std::string ToString() const override;
480  std::string name() const override { return "struct"; }
481 
483  std::shared_ptr<Field> GetChildByName(const std::string& name) const;
484 
486  int GetChildIndex(const std::string& name) const;
487 
488  private:
490  mutable std::unordered_map<std::string, int> name_to_index_;
491 };
492 
493 class ARROW_EXPORT DecimalType : public FixedSizeBinaryType {
494  public:
495  explicit DecimalType(int32_t byte_width, int32_t precision, int32_t scale)
496  : FixedSizeBinaryType(byte_width, Type::DECIMAL),
497  precision_(precision),
498  scale_(scale) {}
499 
500  int32_t precision() const { return precision_; }
501  int32_t scale() const { return scale_; }
502 
503  protected:
504  int32_t precision_;
505  int32_t scale_;
506 };
507 
508 class ARROW_EXPORT Decimal128Type : public DecimalType {
509  public:
510  static constexpr Type::type type_id = Type::DECIMAL;
511 
512  explicit Decimal128Type(int32_t precision, int32_t scale)
513  : DecimalType(16, precision, scale) {}
514 
515  Status Accept(TypeVisitor* visitor) const override;
516  std::string ToString() const override;
517  std::string name() const override { return "decimal"; }
518 };
519 
520 struct UnionMode {
521  enum type { SPARSE, DENSE };
522 };
523 
524 class ARROW_EXPORT UnionType : public NestedType {
525  public:
526  static constexpr Type::type type_id = Type::UNION;
527 
528  UnionType(const std::vector<std::shared_ptr<Field>>& fields,
529  const std::vector<uint8_t>& type_codes,
531 
532  std::string ToString() const override;
533  std::string name() const override { return "union"; }
534  Status Accept(TypeVisitor* visitor) const override;
535 
536  const std::vector<uint8_t>& type_codes() const { return type_codes_; }
537 
538  UnionMode::type mode() const { return mode_; }
539 
540  private:
541  UnionMode::type mode_;
542 
543  // The type id used in the data to indicate each data type in the union. For
544  // example, the first type in the union might be denoted by the id 5 (instead
545  // of 0).
546  std::vector<uint8_t> type_codes_;
547 };
548 
549 // ----------------------------------------------------------------------
550 // Date and time types
551 
552 enum class DateUnit : char { DAY = 0, MILLI = 1 };
553 
554 class ARROW_EXPORT DateType : public FixedWidthType {
555  public:
556  DateUnit unit() const { return unit_; }
557 
558  protected:
559  DateType(Type::type type_id, DateUnit unit);
561 };
562 
564 class ARROW_EXPORT Date32Type : public DateType {
565  public:
566  static constexpr Type::type type_id = Type::DATE32;
567 
568  using c_type = int32_t;
569 
570  Date32Type();
571 
572  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
573 
574  Status Accept(TypeVisitor* visitor) const override;
575  std::string ToString() const override;
576 
577  std::string name() const override { return "date32"; }
578 };
579 
581 class ARROW_EXPORT Date64Type : public DateType {
582  public:
583  static constexpr Type::type type_id = Type::DATE64;
584 
585  using c_type = int64_t;
586 
587  Date64Type();
588 
589  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
590 
591  Status Accept(TypeVisitor* visitor) const override;
592  std::string ToString() const override;
593 
594  std::string name() const override { return "date64"; }
595 };
596 
597 struct TimeUnit {
598  enum type { SECOND = 0, MILLI = 1, MICRO = 2, NANO = 3 };
599 };
600 
601 static inline std::ostream& operator<<(std::ostream& os, TimeUnit::type unit) {
602  switch (unit) {
603  case TimeUnit::SECOND:
604  os << "s";
605  break;
606  case TimeUnit::MILLI:
607  os << "ms";
608  break;
609  case TimeUnit::MICRO:
610  os << "us";
611  break;
612  case TimeUnit::NANO:
613  os << "ns";
614  break;
615  }
616  return os;
617 }
618 
619 class ARROW_EXPORT TimeType : public FixedWidthType, public ParametricType {
620  public:
621  TimeUnit::type unit() const { return unit_; }
622 
623  protected:
624  TimeType(Type::type type_id, TimeUnit::type unit);
626 };
627 
628 class ARROW_EXPORT Time32Type : public TimeType {
629  public:
630  static constexpr Type::type type_id = Type::TIME32;
631  using c_type = int32_t;
632 
633  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
634 
635  explicit Time32Type(TimeUnit::type unit = TimeUnit::MILLI);
636 
637  Status Accept(TypeVisitor* visitor) const override;
638  std::string ToString() const override;
639 
640  std::string name() const override { return "time32"; }
641 };
642 
643 class ARROW_EXPORT Time64Type : public TimeType {
644  public:
645  static constexpr Type::type type_id = Type::TIME64;
646  using c_type = int64_t;
647 
648  int bit_width() const override { return static_cast<int>(sizeof(c_type) * CHAR_BIT); }
649 
650  explicit Time64Type(TimeUnit::type unit = TimeUnit::MILLI);
651 
652  Status Accept(TypeVisitor* visitor) const override;
653  std::string ToString() const override;
654 
655  std::string name() const override { return "time64"; }
656 };
657 
658 class ARROW_EXPORT TimestampType : public FixedWidthType, public ParametricType {
659  public:
660  using Unit = TimeUnit;
661 
662  typedef int64_t c_type;
663  static constexpr Type::type type_id = Type::TIMESTAMP;
664 
665  int bit_width() const override { return static_cast<int>(sizeof(int64_t) * CHAR_BIT); }
666 
668  : FixedWidthType(Type::TIMESTAMP), unit_(unit) {}
669 
670  explicit TimestampType(TimeUnit::type unit, const std::string& timezone)
671  : FixedWidthType(Type::TIMESTAMP), unit_(unit), timezone_(timezone) {}
672 
673  Status Accept(TypeVisitor* visitor) const override;
674  std::string ToString() const override;
675  std::string name() const override { return "timestamp"; }
676 
677  TimeUnit::type unit() const { return unit_; }
678  const std::string& timezone() const { return timezone_; }
679 
680  private:
681  TimeUnit::type unit_;
682  std::string timezone_;
683 };
684 
685 class ARROW_EXPORT IntervalType : public FixedWidthType {
686  public:
687  enum class Unit : char { YEAR_MONTH = 0, DAY_TIME = 1 };
688 
689  using c_type = int64_t;
690  static constexpr Type::type type_id = Type::INTERVAL;
691 
692  int bit_width() const override { return static_cast<int>(sizeof(int64_t) * CHAR_BIT); }
693 
694  explicit IntervalType(Unit unit = Unit::YEAR_MONTH)
695  : FixedWidthType(Type::INTERVAL), unit_(unit) {}
696 
697  Status Accept(TypeVisitor* visitor) const override;
698  std::string ToString() const override { return name(); }
699  std::string name() const override { return "date"; }
700 
701  Unit unit() const { return unit_; }
702 
703  private:
704  Unit unit_;
705 };
706 
707 // ----------------------------------------------------------------------
708 // DictionaryType (for categorical or dictionary-encoded data)
709 
710 class ARROW_EXPORT DictionaryType : public FixedWidthType {
711  public:
712  static constexpr Type::type type_id = Type::DICTIONARY;
713 
714  DictionaryType(const std::shared_ptr<DataType>& index_type,
715  const std::shared_ptr<Array>& dictionary, bool ordered = false);
716 
717  int bit_width() const override;
718 
719  std::shared_ptr<DataType> index_type() const { return index_type_; }
720 
721  std::shared_ptr<Array> dictionary() const;
722 
723  Status Accept(TypeVisitor* visitor) const override;
724  std::string ToString() const override;
725  std::string name() const override { return "dictionary"; }
726 
727  bool ordered() const { return ordered_; }
728 
729  private:
730  // Must be an integer type (not currently checked)
731  std::shared_ptr<DataType> index_type_;
732  std::shared_ptr<Array> dictionary_;
733  bool ordered_;
734 };
735 
736 // ----------------------------------------------------------------------
737 // Schema
738 
742 class ARROW_EXPORT Schema {
743  public:
744  explicit Schema(const std::vector<std::shared_ptr<Field>>& fields,
745  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
746 
747  explicit Schema(std::vector<std::shared_ptr<Field>>&& fields,
748  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
749 
750  virtual ~Schema() = default;
751 
753  bool Equals(const Schema& other) const;
754 
756  std::shared_ptr<Field> field(int i) const { return fields_[i]; }
757 
759  std::shared_ptr<Field> GetFieldByName(const std::string& name) const;
760 
762  int64_t GetFieldIndex(const std::string& name) const;
763 
764  const std::vector<std::shared_ptr<Field>>& fields() const { return fields_; }
765 
769  std::shared_ptr<const KeyValueMetadata> metadata() const;
770 
772  std::string ToString() const;
773 
774  Status AddField(int i, const std::shared_ptr<Field>& field,
775  std::shared_ptr<Schema>* out) const;
776  Status RemoveField(int i, std::shared_ptr<Schema>* out) const;
777 
782  std::shared_ptr<Schema> AddMetadata(
783  const std::shared_ptr<const KeyValueMetadata>& metadata) const;
784 
786  std::shared_ptr<Schema> RemoveMetadata() const;
787 
789  int num_fields() const { return static_cast<int>(fields_.size()); }
790 
791  private:
792  std::vector<std::shared_ptr<Field>> fields_;
793 
795  mutable std::unordered_map<std::string, int> name_to_index_;
796 
797  std::shared_ptr<const KeyValueMetadata> metadata_;
798 };
799 
800 // ----------------------------------------------------------------------
801 // Factory functions
802 
804 ARROW_EXPORT
805 std::shared_ptr<DataType> fixed_size_binary(int32_t byte_width);
806 
808 ARROW_EXPORT
809 std::shared_ptr<DataType> decimal(int32_t precision, int32_t scale);
810 
812 ARROW_EXPORT
813 std::shared_ptr<DataType> list(const std::shared_ptr<Field>& value_type);
814 
816 ARROW_EXPORT
817 std::shared_ptr<DataType> list(const std::shared_ptr<DataType>& value_type);
818 
820 ARROW_EXPORT
821 std::shared_ptr<DataType> timestamp(TimeUnit::type unit);
822 
824 ARROW_EXPORT
825 std::shared_ptr<DataType> timestamp(TimeUnit::type unit, const std::string& timezone);
826 
829 std::shared_ptr<DataType> ARROW_EXPORT time32(TimeUnit::type unit);
830 
833 std::shared_ptr<DataType> ARROW_EXPORT time64(TimeUnit::type unit);
834 
836 std::shared_ptr<DataType> ARROW_EXPORT
837 struct_(const std::vector<std::shared_ptr<Field>>& fields);
838 
840 std::shared_ptr<DataType> ARROW_EXPORT
841 union_(const std::vector<std::shared_ptr<Field>>& child_fields,
842  const std::vector<uint8_t>& type_codes, UnionMode::type mode = UnionMode::SPARSE);
843 
845 std::shared_ptr<DataType> ARROW_EXPORT
846 union_(const std::vector<std::shared_ptr<Array>>& children,
848 
850 std::shared_ptr<DataType> ARROW_EXPORT
851 dictionary(const std::shared_ptr<DataType>& index_type,
852  const std::shared_ptr<Array>& values, bool ordered = false);
853 
860 std::shared_ptr<Field> ARROW_EXPORT field(
861  const std::string& name, const std::shared_ptr<DataType>& type, bool nullable = true,
862  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
863 
869 ARROW_EXPORT
870 std::shared_ptr<Schema> schema(
871  const std::vector<std::shared_ptr<Field>>& fields,
872  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
873 
879 ARROW_EXPORT
880 std::shared_ptr<Schema> schema(
881  std::vector<std::shared_ptr<Field>>&& fields,
882  const std::shared_ptr<const KeyValueMetadata>& metadata = NULLPTR);
883 
884 } // namespace arrow
885 
886 #endif // ARROW_TYPE_H
Definition: type.h:469
int bit_width() const override
Definition: type.h:648
std::string ToString() const override
A string representation of the type, including any children.
Definition: type.h:698
ListType()
Definition: type.h:415
std::shared_ptr< const KeyValueMetadata > metadata() const
Definition: type.h:234
Definition: type.h:597
Definition: type.h:520
A NULL type having no physical storage.
Definition: type.h:48
int bit_width() const override
Definition: type.h:312
const std::string & name() const
Definition: type.h:247
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:577
Definition: type.h:207
Definition: type.h:364
FixedSizeBinaryType(int32_t byte_width, Type::type override_type_id)
Definition: type.h:443
int32_t byte_width_
Definition: type.h:454
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:375
DateUnit unit() const
Definition: type.h:556
int32_t precision() const
Definition: type.h:500
Definition: type.h:316
A superclass for types having additional metadata.
Definition: type.h:216
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:349
type
Definition: type.h:46
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:675
Unsigned 16-bit little-endian integer.
Definition: type.h:60
Definition: type.h:196
IntervalType(Unit unit=Unit::YEAR_MONTH)
Definition: type.h:694
BinaryType()
Definition: type.h:425
Main data type enumeration.
Definition: type.h:45
Definition: type.h:378
const std::vector< std::shared_ptr< Field > > & fields() const
Definition: type.h:764
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:404
std::shared_ptr< Field > child(int i) const
Definition: type.h:149
Unsigned 32-bit little-endian integer.
Definition: type.h:66
int32_t c_type
Definition: type.h:568
std::shared_ptr< DataType > index_type() const
Definition: type.h:719
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:594
Unsigned 8-bit little-endian integer.
Definition: type.h:54
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:355
int64_t c_type
Definition: type.h:585
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:343
Definition: type.h:598
Signed 8-bit little-endian integer.
Definition: type.h:57
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:300
NullType()
Definition: type.h:295
Date as int64_t milliseconds since UNIX epoch.
Definition: type.h:581
std::shared_ptr< DataType > list(const std::shared_ptr< Field > &value_type)
Make an instance of ListType.
A list of some logical data type.
Definition: type.h:121
#define NULLPTR
Definition: macros.h:69
Definition: type.h:521
std::shared_ptr< DataType > value_type() const
Definition: type.h:399
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:517
T ValueType
Definition: type.h:413
DateUnit
Definition: type.h:552
Dictionary aka Category type.
Definition: type.h:130
Time as signed 64-bit integer, representing either microseconds or nanoseconds since midnight...
Definition: type.h:111
Additional ListType class that can be instantiated with only compile-time arguments.
Definition: type.h:411
virtual std::string ToString() const =0
A string representation of the type, including any children.
TimeUnit::type unit() const
Definition: type.h:677
Signed 32-bit little-endian integer.
Definition: type.h:69
Map, a repeated struct logical type.
Definition: type.h:133
Type::type id() const
Definition: type.h:166
DataType(Type::type id)
Definition: type.h:139
Time as signed 32-bit integer, representing either seconds or milliseconds since midnight.
Definition: type.h:107
std::shared_ptr< DataType > time32(TimeUnit::type unit)
Create an instance of 32-bit time type Unit can be either SECOND or MILLI.
Definition: status.h:93
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:313
type
Definition: type.h:598
Type::type id_
Definition: type.h:169
bool nullable() const
Definition: type.h:249
int32_t days since the UNIX epoch
Definition: type.h:96
std::shared_ptr< DataType > decimal(int32_t precision, int32_t scale)
Make an instance of DecimalType.
std::shared_ptr< DataType > dictionary(const std::shared_ptr< DataType > &index_type, const std::shared_ptr< Array > &values, bool ordered=false)
Create an instance of Dictionary type.
int64_t c_type
Definition: type.h:646
std::shared_ptr< DataType > fixed_size_binary(int32_t byte_width)
Make an instance of FixedSizeBinaryType.
int32_t scale_
Definition: type.h:505
type
Definition: type.h:521
int64_t c_type
Definition: type.h:689
Definition: type.h:598
ListType(const std::shared_ptr< Field > &value_field)
Definition: type.h:393
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:448
4-byte floating point value
Definition: type.h:81
Unit unit() const
Definition: type.h:701
Signed 16-bit little-endian integer.
Definition: type.h:63
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:725
const std::vector< uint8_t > & type_codes() const
Definition: type.h:536
DateUnit unit_
Definition: type.h:560
Definition: type.h:328
Definition: type.h:658
Definition: type.h:184
Boolean as 1 bit, LSB bit-packed ordering.
Definition: type.h:51
Signed 64-bit little-endian integer.
Definition: type.h:75
Definition: type.h:340
Struct of logical types.
Definition: type.h:124
Variable-length bytes (no guarantee of UTF8-ness)
Definition: type.h:90
Definition: type.h:291
int bit_width() const override
Definition: type.h:633
int bit_width() const override
Definition: type.h:589
Definition: type.h:421
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:466
std::shared_ptr< DataType > type() const
Definition: type.h:248
Definition: type.h:303
TimestampType(TimeUnit::type unit, const std::string &timezone)
Definition: type.h:670
ListType(const std::shared_ptr< DataType > &value_type)
Definition: type.h:390
Definition: type.h:685
Definition: type.h:385
StringType()
Definition: type.h:462
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:640
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:331
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:319
Definition: type.h:598
Exact timestamp encoded with int64 since UNIX epoch Default unit millisecond.
Definition: type.h:103
Definition: type.h:458
Unit
Definition: type.h:687
int bit_width() const override
Definition: type.h:692
Fixed-size binary. Each value occupies the same number of bytes.
Definition: type.h:93
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:429
std::vector< std::shared_ptr< Field > > children_
Definition: type.h:170
Definition: type.h:493
Definition: type.h:201
TimeUnit::type unit() const
Definition: type.h:621
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:382
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:699
TimestampType(TimeUnit::type unit=TimeUnit::MILLI)
Definition: type.h:667
std::shared_ptr< Field > value_field() const
Definition: type.h:397
const std::vector< std::shared_ptr< Field > > & children() const
Definition: type.h:151
Definition: type.h:218
Sequence of arrow::Field objects describing the columns of a record batch or table data structure...
Definition: type.h:742
Definition: type.h:598
std::ostream & operator<<(std::ostream &os, const DataType &type)
Definition: type.h:176
Definition: type.h:227
Top-level namespace for Apache Arrow C++ API.
Definition: adapter.h:32
Definition: type.h:619
Definition: type.h:508
int32_t precision_
Definition: type.h:504
Definition: type.h:371
FixedSizeBinaryType(int32_t byte_width)
Definition: type.h:441
Definition: type.h:334
int bit_width() const override
Definition: type.h:665
8-byte floating point value
Definition: type.h:84
int32_t scale() const
Definition: type.h:501
Definition: type.h:346
Date as int32_t days since UNIX epoch.
Definition: type.h:564
DecimalType(int32_t byte_width, int32_t precision, int32_t scale)
Definition: type.h:495
Definition: type.h:554
int32_t byte_width() const
Definition: type.h:450
int64_t milliseconds since the UNIX epoch
Definition: type.h:99
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 an instance of Union type.
Definition: type.h:210
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:368
Definition: type.h:521
int32_t c_type
Definition: type.h:631
std::shared_ptr< DataType > time64(TimeUnit::type unit)
Create an instance of 64-bit time type Unit can be either MICRO or NANO.
UTF8 variable-length string as List<Char>
Definition: type.h:87
Precision
Definition: type.h:210
Unsigned 64-bit little-endian integer.
Definition: type.h:72
std::shared_ptr< DataType > struct_(const std::vector< std::shared_ptr< Field >> &fields)
Create an instance of Struct type.
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:223
BooleanType()
Definition: type.h:307
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:229
Definition: type.h:710
int bit_width() const override
Definition: type.h:572
Definition: type.h:643
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:533
Definition: type.h:352
std::shared_ptr< Field > field(int i) const
Return the ith schema element. Does not boundscheck.
Definition: type.h:756
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:480
int num_children() const
Definition: type.h:153
Definition: type.h:322
int64_t c_type
Definition: type.h:662
virtual bool is_signed() const =0
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:655
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:337
2-byte floating point value
Definition: type.h:78
Definition: type.h:628
Unions of logical types.
Definition: type.h:127
Definition: type.h:137
std::shared_ptr< DataType > TypePtr
Definition: type.h:182
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:325
bool ordered() const
Definition: type.h:727
Definition: type.h:524
#define ARROW_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:23
YEAR_MONTH or DAY_TIME interval in SQL style.
Definition: type.h:114
const std::string & timezone() const
Definition: type.h:678
std::string name() const override
A string name of the type, omitting any child fields.
Definition: type.h:361
Precision- and scale-based decimal type.
Definition: type.h:118
BinaryType(Type::type logical_type)
Definition: type.h:433
Decimal128Type(int32_t precision, int32_t scale)
Definition: type.h:512
Definition: type.h:191
Definition: type.h:358
UnionMode::type mode() const
Definition: type.h:538
std::shared_ptr< DataType > timestamp(TimeUnit::type unit)
Make an instance of TimestampType.
TimeUnit::type unit_
Definition: type.h:625
Definition: type.h:437
StructType(const std::vector< std::shared_ptr< Field >> &fields)
Definition: type.h:473
int num_fields() const
Return the number of fields (columns) in the schema.
Definition: type.h:789