arrow_sql_server/arrow/
field.rs1use arrow_schema::DataType;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct ArrowFieldRef {
11 index: usize,
12 name: String,
13 nullable: bool,
14 data_type: DataType,
15}
16
17impl ArrowFieldRef {
18 pub const fn new(index: usize, name: String, nullable: bool, data_type: DataType) -> Self {
20 Self {
21 index,
22 name,
23 nullable,
24 data_type,
25 }
26 }
27
28 pub const fn index(&self) -> usize {
30 self.index
31 }
32
33 pub fn name(&self) -> &str {
35 &self.name
36 }
37
38 pub const fn nullable(&self) -> bool {
40 self.nullable
41 }
42
43 pub const fn data_type(&self) -> &DataType {
45 &self.data_type
46 }
47}
48
49pub(crate) fn is_arrow_string_family(data_type: &DataType) -> bool {
51 matches!(
52 data_type,
53 DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View
54 )
55}
56
57pub(crate) fn is_arrow_binary_family(data_type: &DataType) -> bool {
59 matches!(
60 data_type,
61 DataType::Binary | DataType::LargeBinary | DataType::BinaryView
62 )
63}
64
65#[cfg(test)]
66mod tests {
67 use arrow_schema::DataType;
68
69 use super::{is_arrow_binary_family, is_arrow_string_family};
70
71 #[test]
72 fn identifies_arrow_variable_width_representation_families() {
73 for data_type in [DataType::Utf8, DataType::LargeUtf8, DataType::Utf8View] {
74 assert!(is_arrow_string_family(&data_type));
75 assert!(!is_arrow_binary_family(&data_type));
76 }
77
78 for data_type in [
79 DataType::Binary,
80 DataType::LargeBinary,
81 DataType::BinaryView,
82 ] {
83 assert!(is_arrow_binary_family(&data_type));
84 assert!(!is_arrow_string_family(&data_type));
85 }
86
87 for data_type in [DataType::Int32, DataType::FixedSizeBinary(4)] {
88 assert!(!is_arrow_string_family(&data_type));
89 assert!(!is_arrow_binary_family(&data_type));
90 }
91 }
92}