@@ -4,7 +4,8 @@ use crate::types::{FromSqlError, FromSqlResult};
44use crate :: Row ;
55use rust_decimal:: prelude:: * ;
66
7- use arrow:: array:: { Array , ListArray } ;
7+ use arrow:: array:: { Array , DictionaryArray , ListArray } ;
8+ use arrow:: datatypes:: { UInt16Type , UInt32Type , UInt8Type } ;
89
910/// An absolute length of time in seconds, milliseconds, microseconds or nanoseconds.
1011/// Copy from arrow::datatypes::TimeUnit
@@ -75,6 +76,19 @@ pub enum ValueRef<'a> {
7576 } ,
7677 /// The value is a list
7778 List ( & ' a ListArray , usize ) ,
79+ /// The value is an enum
80+ Enum ( EnumType < ' a > , usize ) ,
81+ }
82+
83+ /// Wrapper type for different enum sizes
84+ #[ derive( Debug , Copy , Clone , PartialEq ) ]
85+ pub enum EnumType < ' a > {
86+ /// The underlying enum type is u8
87+ UInt8 ( & ' a DictionaryArray < UInt8Type > ) ,
88+ /// The underlying enum type is u16
89+ UInt16 ( & ' a DictionaryArray < UInt16Type > ) ,
90+ /// The underlying enum type is u32
91+ UInt32 ( & ' a DictionaryArray < UInt32Type > ) ,
7892}
7993
8094impl ValueRef < ' _ > {
@@ -103,6 +117,7 @@ impl ValueRef<'_> {
103117 ValueRef :: Time64 ( ..) => Type :: Time64 ,
104118 ValueRef :: Interval { .. } => Type :: Interval ,
105119 ValueRef :: List ( arr, _) => arr. data_type ( ) . into ( ) ,
120+ ValueRef :: Enum ( ..) => Type :: Enum ,
106121 }
107122 }
108123
@@ -170,6 +185,24 @@ impl From<ValueRef<'_>> for Value {
170185 . collect ( ) ;
171186 Value :: List ( map)
172187 }
188+ ValueRef :: Enum ( items, idx) => {
189+ let value = Row :: value_ref_internal (
190+ idx,
191+ 0 ,
192+ match items {
193+ EnumType :: UInt8 ( res) => res. values ( ) ,
194+ EnumType :: UInt16 ( res) => res. values ( ) ,
195+ EnumType :: UInt32 ( res) => res. values ( ) ,
196+ } ,
197+ )
198+ . to_owned ( ) ;
199+
200+ if let Value :: Text ( s) = value {
201+ Value :: Enum ( s)
202+ } else {
203+ panic ! ( "Enum value is not a string" )
204+ }
205+ }
173206 }
174207 }
175208}
@@ -213,6 +246,7 @@ impl<'a> From<&'a Value> for ValueRef<'a> {
213246 Value :: Time64 ( t, d) => ValueRef :: Time64 ( t, d) ,
214247 Value :: Interval { months, days, nanos } => ValueRef :: Interval { months, days, nanos } ,
215248 Value :: List ( ..) => unimplemented ! ( ) ,
249+ Value :: Enum ( ..) => todo ! ( ) ,
216250 }
217251 }
218252}
0 commit comments