1313use std:: sync:: Arc ;
1414
1515use arrow_schema:: { DataType , Field , FieldRef , Fields , Schema , SchemaBuilder , SchemaRef } ;
16- use itertools:: Itertools ;
1716use vortex_datetime_dtype:: arrow:: { make_arrow_temporal_dtype, make_temporal_ext_dtype} ;
1817use vortex_datetime_dtype:: is_temporal_ext_type;
19- use vortex_dtype:: { DType , Nullability , PType , StructDType } ;
18+ use vortex_dtype:: { DType , FieldName , Nullability , PType , StructDType } ;
2019use vortex_error:: { vortex_bail, vortex_err, VortexResult } ;
2120
2221use crate :: arrow:: { FromArrowType , TryFromArrowType } ;
@@ -46,23 +45,23 @@ impl TryFromArrowType<&DataType> for PType {
4645impl FromArrowType < SchemaRef > for DType {
4746 fn from_arrow ( value : SchemaRef ) -> Self {
4847 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 ( ) ) ,
6149 Nullability :: NonNullable , // Must match From<RecordBatch> for Array
6250 )
6351 }
6452}
6553
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+
6665impl FromArrowType < & Field > for DType {
6766 fn from_arrow ( field : & Field ) -> Self {
6867 use vortex_dtype:: DType :: * ;
@@ -88,13 +87,7 @@ impl FromArrowType<&Field> for DType {
8887 DataType :: List ( e) | DataType :: LargeList ( e) => {
8988 List ( Arc :: new ( Self :: from_arrow ( e. as_ref ( ) ) ) , nullability)
9089 }
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) ,
9891 _ => unimplemented ! ( "Arrow data type not yet supported: {:?}" , field. data_type( ) ) ,
9992 }
10093 }
@@ -207,10 +200,10 @@ mod test {
207200
208201 assert_eq ! (
209202 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+ ] ) ,
214207 Nullability :: NonNullable ,
215208 ) )
216209 . unwrap( ) ,
0 commit comments