Skip to content

Commit b549452

Browse files
committed
Added arrow-avro SchemaStore and fingerprint support to schema.rs and made the schema module public. Integrated new SchemaStore to the Decoder in reader/mod.rs. Stubbed out AvroField::resolve_from_writer_and_reader in codec.rs. Added new tests to cover changes
1 parent 16794ab commit b549452

File tree

4 files changed

+1079
-118
lines changed

4 files changed

+1079
-118
lines changed

arrow-avro/src/codec.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ impl AvroField {
139139
pub fn name(&self) -> &str {
140140
&self.name
141141
}
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+
}
142158
}
143159

144160
impl<'a> TryFrom<&Schema<'a>> for AvroField {
@@ -164,21 +180,33 @@ impl<'a> TryFrom<&Schema<'a>> for AvroField {
164180
/// Builder for an [`AvroField`]
165181
#[derive(Debug)]
166182
pub struct AvroFieldBuilder<'a> {
167-
schema: &'a Schema<'a>,
183+
writer_schema: &'a Schema<'a>,
184+
reader_schema: Option<&'a Schema<'a>>,
168185
use_utf8view: bool,
169186
strict_mode: bool,
170187
}
171188

172189
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 {
175192
Self {
176-
schema,
193+
writer_schema,
194+
reader_schema: None,
177195
use_utf8view: false,
178196
strict_mode: false,
179197
}
180198
}
181199

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+
182210
/// Enable or disable Utf8View support
183211
pub fn with_utf8view(mut self, use_utf8view: bool) -> Self {
184212
self.use_utf8view = use_utf8view;
@@ -193,11 +221,11 @@ impl<'a> AvroFieldBuilder<'a> {
193221

194222
/// Build an [`AvroField`] from the builder
195223
pub fn build(self) -> Result<AvroField, ArrowError> {
196-
match self.schema {
224+
match self.writer_schema {
197225
Schema::Complex(ComplexType::Record(r)) => {
198226
let mut resolver = Resolver::default();
199227
let data_type = make_data_type(
200-
self.schema,
228+
self.writer_schema,
201229
None,
202230
&mut resolver,
203231
self.use_utf8view,
@@ -210,7 +238,7 @@ impl<'a> AvroFieldBuilder<'a> {
210238
}
211239
_ => Err(ArrowError::ParseError(format!(
212240
"Expected a Record schema to build an AvroField, but got {:?}",
213-
self.schema
241+
self.writer_schema
214242
))),
215243
}
216244
}

arrow-avro/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
/// Implements the primary reader interface and record decoding logic.
3434
pub mod reader;
3535

36-
// Avro schema parsing and representation
37-
//
38-
// Provides types for parsing and representing Avro schema definitions.
39-
mod schema;
36+
/// Avro schema parsing and representation
37+
///
38+
/// Provides types for parsing and representing Avro schema definitions.
39+
pub mod schema;
4040

4141
/// Compression codec implementations for Avro
4242
///

0 commit comments

Comments
 (0)