@@ -33,7 +33,7 @@ use arrow::buffer::{Buffer, MutableBuffer};
33
33
use arrow:: datatypes:: {
34
34
ArrowDictionaryKeyType , ArrowNumericType , ArrowPrimitiveType , DataType , Date32Type ,
35
35
Date64Type , Field , Float32Type , Float64Type , Int16Type , Int32Type , Int64Type ,
36
- Int8Type , Schema , Time32MillisecondType , Time32SecondType , Time64MicrosecondType ,
36
+ Int8Type , Time32MillisecondType , Time32SecondType , Time64MicrosecondType ,
37
37
Time64NanosecondType , TimeUnit , TimestampMicrosecondType , TimestampMillisecondType ,
38
38
TimestampNanosecondType , TimestampSecondType , UInt16Type , UInt32Type , UInt64Type ,
39
39
UInt8Type ,
@@ -56,23 +56,17 @@ type RecordSlice<'a> = &'a [&'a Vec<(String, Value)>];
56
56
pub struct AvroArrowArrayReader < ' a , R : Read > {
57
57
reader : AvroReader < ' a , R > ,
58
58
schema : SchemaRef ,
59
- projection : Option < Vec < String > > ,
60
59
schema_lookup : BTreeMap < String , usize > ,
61
60
}
62
61
63
62
impl < R : Read > AvroArrowArrayReader < ' _ , R > {
64
- pub fn try_new (
65
- reader : R ,
66
- schema : SchemaRef ,
67
- projection : Option < Vec < String > > ,
68
- ) -> Result < Self > {
63
+ pub fn try_new ( reader : R , schema : SchemaRef ) -> Result < Self > {
69
64
let reader = AvroReader :: new ( reader) ?;
70
65
let writer_schema = reader. writer_schema ( ) . clone ( ) ;
71
66
let schema_lookup = Self :: schema_lookup ( writer_schema) ?;
72
67
Ok ( Self {
73
68
reader,
74
69
schema,
75
- projection,
76
70
schema_lookup,
77
71
} )
78
72
}
@@ -175,20 +169,9 @@ impl<R: Read> AvroArrowArrayReader<'_, R> {
175
169
} ;
176
170
177
171
let rows = rows. iter ( ) . collect :: < Vec < & Vec < ( String , Value ) > > > ( ) ;
178
- let projection = self . projection . clone ( ) . unwrap_or_default ( ) ;
179
- let arrays =
180
- self . build_struct_array ( & rows, "" , self . schema . fields ( ) , & projection) ;
181
- let projected_fields = if projection. is_empty ( ) {
182
- self . schema . fields ( ) . clone ( )
183
- } else {
184
- projection
185
- . iter ( )
186
- . filter_map ( |name| self . schema . column_with_name ( name) )
187
- . map ( |( _, field) | field. clone ( ) )
188
- . collect ( )
189
- } ;
190
- let projected_schema = Arc :: new ( Schema :: new ( projected_fields) ) ;
191
- Some ( arrays. and_then ( |arr| RecordBatch :: try_new ( projected_schema, arr) ) )
172
+ let arrays = self . build_struct_array ( & rows, "" , self . schema . fields ( ) ) ;
173
+
174
+ Some ( arrays. and_then ( |arr| RecordBatch :: try_new ( Arc :: clone ( & self . schema ) , arr) ) )
192
175
}
193
176
194
177
fn build_boolean_array ( & self , rows : RecordSlice , col_name : & str ) -> ArrayRef {
@@ -615,7 +598,7 @@ impl<R: Read> AvroArrowArrayReader<'_, R> {
615
598
let sub_parent_field_name =
616
599
format ! ( "{}.{}" , parent_field_name, list_field. name( ) ) ;
617
600
let arrays =
618
- self . build_struct_array ( & rows, & sub_parent_field_name, fields, & [ ] ) ?;
601
+ self . build_struct_array ( & rows, & sub_parent_field_name, fields) ?;
619
602
let data_type = DataType :: Struct ( fields. clone ( ) ) ;
620
603
ArrayDataBuilder :: new ( data_type)
621
604
. len ( rows. len ( ) )
@@ -645,20 +628,14 @@ impl<R: Read> AvroArrowArrayReader<'_, R> {
645
628
/// The function does not construct the StructArray as some callers would want the child arrays.
646
629
///
647
630
/// *Note*: The function is recursive, and will read nested structs.
648
- ///
649
- /// If `projection` is not empty, then all values are returned. The first level of projection
650
- /// occurs at the `RecordBatch` level. No further projection currently occurs, but would be
651
- /// useful if plucking values from a struct, e.g. getting `a.b.c.e` from `a.b.c.{d, e}`.
652
631
fn build_struct_array (
653
632
& self ,
654
633
rows : RecordSlice ,
655
634
parent_field_name : & str ,
656
635
struct_fields : & Fields ,
657
- projection : & [ String ] ,
658
636
) -> ArrowResult < Vec < ArrayRef > > {
659
637
let arrays: ArrowResult < Vec < ArrayRef > > = struct_fields
660
638
. iter ( )
661
- . filter ( |field| projection. is_empty ( ) || projection. contains ( field. name ( ) ) )
662
639
. map ( |field| {
663
640
let field_path = if parent_field_name. is_empty ( ) {
664
641
field. name ( ) . to_string ( )
@@ -840,12 +817,8 @@ impl<R: Read> AvroArrowArrayReader<'_, R> {
840
817
}
841
818
} )
842
819
. collect :: < Vec < & Vec < ( String , Value ) > > > ( ) ;
843
- let arrays = self . build_struct_array (
844
- & struct_rows,
845
- & field_path,
846
- fields,
847
- & [ ] ,
848
- ) ?;
820
+ let arrays =
821
+ self . build_struct_array ( & struct_rows, & field_path, fields) ?;
849
822
// construct a struct array's data in order to set null buffer
850
823
let data_type = DataType :: Struct ( fields. clone ( ) ) ;
851
824
let data = ArrayDataBuilder :: new ( data_type)
0 commit comments