-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop leaking Avro objects from parser #12828
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,9 @@ | |
|
||
import java.nio.ByteBuffer; | ||
import java.util.EnumSet; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
@@ -164,7 +166,7 @@ private Object transformValue(final Object field) | |
} else if (field instanceof Utf8) { | ||
return field.toString(); | ||
} else if (field instanceof List) { | ||
return ((List<?>) field).stream().filter(Objects::nonNull).collect(Collectors.toList()); | ||
return ((List<?>) field).stream().filter(Objects::nonNull).map(this::transformValue).collect(Collectors.toList()); | ||
} else if (field instanceof GenericEnumSymbol) { | ||
return field.toString(); | ||
} else if (field instanceof GenericFixed) { | ||
|
@@ -173,6 +175,20 @@ private Object transformValue(final Object field) | |
} else { | ||
return ((GenericFixed) field).bytes(); | ||
} | ||
} else if (field instanceof Map) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this should use like |
||
LinkedHashMap<String, Object> retVal = new LinkedHashMap<>(); | ||
Map<?, ?> fieldMap = (Map<?, ?>) field; | ||
for (Map.Entry<?, ?> entry : fieldMap.entrySet()) { | ||
retVal.put(String.valueOf(entry.getKey()), transformValue(entry.getValue())); | ||
} | ||
return retVal; | ||
} else if (field instanceof GenericRecord) { | ||
LinkedHashMap<String, Object> retVal = new LinkedHashMap<>(); | ||
GenericRecord record = (GenericRecord) field; | ||
for (Schema.Field key : record.getSchema().getFields()) { | ||
retVal.put(key.name(), transformValue(record.get(key.pos()))); | ||
} | ||
return retVal; | ||
} | ||
return field; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could possibly generate new output for a list which has
ByteBuffer
in it. But I think if anyone is using this then their data might look absurd since doing atoString
onByteBuffer
doesn't return the backed bytes.