13
13
use std:: sync:: Arc ;
14
14
15
15
use arrow_schema:: { DataType , Field , FieldRef , Fields , Schema , SchemaBuilder , SchemaRef } ;
16
- use itertools:: Itertools ;
17
16
use vortex_datetime_dtype:: arrow:: { make_arrow_temporal_dtype, make_temporal_ext_dtype} ;
18
17
use vortex_datetime_dtype:: is_temporal_ext_type;
19
- use vortex_dtype:: { DType , Nullability , PType , StructDType } ;
18
+ use vortex_dtype:: { DType , FieldName , Nullability , PType , StructDType } ;
20
19
use vortex_error:: { vortex_bail, vortex_err, VortexResult } ;
21
20
22
21
use crate :: arrow:: { FromArrowType , TryFromArrowType } ;
@@ -46,23 +45,23 @@ impl TryFromArrowType<&DataType> for PType {
46
45
impl FromArrowType < SchemaRef > for DType {
47
46
fn from_arrow ( value : SchemaRef ) -> Self {
48
47
Self :: Struct (
49
- StructDType :: new (
50
- value
51
- . fields ( )
52
- . iter ( )
53
- . map ( |f| f. name ( ) . as_str ( ) . into ( ) )
54
- . collect ( ) ,
55
- value
56
- . fields ( )
57
- . iter ( )
58
- . map ( |f| Self :: from_arrow ( f. as_ref ( ) ) )
59
- . collect_vec ( ) ,
60
- ) ,
48
+ StructDType :: from_arrow ( value. fields ( ) ) ,
61
49
Nullability :: NonNullable , // Must match From<RecordBatch> for Array
62
50
)
63
51
}
64
52
}
65
53
54
+ impl FromArrowType < & Fields > for StructDType {
55
+ fn from_arrow ( value : & Fields ) -> Self {
56
+ StructDType :: from_iter ( value. into_iter ( ) . map ( |f| {
57
+ (
58
+ FieldName :: from ( f. name ( ) . as_str ( ) ) ,
59
+ DType :: from_arrow ( f. as_ref ( ) ) ,
60
+ )
61
+ } ) )
62
+ }
63
+ }
64
+
66
65
impl FromArrowType < & Field > for DType {
67
66
fn from_arrow ( field : & Field ) -> Self {
68
67
use vortex_dtype:: DType :: * ;
@@ -88,13 +87,7 @@ impl FromArrowType<&Field> for DType {
88
87
DataType :: List ( e) | DataType :: LargeList ( e) => {
89
88
List ( Arc :: new ( Self :: from_arrow ( e. as_ref ( ) ) ) , nullability)
90
89
}
91
- DataType :: Struct ( f) => Struct (
92
- StructDType :: new (
93
- f. iter ( ) . map ( |f| f. name ( ) . as_str ( ) . into ( ) ) . collect ( ) ,
94
- f. iter ( ) . map ( |f| Self :: from_arrow ( f. as_ref ( ) ) ) . collect_vec ( ) ,
95
- ) ,
96
- nullability,
97
- ) ,
90
+ DataType :: Struct ( f) => Struct ( StructDType :: from_arrow ( f) , nullability) ,
98
91
_ => unimplemented ! ( "Arrow data type not yet supported: {:?}" , field. data_type( ) ) ,
99
92
}
100
93
}
@@ -207,10 +200,10 @@ mod test {
207
200
208
201
assert_eq ! (
209
202
infer_data_type( & DType :: Struct (
210
- StructDType :: new (
211
- FieldNames :: from ( vec! [ FieldName :: from ( "field_a" ) , FieldName :: from ( "field_b" ) ] ) ,
212
- vec! [ DType :: Bool ( false . into ( ) ) , DType :: Utf8 ( true . into( ) ) ] ,
213
- ) ,
203
+ StructDType :: from_iter ( [
204
+ ( "field_a" , DType :: Bool ( false . into ( ) ) ) ,
205
+ ( "field_b" , DType :: Utf8 ( true . into( ) ) )
206
+ ] ) ,
214
207
Nullability :: NonNullable ,
215
208
) )
216
209
. unwrap( ) ,
0 commit comments