Page
Library
Module
Module type
Parameter
Class
Class type
Source
Avro_simple.DecoderSourceAvro decoder with schema evolution support.
This module provides decoding functionality for Avro binary data that supports schema evolution. It can read data written with one schema (writer schema) and decode it according to a different but compatible schema (reader schema).
Avro's schema evolution allows data written with one version of a schema to be read with a different version, following these compatibility rules:
The decoder automatically handles numeric type promotions:
Records support field-level evolution:
Enums support symbol evolution:
The typical workflow is: 1. Parse both reader and writer schemas using Schema.parse 2. Call decode_with_schemas with both schemas and the binary data 3. The function returns either a decoded Value.t or an error describing schema incompatibility
Example:
let reader_schema = Schema.parse reader_json in
let writer_schema = Schema.parse writer_json in
match decode_with_schemas reader_schema writer_schema binary_data with
| Ok value -> (* process decoded value *)
| Error mismatch -> (* handle schema incompatibility *)decode_value read_schema inp decodes a value from input inp using the resolved read schema.
The read_schema must be obtained by resolving a reader schema against a writer schema using Resolution.resolve_schemas. This resolved schema contains all the information needed to:
val decode_with_schemas :
Schema.t ->
Schema.t ->
bytes ->
(Value.t, Resolution.mismatch) resultdecode_with_schemas reader_schema writer_schema bytes decodes binary Avro data that was written with writer_schema, interpreting it according to reader_schema.
This is the main entry point for decoding with schema evolution. It: 1. Resolves the two schemas to determine how to transform data 2. Creates an input stream from the bytes 3. Decodes the data applying all necessary transformations
Schema compatibility is determined by Resolution.resolve_schemas. Common incompatibilities include: