Search in sources :

Example 61 with IntValue

use of org.apache.flink.types.IntValue in project flink by apache.

the class SpillingResettableMutableObjectIteratorTest method startup.

@Before
public void startup() {
    // set up IO and memory manager
    this.memman = new MemoryManager(MEMORY_CAPACITY, 1);
    this.ioman = new IOManagerAsync();
    // create test objects
    final ArrayList<Record> objects = new ArrayList<Record>(NUM_TESTRECORDS);
    for (int i = 0; i < NUM_TESTRECORDS; ++i) {
        Record tmp = new Record(new IntValue(i));
        objects.add(tmp);
    }
    this.reader = new MutableObjectIteratorWrapper(objects.iterator());
}
Also used : IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) MutableObjectIteratorWrapper(org.apache.flink.runtime.operators.testutils.MutableObjectIteratorWrapper) ArrayList(java.util.ArrayList) Record(org.apache.flink.types.Record) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) IntValue(org.apache.flink.types.IntValue) Before(org.junit.Before)

Example 62 with IntValue

use of org.apache.flink.types.IntValue in project flink by apache.

the class OutputEmitterTest method testNullKey.

@Test
public void testNullKey() {
    // Test for IntValue
    @SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> intComp = new RecordComparatorFactory(new int[] { 0 }, new Class[] { IntValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> oe1 = new OutputEmitter<Record>(ShipStrategyType.PARTITION_HASH, intComp);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<Record>(new RecordSerializerFactory().getSerializer());
    Record rec = new Record(2);
    rec.setField(1, new IntValue(1));
    delegate.setInstance(rec);
    try {
        oe1.selectChannels(delegate, 100);
    } catch (NullKeyFieldException re) {
        Assert.assertEquals(0, re.getFieldNumber());
        return;
    }
    Assert.fail("Expected a NullKeyFieldException.");
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) OutputEmitter(org.apache.flink.runtime.operators.shipping.OutputEmitter) NullKeyFieldException(org.apache.flink.types.NullKeyFieldException) RecordSerializerFactory(org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory) Record(org.apache.flink.types.Record) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Example 63 with IntValue

use of org.apache.flink.types.IntValue in project flink by apache.

the class OutputEmitterTest method testMultiKeys.

@Test
public void testMultiKeys() {
    @SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> multiComp = new RecordComparatorFactory(new int[] { 0, 1, 3 }, new Class[] { IntValue.class, StringValue.class, DoubleValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> oe1 = new OutputEmitter<Record>(ShipStrategyType.PARTITION_HASH, multiComp);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<Record>(new RecordSerializerFactory().getSerializer());
    int numChannels = 100;
    int numRecords = 5000;
    int[] hit = new int[numChannels];
    for (int i = 0; i < numRecords; i++) {
        Record rec = new Record(4);
        rec.setField(0, new IntValue(i));
        rec.setField(1, new StringValue("AB" + i + "CD" + i));
        rec.setField(3, new DoubleValue(i * 3.141d));
        delegate.setInstance(rec);
        int[] chans = oe1.selectChannels(delegate, hit.length);
        for (int chan : chans) {
            hit[chan]++;
        }
    }
    int cnt = 0;
    for (int aHit : hit) {
        assertTrue(aHit > 0);
        cnt += aHit;
    }
    assertTrue(cnt == numRecords);
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) RecordSerializerFactory(org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) OutputEmitter(org.apache.flink.runtime.operators.shipping.OutputEmitter) DoubleValue(org.apache.flink.types.DoubleValue) Record(org.apache.flink.types.Record) StringValue(org.apache.flink.types.StringValue) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Example 64 with IntValue

use of org.apache.flink.types.IntValue in project flink by apache.

the class OutputEmitterTest method testBroadcast.

@Test
public void testBroadcast() {
    // Test for IntValue
    @SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> intComp = new RecordComparatorFactory(new int[] { 0 }, new Class[] { IntValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> oe1 = new OutputEmitter<Record>(ShipStrategyType.BROADCAST, intComp);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<Record>(new RecordSerializerFactory().getSerializer());
    int numChannels = 100;
    int numRecords = 50000;
    int[] hit = new int[numChannels];
    for (int i = 0; i < numRecords; i++) {
        IntValue k = new IntValue(i);
        Record rec = new Record(k);
        delegate.setInstance(rec);
        int[] chans = oe1.selectChannels(delegate, hit.length);
        for (int chan : chans) {
            hit[chan]++;
        }
    }
    for (int aHit : hit) {
        assertTrue(aHit + "", aHit == numRecords);
    }
    // Test for StringValue
    @SuppressWarnings({ "unchecked", "rawtypes" }) final TypeComparator<Record> stringComp = new RecordComparatorFactory(new int[] { 0 }, new Class[] { StringValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> oe2 = new OutputEmitter<Record>(ShipStrategyType.BROADCAST, stringComp);
    numChannels = 100;
    numRecords = 5000;
    hit = new int[numChannels];
    for (int i = 0; i < numRecords; i++) {
        StringValue k = new StringValue(i + "");
        Record rec = new Record(k);
        delegate.setInstance(rec);
        int[] chans = oe2.selectChannels(delegate, hit.length);
        for (int chan : chans) {
            hit[chan]++;
        }
    }
    for (int aHit : hit) {
        assertTrue(aHit + "", aHit == numRecords);
    }
}
Also used : RecordComparatorFactory(org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory) RecordSerializerFactory(org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory) SerializationDelegate(org.apache.flink.runtime.plugable.SerializationDelegate) OutputEmitter(org.apache.flink.runtime.operators.shipping.OutputEmitter) Record(org.apache.flink.types.Record) StringValue(org.apache.flink.types.StringValue) IntValue(org.apache.flink.types.IntValue) Test(org.junit.Test)

Example 65 with IntValue

use of org.apache.flink.types.IntValue in project flink by apache.

the class ReusingBlockResettableIteratorTest method startup.

@Before
public void startup() {
    // set up IO and memory manager
    this.memman = new MemoryManager(MEMORY_CAPACITY, 1);
    // create test objects
    this.objects = new ArrayList<Record>(20000);
    for (int i = 0; i < NUM_VALUES; ++i) {
        this.objects.add(new Record(new IntValue(i)));
    }
    // create the reader
    this.reader = objects.iterator();
}
Also used : Record(org.apache.flink.types.Record) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) IntValue(org.apache.flink.types.IntValue) Before(org.junit.Before)

Aggregations

IntValue (org.apache.flink.types.IntValue)65 Test (org.junit.Test)41 StringValue (org.apache.flink.types.StringValue)36 IOException (java.io.IOException)23 Record (org.apache.flink.types.Record)23 LongValue (org.apache.flink.types.LongValue)20 DoubleValue (org.apache.flink.types.DoubleValue)15 Configuration (org.apache.flink.configuration.Configuration)12 FileInputSplit (org.apache.flink.core.fs.FileInputSplit)12 Value (org.apache.flink.types.Value)12 ArrayList (java.util.ArrayList)9 Before (org.junit.Before)9 OutputEmitter (org.apache.flink.runtime.operators.shipping.OutputEmitter)8 SerializationDelegate (org.apache.flink.runtime.plugable.SerializationDelegate)8 RecordSerializerFactory (org.apache.flink.runtime.testutils.recordutils.RecordSerializerFactory)8 NoSuchElementException (java.util.NoSuchElementException)7 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)7 RecordComparatorFactory (org.apache.flink.runtime.testutils.recordutils.RecordComparatorFactory)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 NullValue (org.apache.flink.types.NullValue)6