Search in sources :

Example 1 with RecordSerializer

use of org.apache.flink.runtime.testutils.recordutils.RecordSerializer in project flink by apache.

the class ReusingKeyGroupedIteratorTest method setup.

@Before
public void setup() {
    final ArrayList<IntStringPair> source = new ArrayList<IntStringPair>();
    // add elements to the source
    source.add(new IntStringPair(new IntValue(1), new StringValue("A")));
    source.add(new IntStringPair(new IntValue(2), new StringValue("B")));
    source.add(new IntStringPair(new IntValue(3), new StringValue("C")));
    source.add(new IntStringPair(new IntValue(3), new StringValue("D")));
    source.add(new IntStringPair(new IntValue(4), new StringValue("E")));
    source.add(new IntStringPair(new IntValue(4), new StringValue("F")));
    source.add(new IntStringPair(new IntValue(4), new StringValue("G")));
    source.add(new IntStringPair(new IntValue(5), new StringValue("H")));
    source.add(new IntStringPair(new IntValue(5), new StringValue("I")));
    source.add(new IntStringPair(new IntValue(5), new StringValue("J")));
    source.add(new IntStringPair(new IntValue(5), new StringValue("K")));
    source.add(new IntStringPair(new IntValue(5), new StringValue("L")));
    this.sourceIter = new MutableObjectIterator<Record>() {

        final Iterator<IntStringPair> it = source.iterator();

        @Override
        public Record next(Record reuse) throws IOException {
            if (it.hasNext()) {
                IntStringPair pair = it.next();
                reuse.setField(0, pair.getInteger());
                reuse.setField(1, pair.getString());
                return reuse;
            } else {
                return null;
            }
        }

        @Override
        public Record next() throws IOException {
            if (it.hasNext()) {
                IntStringPair pair = it.next();
                Record result = new Record(2);
                result.setField(0, pair.getInteger());
                result.setField(1, pair.getString());
                return result;
            } else {
                return null;
            }
        }
    };
    final RecordSerializer serializer = RecordSerializer.get();
    @SuppressWarnings("unchecked") final RecordComparator comparator = new RecordComparator(new int[] { 0 }, new Class[] { IntValue.class });
    this.psi = new ReusingKeyGroupedIterator<Record>(this.sourceIter, serializer, comparator);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) RecordComparator(org.apache.flink.runtime.testutils.recordutils.RecordComparator) Record(org.apache.flink.types.Record) StringValue(org.apache.flink.types.StringValue) IntValue(org.apache.flink.types.IntValue) RecordSerializer(org.apache.flink.runtime.testutils.recordutils.RecordSerializer) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RecordComparator (org.apache.flink.runtime.testutils.recordutils.RecordComparator)1 RecordSerializer (org.apache.flink.runtime.testutils.recordutils.RecordSerializer)1 IntValue (org.apache.flink.types.IntValue)1 Record (org.apache.flink.types.Record)1 StringValue (org.apache.flink.types.StringValue)1 Before (org.junit.Before)1