@@ -29,7 +29,7 @@ use std::sync::Arc;
29
29
/// To accommodate this we special case two-variant unions where one of the
30
30
/// variants is the null type, and use this to derive arrow's notion of nullability
31
31
#[ derive( Debug , Copy , Clone ) ]
32
- enum Nulls {
32
+ pub enum Nullability {
33
33
/// The nulls are encoded as the first union variant
34
34
NullFirst ,
35
35
/// The nulls are encoded as the second union variant
@@ -39,7 +39,7 @@ enum Nulls {
39
39
/// An Avro datatype mapped to the arrow data model
40
40
#[ derive( Debug , Clone ) ]
41
41
pub struct AvroDataType {
42
- nulls : Option < Nulls > ,
42
+ nullability : Option < Nullability > ,
43
43
metadata : HashMap < String , String > ,
44
44
codec : Codec ,
45
45
}
@@ -48,7 +48,15 @@ impl AvroDataType {
48
48
/// Returns an arrow [`Field`] with the given name
49
49
pub fn field_with_name ( & self , name : & str ) -> Field {
50
50
let d = self . codec . data_type ( ) ;
51
- Field :: new ( name, d, self . nulls . is_some ( ) ) . with_metadata ( self . metadata . clone ( ) )
51
+ Field :: new ( name, d, self . nullability . is_some ( ) ) . with_metadata ( self . metadata . clone ( ) )
52
+ }
53
+
54
+ pub fn codec ( & self ) -> & Codec {
55
+ & self . codec
56
+ }
57
+
58
+ pub fn nullability ( & self ) -> Option < Nullability > {
59
+ self . nullability
52
60
}
53
61
}
54
62
@@ -65,9 +73,13 @@ impl AvroField {
65
73
self . data_type . field_with_name ( & self . name )
66
74
}
67
75
68
- /// Returns the [`Codec`]
69
- pub fn codec ( & self ) -> & Codec {
70
- & self . data_type . codec
76
+ /// Returns the [`AvroDataType`]
77
+ pub fn data_type ( & self ) -> & AvroDataType {
78
+ & self . data_type
79
+ }
80
+
81
+ pub fn name ( & self ) -> & str {
82
+ & self . name
71
83
}
72
84
}
73
85
@@ -114,7 +126,7 @@ pub enum Codec {
114
126
Fixed ( i32 ) ,
115
127
List ( Arc < AvroDataType > ) ,
116
128
Struct ( Arc < [ AvroField ] > ) ,
117
- Duration ,
129
+ Interval ,
118
130
}
119
131
120
132
impl Codec {
@@ -137,7 +149,7 @@ impl Codec {
137
149
Self :: TimestampMicros ( is_utc) => {
138
150
DataType :: Timestamp ( TimeUnit :: Microsecond , is_utc. then ( || "+00:00" . into ( ) ) )
139
151
}
140
- Self :: Duration => DataType :: Interval ( IntervalUnit :: MonthDayNano ) ,
152
+ Self :: Interval => DataType :: Interval ( IntervalUnit :: MonthDayNano ) ,
141
153
Self :: Fixed ( size) => DataType :: FixedSizeBinary ( * size) ,
142
154
Self :: List ( f) => {
143
155
DataType :: List ( Arc :: new ( f. field_with_name ( Field :: LIST_FIELD_DEFAULT_NAME ) ) )
@@ -200,7 +212,7 @@ fn make_data_type<'a>(
200
212
) -> Result < AvroDataType , ArrowError > {
201
213
match schema {
202
214
Schema :: TypeName ( TypeName :: Primitive ( p) ) => Ok ( AvroDataType {
203
- nulls : None ,
215
+ nullability : None ,
204
216
metadata : Default :: default ( ) ,
205
217
codec : ( * p) . into ( ) ,
206
218
} ) ,
@@ -213,12 +225,12 @@ fn make_data_type<'a>(
213
225
match ( f. len ( ) == 2 , null) {
214
226
( true , Some ( 0 ) ) => {
215
227
let mut field = make_data_type ( & f[ 1 ] , namespace, resolver) ?;
216
- field. nulls = Some ( Nulls :: NullFirst ) ;
228
+ field. nullability = Some ( Nullability :: NullFirst ) ;
217
229
Ok ( field)
218
230
}
219
231
( true , Some ( 1 ) ) => {
220
232
let mut field = make_data_type ( & f[ 0 ] , namespace, resolver) ?;
221
- field. nulls = Some ( Nulls :: NullSecond ) ;
233
+ field. nullability = Some ( Nullability :: NullSecond ) ;
222
234
Ok ( field)
223
235
}
224
236
_ => Err ( ArrowError :: NotYetImplemented ( format ! (
@@ -241,7 +253,7 @@ fn make_data_type<'a>(
241
253
. collect :: < Result < _ , ArrowError > > ( ) ?;
242
254
243
255
let field = AvroDataType {
244
- nulls : None ,
256
+ nullability : None ,
245
257
codec : Codec :: Struct ( fields) ,
246
258
metadata : r. attributes . field_metadata ( ) ,
247
259
} ;
@@ -251,7 +263,7 @@ fn make_data_type<'a>(
251
263
ComplexType :: Array ( a) => {
252
264
let mut field = make_data_type ( a. items . as_ref ( ) , namespace, resolver) ?;
253
265
Ok ( AvroDataType {
254
- nulls : None ,
266
+ nullability : None ,
255
267
metadata : a. attributes . field_metadata ( ) ,
256
268
codec : Codec :: List ( Arc :: new ( field) ) ,
257
269
} )
@@ -262,7 +274,7 @@ fn make_data_type<'a>(
262
274
} ) ?;
263
275
264
276
let field = AvroDataType {
265
- nulls : None ,
277
+ nullability : None ,
266
278
metadata : f. attributes . field_metadata ( ) ,
267
279
codec : Codec :: Fixed ( size) ,
268
280
} ;
@@ -298,7 +310,7 @@ fn make_data_type<'a>(
298
310
( Some ( "local-timestamp-micros" ) , c @ Codec :: Int64 ) => {
299
311
* c = Codec :: TimestampMicros ( false )
300
312
}
301
- ( Some ( "duration" ) , c @ Codec :: Fixed ( 12 ) ) => * c = Codec :: Duration ,
313
+ ( Some ( "duration" ) , c @ Codec :: Fixed ( 12 ) ) => * c = Codec :: Interval ,
302
314
( Some ( logical) , _) => {
303
315
// Insert unrecognized logical type into metadata map
304
316
field. metadata . insert ( "logicalType" . into ( ) , logical. into ( ) ) ;
0 commit comments