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 2020/12/21 09:27:00 UTC
[jira] [Updated] (AVRO-3011) How to build a new schema
[ https://issues.apache.org/jira/browse/AVRO-3011?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
liujinhui updated AVRO-3011:
----------------------------
Description:
{code:java}
@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}
> How to build a new schema
> -------------------------
>
> Key: AVRO-3011
> URL: https://issues.apache.org/jira/browse/AVRO-3011
> Project: Apache Avro
> Issue Type: Bug
> Reporter: liujinhui
> Priority: Major
>
> {code:java}
> @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}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)