polars_arrow/datatypes/physical_type.rs
1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4pub use crate::types::PrimitiveType;
5
6/// The set of physical types: unique in-memory representations of an Arrow array.
7///
8/// A physical type has a one-to-many relationship with a [`crate::datatypes::ArrowDataType`] and
9/// a one-to-one mapping to each struct in this crate that implements [`crate::array::Array`].
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12pub enum PhysicalType {
13 /// A Null with no allocation.
14 Null,
15 /// A boolean represented as a single bit.
16 Boolean,
17 /// An array where each slot has a known compile-time size.
18 Primitive(PrimitiveType),
19 /// Opaque binary data of variable length.
20 Binary,
21 /// Opaque binary data of fixed size.
22 FixedSizeBinary,
23 /// Opaque binary data of variable length and 64-bit offsets.
24 LargeBinary,
25 /// A variable-length string in Unicode with UTF-8 encoding.
26 Utf8,
27 /// A variable-length string in Unicode with UFT-8 encoding and 64-bit offsets.
28 LargeUtf8,
29 /// A list of some data type with variable length.
30 List,
31 /// A list of some data type with fixed length.
32 FixedSizeList,
33 /// A list of some data type with variable length and 64-bit offsets.
34 LargeList,
35 /// A nested type that contains an arbitrary number of fields.
36 Struct,
37 /// A nested type that represents slots of differing types.
38 Union,
39 /// A nested type.
40 Map,
41 /// A dictionary encoded array by `IntegerType`.
42 Dictionary(IntegerType),
43 /// A binary type that inlines small values
44 /// and can intern bytes.
45 BinaryView,
46 /// A string type that inlines small values
47 /// and can intern strings.
48 Utf8View,
49}
50
51impl PhysicalType {
52 /// Whether this physical type equals [`PhysicalType::Primitive`] of type `primitive`.
53 pub fn eq_primitive(&self, primitive: PrimitiveType) -> bool {
54 if let Self::Primitive(o) = self {
55 o == &primitive
56 } else {
57 false
58 }
59 }
60
61 pub fn is_primitive(&self) -> bool {
62 matches!(self, Self::Primitive(_))
63 }
64}
65
66/// the set of valid indices types of a dictionary-encoded Array.
67/// Each type corresponds to a variant of [`crate::array::DictionaryArray`].
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
69#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
70pub enum IntegerType {
71 /// A signed 8-bit integer.
72 Int8,
73 /// A signed 16-bit integer.
74 Int16,
75 /// A signed 32-bit integer.
76 Int32,
77 /// A signed 64-bit integer.
78 Int64,
79 /// A signed 128-bit integer.
80 Int128,
81 /// An unsigned 8-bit integer.
82 UInt8,
83 /// An unsigned 16-bit integer.
84 UInt16,
85 /// An unsigned 32-bit integer.
86 UInt32,
87 /// An unsigned 64-bit integer.
88 UInt64,
89}