-
Notifications
You must be signed in to change notification settings - Fork 1.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
AVRO-4039 [java] fix GenericData.newArray to only return an appropriate array implementation #3307
base: main
Are you sure you want to change the base?
AVRO-4039 [java] fix GenericData.newArray to only return an appropriate array implementation #3307
Conversation
only return an appropriate array
related issue - https://issues.apache.org/jira/browse/AVRO-4039 |
only return an appropriate array
lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
Outdated
Show resolved
Hide resolved
if (schema.getElementType().getLogicalType() != null) { | ||
return new GenericData.Array<Object>(size, schema); | ||
} |
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.
Please note that a logical type positiveInteger
is a perfectly valid logical type for an int
value. So we cannot assume an Object
here (even though it's the most likely option).
Can you please use GenericData#getConversionFor(LogicalType)
, Conversion#getConvertedType()
and Boolean#TYPE
et.al. to determine the correct type?
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.
@opwvhk that's - shows how little I know about avro
Will have a look and rework
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.
@opwvhk reworked and added some tests
lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
Outdated
Show resolved
Hide resolved
lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
Outdated
Show resolved
Hide resolved
public static GenericData.AbstractArray<?> createOptimizedArray(int size, Schema schema, Schema.Type valueType) { | ||
|
||
if (valueType != null) | ||
switch (valueType) { |
Check warning
Code scanning / CodeQL
Missing enum case in switch Warning
ARRAY
BYTES
ENUM
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.
am I expected to add a default:break;
lang/java/avro/src/test/java/org/apache/avro/generic/GenericDataTest.java
Show resolved
Hide resolved
lang/java/avro/src/test/java/org/apache/avro/generic/GenericDataTest.java
Show resolved
Hide resolved
Hi @mkeskells, |
doh pushed now |
@opwvhk What's the process from here to get this merged? Does it need other reviewers to approve etc? |
What is the purpose of the change
PrimitiveArray
when it would not be appropriateGenericContainer
is returned the schema must match the supplied schemaappropriate means that
GenericContainer
and thus has a schema, then the schema is the sameIf we can't reuse the supplied value, then generate an appropriate collection, using the optimised values where we can
Updated the documentation, and added tests
Verifying this change
This change added tests and can be verified as follows:
Documentation