[ 
https://issues.apache.org/jira/browse/AVRO-637?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12903729#action_12903729
 ] 

Scott Carey commented on AVRO-637:
----------------------------------

I think the type in SpecificRecord and elsewhere has to be a List<T> instead of 
Collection<T> in order to guarantee ordering, and that methods like add() 
actually append to the list.  If someone sets a field to an arbitrary 
collection, say a Set, then that gets passed on to other code that expects 
add() to function like an array, there will be surprises.

I believe that at minimum, GenericDatumReader.newArray() and addToArray() need 
to check for instanceof List instead of Collection, and if a non-list 
Collection, create a new GenericArray from a non-list Collection.

We should be able to take in any Collection to initialize an inner List; if 
there was a getter/setter style for SpecificRecord then the setter could take 
Collection<T> and the getter return List<T>, but with raw public member 
variables our hands are tied.

Alternatively, a simple thing to do is just change Collection to List in this 
patch -- clients can always use new ArrayList(Collection c);


As much as I like this feature and think that making such changes should be 
done sooner rather than later, I suspect we will be changing these APIs more in 
the future and it might be less painful to batch them all up.  Specifically, 
I'm thinking about changes to the generated classes such as using 
getters/setters to hide the internal representation of the data.



> GenericArray should implement Collection
> ----------------------------------------
>
>                 Key: AVRO-637
>                 URL: https://issues.apache.org/jira/browse/AVRO-637
>             Project: Avro
>          Issue Type: New Feature
>          Components: java
>            Reporter: Doug Cutting
>            Assignee: Doug Cutting
>             Fix For: 1.5.0
>
>         Attachments: AVRO-637.patch, AVRO-637.patch
>
>
> It would be nice if Avro arrays were better integrated with Java collections. 
>  The GenericArray interface permits array element reuse, which is awkward 
> with java.util.Collection.  But if GenericArray implemented Collection and 
> the Avro runtime permitted arbitrary Collection implementations to be passed 
> for Arrays then it would simplify many applications.  The runtime could still 
> reuse elements if an array implemented GenericArray, so performance would not 
> suffer for applications that, e.g., loop over a data file, reusing instances.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to