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();
}
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();
}
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());
}
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));
}
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);
}
Aggregations