나는 두 가지 질문이 있습니다아 브로 스키마 진화
이 가능 같은 리더를 사용하고 호환, 예를 들어, 두 개의 스키마로 작성된 기록을 분석하는 것입니다
Schema V2
은Schema V1
과 비교하여 추가 필드를 가질 수 있습니다. 나는 대답이 '아니오'라고 생각하지만 그렇다면 어떻게해야합니까?내가
Schema V1
로 기록을 작성하고Schema V2
로 읽기 시도했다, 그러나 나는 다음과 같은 오류가 발생합니다 :org.apache.avro.AvroTypeException : 기대, foo는 찾을 수 foo는
나는 아 브로-1.7.3 및 사용 :
writer = new GenericDatumWriter<GenericData.Record>(SchemaV1);
reader = new GenericDatumReader<GenericData.Record>(SchemaV2, SchemaV1);
여기 (나뿐만 아니라 네임 스페이스를 추가하는 시도했지만 운) 두 스키마의 예입니다.
스키마 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"
}]
}
}]
}]
}
감사합니다.
기본 값은 필수입니다. 판독기 스키마에는 있지만 작성기 스키마에는없는 필드에 기본값을 제공하지 않으면 Avro는 구문 분석 된 구조에서이 새 필드를 작성하는 방법을 알 수 없습니다. – LiMuBei