On Fr 30 aug. 2024 17:35, Anton Aleshin <anton.ales...@gmail.com> wrote:
> I have two schemas: > [2 schemata, V1 & V2, the latter with correct aliases for renamed fields] > > I generated Java classes from schema V1 and V2 using Apache Avro Tools > 1.12.0. Then, using a serializer, classes v2, and schema v2, I obtained a > binary message. Next, I tried to deserialize this message using classes v1 > and schema v2, and I got the following error: [...] This error occurs because the schemata and (generated) classes cannot be mixed this way. With the schemata you defined, you can write data with V1 classes (this will use the V1 schema) and read it with the V2 classes. This works, because the V2 schema has the aliases connecting it to the V1 schema. (When using the BinaryMessageDecoder, you'll need to provide the V1 schema as well, so it can interpret the data; the DataFileReader takes the write schema from the file) The other way around is not possible, as the V1 schema has no aliases. Experts may note that this is not entirely true in this particular example, but that is only because the structure of the schemata is identical (this is rare with schema evolution). I realized that when searching for a class, the deserializer doesn't find > the TestRecordV2 class and uses GenericRecord instead. However, logically, > if it can't find the TestRecordV2 class, it should look for the name in the > alias TestRecordV1, and then the class would be found. Could you explain > how to use aliases in the case of renaming a record? > You've correctly defined the aliases to rename records and fields in the V1 schema when reading the data as the V2 schema. The error was in using the schemata and generated classes. I hope the explanation above helps to make it work. Kind regards, Oscar -- Oscar Westra van Holthe - Kind <opw...@apache.org>