[ 
https://issues.apache.org/jira/browse/AVRO-3011?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

liujinhui updated AVRO-3011:
----------------------------
    Priority: Blocker  (was: Major)

> Fields are already setCaused by: org.apache.avro.AvroRuntimeException: 
> -----------------------------------------------------------------------
>
>                 Key: AVRO-3011
>                 URL: https://issues.apache.org/jira/browse/AVRO-3011
>             Project: Apache Avro
>          Issue Type: Bug
>            Reporter: liujinhui
>            Priority: Blocker
>
> {code:java}
> public class CompatibleDatumReader<D> extends GenericDatumReader<D> {
>    public CompatibleDatumReader(Schema writer, Schema reader) {
>       super(writer, reader);
>    }
> @Override
> protected Object readRecord(Object old, Schema expected, ResolvingDecoder in) 
> throws IOException {
>    Object r = getData().newRecord(old, expected);
>    Map<String, String> removeField = new HashMap<>();
>    
>    for (Field f : in.readFieldOrder()) {
>       int pos = f.pos();
>       String name = f.name();
>       Object oldDatum = (old != null) ? getData().getField(r, name, pos) : 
> null;
>       try {
>          read(oldDatum, f.schema(), in);
>       } catch (EOFException e) {
>          removeField.put(name, name);
>          continue;
>       }
>    }
>    List<Schema.Field> list = new ArrayList<>();
>    if(removeField.size() > 0) {
>       Iterator<Field> iterator = expected.getFields().iterator();
>       while (iterator.hasNext()) {
>          Field field = iterator.next();
>          if (!removeField.containsKey(field.name())) {
>             list.add(field);
>          }
>       }
>       expected.setFields(list);
>    }
> {code}
> Who can help me, how to build a new schema? My idea is as follows, but he 
> will throw an exception
> {code:java}
> Caused by: org.apache.avro.AvroRuntimeException: Fields are already setCaused 
> by: org.apache.avro.AvroRuntimeException: Fields are already set at 
> org.apache.avro.Schema$RecordSchema.setFields(Schema.java:640)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to