Search in sources :

Example 16 with DoubleValue

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

the class EitherSerializerTest method testStringValueDoubleValueEither.

@Test
public void testStringValueDoubleValueEither() {
    @SuppressWarnings("unchecked") Either<StringValue, DoubleValue>[] testData = new Either[] { Left(new StringValue("banana")), Left.of(new StringValue("apple")), new Left(new StringValue("")), Right(new DoubleValue(32.0)), Right.of(new DoubleValue(Double.MIN_VALUE)), new Right(new DoubleValue(Double.MAX_VALUE)) };
    EitherTypeInfo<StringValue, DoubleValue> eitherTypeInfo = new EitherTypeInfo<>(ValueTypeInfo.STRING_VALUE_TYPE_INFO, ValueTypeInfo.DOUBLE_VALUE_TYPE_INFO);
    EitherSerializer<StringValue, DoubleValue> eitherSerializer = (EitherSerializer<StringValue, DoubleValue>) eitherTypeInfo.createSerializer(new ExecutionConfig());
    SerializerTestInstance<Either<StringValue, DoubleValue>> testInstance = new EitherSerializerTestInstance<>(eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData);
    testInstance.testAll();
}
Also used : Left(org.apache.flink.types.Either.Left) Right(org.apache.flink.types.Either.Right) EitherTypeInfo(org.apache.flink.api.java.typeutils.EitherTypeInfo) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) DoubleValue(org.apache.flink.types.DoubleValue) Either(org.apache.flink.types.Either) StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 17 with DoubleValue

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

the class EitherSerializerTest method testEitherWithTupleValues.

@Test
public void testEitherWithTupleValues() {
    @SuppressWarnings("unchecked") Either<Tuple2<LongValue, LongValue>, DoubleValue>[] testData = new Either[] { Left(new Tuple2<>(new LongValue(2L), new LongValue(9L))), new Left<>(new Tuple2<>(new LongValue(Long.MIN_VALUE), new LongValue(Long.MAX_VALUE))), new Right<>(new DoubleValue(32.0)), Right(new DoubleValue(Double.MIN_VALUE)), Right(new DoubleValue(Double.MAX_VALUE)) };
    EitherTypeInfo<Tuple2<LongValue, LongValue>, DoubleValue> eitherTypeInfo = new EitherTypeInfo<>(new TupleTypeInfo<Tuple2<LongValue, LongValue>>(ValueTypeInfo.LONG_VALUE_TYPE_INFO, ValueTypeInfo.LONG_VALUE_TYPE_INFO), ValueTypeInfo.DOUBLE_VALUE_TYPE_INFO);
    EitherSerializer<Tuple2<LongValue, LongValue>, DoubleValue> eitherSerializer = (EitherSerializer<Tuple2<LongValue, LongValue>, DoubleValue>) eitherTypeInfo.createSerializer(new ExecutionConfig());
    SerializerTestInstance<Either<Tuple2<LongValue, LongValue>, DoubleValue>> testInstance = new EitherSerializerTestInstance<>(eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData);
    testInstance.testAll();
}
Also used : Left(org.apache.flink.types.Either.Left) Right(org.apache.flink.types.Either.Right) EitherTypeInfo(org.apache.flink.api.java.typeutils.EitherTypeInfo) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) DoubleValue(org.apache.flink.types.DoubleValue) Tuple2(org.apache.flink.api.java.tuple.Tuple2) LongValue(org.apache.flink.types.LongValue) Either(org.apache.flink.types.Either) Test(org.junit.Test)

Example 18 with DoubleValue

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

the class EitherSerializerTest method testEitherWithObjectReuse.

@Test
public void testEitherWithObjectReuse() {
    EitherTypeInfo<LongValue, DoubleValue> eitherTypeInfo = new EitherTypeInfo<>(ValueTypeInfo.LONG_VALUE_TYPE_INFO, ValueTypeInfo.DOUBLE_VALUE_TYPE_INFO);
    EitherSerializer<LongValue, DoubleValue> eitherSerializer = (EitherSerializer<LongValue, DoubleValue>) eitherTypeInfo.createSerializer(new ExecutionConfig());
    LongValue lv = new LongValue();
    DoubleValue dv = new DoubleValue();
    Either<LongValue, DoubleValue> left = Left(lv);
    Either<LongValue, DoubleValue> right = Right(dv);
    // the first copy creates a new instance of Left
    Either<LongValue, DoubleValue> copy0 = eitherSerializer.copy(left, right);
    // then the cross-references are used for future copies
    Either<LongValue, DoubleValue> copy1 = eitherSerializer.copy(right, copy0);
    Either<LongValue, DoubleValue> copy2 = eitherSerializer.copy(left, copy1);
    // validate reference equality
    assertSame(right, copy1);
    assertSame(copy0, copy2);
    // validate reference equality of contained objects
    assertSame(right.right(), copy1.right());
    assertSame(copy0.left(), copy2.left());
}
Also used : DoubleValue(org.apache.flink.types.DoubleValue) LongValue(org.apache.flink.types.LongValue) EitherTypeInfo(org.apache.flink.api.java.typeutils.EitherTypeInfo) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Test(org.junit.Test)

Example 19 with DoubleValue

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

the class GraphKeyTypeTransformTest method testToDoubleValue.

// DoubleValue
@Test
public void testToDoubleValue() throws Exception {
    TranslateFunction<LongValue, DoubleValue> translator = new LongValueToDoubleValue();
    Assert.assertEquals(new DoubleValue(Double.longBitsToDouble(0L)), translator.translate(new LongValue(0L), doubleValue));
    Assert.assertEquals(new DoubleValue(Double.longBitsToDouble(Long.MIN_VALUE)), translator.translate(new LongValue(Long.MIN_VALUE), doubleValue));
    Assert.assertEquals(new DoubleValue(Double.longBitsToDouble(Long.MAX_VALUE)), translator.translate(new LongValue(Long.MAX_VALUE), doubleValue));
}
Also used : DoubleValue(org.apache.flink.types.DoubleValue) LongValueToDoubleValue(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToDoubleValue) LongValue(org.apache.flink.types.LongValue) LongValueToDoubleValue(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToDoubleValue) Test(org.junit.Test)

Example 20 with DoubleValue

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

the class OutputEmitterTest method testMultiKeys.

@Test
public void testMultiKeys() {
    final int numberOfChannels = 100;
    final int numRecords = 5000;
    final TypeComparator<Record> multiComp = new RecordComparatorFactory(new int[] { 0, 1, 3 }, new Class[] { IntValue.class, StringValue.class, DoubleValue.class }).createComparator();
    final ChannelSelector<SerializationDelegate<Record>> selector = createChannelSelector(ShipStrategyType.PARTITION_HASH, multiComp, numberOfChannels);
    final SerializationDelegate<Record> delegate = new SerializationDelegate<>(new RecordSerializerFactory().getSerializer());
    int[] hits = new int[numberOfChannels];
    for (int i = 0; i < numRecords; i++) {
        Record record = new Record(4);
        record.setField(0, new IntValue(i));
        record.setField(1, new StringValue("AB" + i + "CD" + i));
        record.setField(3, new DoubleValue(i * 3.141d));
        delegate.setInstance(record);
        int channel = selector.selectChannel(delegate);
        hits[channel]++;
    }
    int totalHitCount = 0;
    for (int hit : hits) {
        assertTrue(hit > 0);
        totalHitCount += hit;
    }
    assertTrue(totalHitCount == 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) 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)

Aggregations

DoubleValue (org.apache.flink.types.DoubleValue)20 Test (org.junit.Test)12 LongValue (org.apache.flink.types.LongValue)5 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)4 EitherTypeInfo (org.apache.flink.api.java.typeutils.EitherTypeInfo)4 Random (java.util.Random)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 StringValue (org.apache.flink.types.StringValue)3 DoubleSumAggregator (org.apache.flink.api.common.aggregators.DoubleSumAggregator)2 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)2 LongValueToDoubleValue (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToDoubleValue)2 Either (org.apache.flink.types.Either)2 Left (org.apache.flink.types.Either.Left)2 Right (org.apache.flink.types.Either.Right)2 IntValue (org.apache.flink.types.IntValue)2 ArrayList (java.util.ArrayList)1 TestInputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestInputView)1 TestOutputView (org.apache.flink.api.common.typeutils.ComparatorTestBase.TestOutputView)1 DoubleValueSerializer (org.apache.flink.api.common.typeutils.base.DoubleValueSerializer)1 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)1