What I am trying to accomplish is simple: Return the list containing a Tuple2 as a Java Iterator.
The code snippet is:
....public java.util.Iterator<Tuple2<Path, Text>> call(InputSplit inputSplit, java.util.Iterator<Tuple2<LongWritable, Text>> iter) throws Exception {
..... java.util.List<Tuple2<Path, Text>> elements = new java.util.ArrayList<Tuple2<Path, Text>>();
while(iter.hasNext()){
Tuple2<LongWritable,Text> tupled = iter.next();
Tuple2<Path, Text> toAdd = new Tuple2<Path, Text>(file.getPath(),tupled._2);
elements.add(toAdd);
}
java.util.Iterator<Tuple2<Path, Text>> it = elements.iterator();
return it; .....}
Note: the variable iter
is also a Java Iterator.
The error I get is:
java.lang.ClassCastException: java.util.ArrayList$Itr cannot be cast to scala.collection.Iterator
- What am I doing wrong? (I am aware that I am using
Tuple2
, which is meant for Scala). - How do I return a Java Iterator with a
Tuple2
or aTuple2
equivalent ?
Thank you