@@ -139,6 +139,22 @@ impl AvroField {
139
139
pub fn name ( & self ) -> & str {
140
140
& self . name
141
141
}
142
+
143
+ /// Performs schema resolution between a writer and reader schema.
144
+ ///
145
+ /// This is the primary entry point for handling schema evolution. It produces an
146
+ /// `AvroField` that contains all the necessary information to read data written
147
+ /// with the `writer` schema as if it were written with the `reader` schema.
148
+ pub fn resolve_from_writer_and_reader < ' a > (
149
+ writer : & ' a Schema < ' a > ,
150
+ reader : & ' a Schema < ' a > ,
151
+ use_utf8view : bool ,
152
+ strict_mode : bool ,
153
+ ) -> Result < Self , ArrowError > {
154
+ Err ( ArrowError :: NotYetImplemented (
155
+ "Resolving schema from a writer and reader schema is not yet implemented" . to_string ( ) ,
156
+ ) )
157
+ }
142
158
}
143
159
144
160
impl < ' a > TryFrom < & Schema < ' a > > for AvroField {
@@ -164,21 +180,33 @@ impl<'a> TryFrom<&Schema<'a>> for AvroField {
164
180
/// Builder for an [`AvroField`]
165
181
#[ derive( Debug ) ]
166
182
pub struct AvroFieldBuilder < ' a > {
167
- schema : & ' a Schema < ' a > ,
183
+ writer_schema : & ' a Schema < ' a > ,
184
+ reader_schema : Option < & ' a Schema < ' a > > ,
168
185
use_utf8view : bool ,
169
186
strict_mode : bool ,
170
187
}
171
188
172
189
impl < ' a > AvroFieldBuilder < ' a > {
173
- /// Creates a new [`AvroFieldBuilder`]
174
- pub fn new ( schema : & ' a Schema < ' a > ) -> Self {
190
+ /// Creates a new [`AvroFieldBuilder`] for a given writer schema.
191
+ pub fn new ( writer_schema : & ' a Schema < ' a > ) -> Self {
175
192
Self {
176
- schema,
193
+ writer_schema,
194
+ reader_schema : None ,
177
195
use_utf8view : false ,
178
196
strict_mode : false ,
179
197
}
180
198
}
181
199
200
+ /// Sets the reader schema for schema resolution.
201
+ ///
202
+ /// If a reader schema is provided, the builder will produce a resolved `AvroField`
203
+ /// that can handle differences between the writer's and reader's schemas.
204
+ #[ inline]
205
+ pub fn with_reader_schema ( mut self , reader_schema : & ' a Schema < ' a > ) -> Self {
206
+ self . reader_schema = Some ( reader_schema) ;
207
+ self
208
+ }
209
+
182
210
/// Enable or disable Utf8View support
183
211
pub fn with_utf8view ( mut self , use_utf8view : bool ) -> Self {
184
212
self . use_utf8view = use_utf8view;
@@ -193,11 +221,11 @@ impl<'a> AvroFieldBuilder<'a> {
193
221
194
222
/// Build an [`AvroField`] from the builder
195
223
pub fn build ( self ) -> Result < AvroField , ArrowError > {
196
- match self . schema {
224
+ match self . writer_schema {
197
225
Schema :: Complex ( ComplexType :: Record ( r) ) => {
198
226
let mut resolver = Resolver :: default ( ) ;
199
227
let data_type = make_data_type (
200
- self . schema ,
228
+ self . writer_schema ,
201
229
None ,
202
230
& mut resolver,
203
231
self . use_utf8view ,
@@ -210,7 +238,7 @@ impl<'a> AvroFieldBuilder<'a> {
210
238
}
211
239
_ => Err ( ArrowError :: ParseError ( format ! (
212
240
"Expected a Record schema to build an AvroField, but got {:?}" ,
213
- self . schema
241
+ self . writer_schema
214
242
) ) ) ,
215
243
}
216
244
}
0 commit comments