You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "liujinhui (Jira)" <ji...@apache.org> on 2021/03/08 09:16:00 UTC

[jira] [Resolved] (AVRO-3011) Fields are already setCaused by: org.apache.avro.AvroRuntimeException:

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

liujinhui resolved AVRO-3011.
-----------------------------
    Resolution: Cannot Reproduce

> 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: Major
>
> {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)