You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by Jeff Hammerbacher <ha...@cloudera.com> on 2010/05/20 03:16:24 UTC
Two questions about GenericArray in the Java implementation
1) Why does size() return a long instead of an int? java.util.List, for
example, returns an int. Not returning an int leads to a lot of lint.
2) Why is there no get(index i) method? I can get an iterator and
continually call next(), but sometimes you want to look up a single element
by index.
My apologies if these are dumb questions; I know very little about Java.
Thanks,
Jeff
Re: Two questions about GenericArray in the Java implementation
Posted by Doug Cutting <cu...@apache.org>.
On 05/19/2010 06:16 PM, Jeff Hammerbacher wrote:
> 2) Why is there no get(index i) method? I can get an iterator and
> continually call next(), but sometimes you want to look up a single element
> by index.
An array could in theory be larger than fits in memory, so random access
should perhaps not be encouraged. That said, the only implementation of
this interface, GenericData.Array, is entirely in memory. Probably we
should at least add a get(int) method to that class.
Doug
RE: Two questions about GenericArray in the Java implementation
Posted by Scott Carey <sc...@richrelevance.com>.
1) I think the intent was to support avro arrays with more than 2 billion elements eventually. Additionally the underlying serialized array size in the avro spec is a long, not an int.
2) We could add something to get items by index but it could only work on small arrays that are not streamed. I don't think the Generic interface supports streaming large arrays yet anyway.
Generally, most users will loop over an array using the Java 5 syntax that hides the iterator creation and get() call:
GenericArray<SomeType> array;
for (SomeType item : array) {
doSomething(item);
}
Rather than something like
for (i = 0; i < size; i++) {
SomeType item = array.get(i);
doSomething(item);
}
-Scott
-----Original Message-----
From: Jeff Hammerbacher [mailto:hammer@cloudera.com]
Sent: Wednesday, May 19, 2010 6:16 PM
To: dev@avro.apache.org
Subject: Two questions about GenericArray in the Java implementation
1) Why does size() return a long instead of an int? java.util.List, for
example, returns an int. Not returning an int leads to a lot of lint.
2) Why is there no get(index i) method? I can get an iterator and
continually call next(), but sometimes you want to look up a single element
by index.
My apologies if these are dumb questions; I know very little about Java.
Thanks,
Jeff