2 つの質問があります。
同じリーダーを使用して、互換性のある 2 つのスキーマで記述されたレコードを解析することはでき
Schema V2
ますSchema V1
か? ここでの答えはノーだと思いますが、イエスの場合、どうすればいいですか?Schema V1
でレコードの書き込みと読み取りを試みましたSchema V2
が、次のエラーが発生します。org.apache.avro.AvroTypeException: foo が見つかりました。foo が必要です
私はavro-1.7.3を使用しました:
writer = new GenericDatumWriter<GenericData.Record>(SchemaV1);
reader = new GenericDatumReader<GenericData.Record>(SchemaV2, SchemaV1);
2 つのスキーマの例を次に示します (名前空間も追加しようとしましたが、うまくいきませんでした)。
スキーマ V1:
{
"name": "foo",
"type": "record",
"fields": [{
"name": "products",
"type": {
"type": "array",
"items": {
"name": "product",
"type": "record",
"fields": [{
"name": "a1",
"type": "string"
}, {
"name": "a2",
"type": {"type": "fixed", "name": "a3", "size": 1}
}, {
"name": "a4",
"type": "int"
}, {
"name": "a5",
"type": "int"
}]
}
}
}]
}
スキーマ V2:
{
"name": "foo",
"type": "record",
"fields": [{
"name": "products",
"type": {
"type": "array",
"items": {
"name": "product",
"type": "record",
"fields": [{
"name": "a1",
"type": "string"
}, {
"name": "a2",
"type": {"type": "fixed", "name": "a3", "size": 1}
}, {
"name": "a4",
"type": "int"
}, {
"name": "a5",
"type": "int"
}]
}
}
},
{
"name": "purchases",
"type": ["null",{
"type": "array",
"items": {
"name": "purchase",
"type": "record",
"fields": [{
"name": "a1",
"type": "int"
}, {
"name": "a2",
"type": "int"
}]
}
}]
}]
}
前もって感謝します。