@Override public Either<L, R> map2(L value) { return Either.Left(value); } }
/** * Sets the new value of this vertex. * * <p>This should be called at most once per ComputeFunction. * * @param newValue The new vertex value. */ public final void setNewVertexValue(VV newValue) { if (setNewVertexValueCalled) { throw new IllegalStateException("setNewVertexValue should only be called at most once per updateVertex"); } setNewVertexValueCalled = true; outVertex.f1 = newValue; out.collect(Either.Left(outVertex)); }
@Override public void open(Configuration parameters) { outTuple = new Tuple2<>(); nullMessage = Either.Left(NullValue.getInstance()); outTuple.f1 = nullMessage; }
@Override public Either<L, R> deserialize(DataInputView source) throws IOException { boolean isLeft = source.readBoolean(); if (isLeft) { return Left(leftSerializer.deserialize(source)); } else { return Right(rightSerializer.deserialize(source)); } }
@Test(expected=InvalidTypesException.class) public void testEitherFromObjectException() { Either<String, Tuple1<Integer>> either = Either.Left("test"); TypeExtractor.getForObject(either); }
@Override public Either<L, R> copy(Either<L, R> from) { if (from.isLeft()) { L left = from.left(); L copyLeft = leftSerializer.copy(left); return Left(copyLeft); } else { R right = from.right(); R copyRight = rightSerializer.copy(right); return Right(copyRight); } }
@Override public String map(Integer value) throws Exception { touchState(tupleState, () -> Tuple2.of("19", 19)); touchState(eitherState, () -> Either.Left("255")); final Address newAddress = Address.newBuilder() .setCity("New York") .setZip("10036") .setStreet("555 W 42nd St") .setState("NY") .setNum(555) .build(); Address existingAddress = avroState.value(); if (existingAddress != null) { if (!Objects.equals(existingAddress.getAppno(), EXPECTED_DEFAULT_VALUE)) { // this is expected to fail the job, if found in the output files. System.out.println("Wrong Default Value."); } } avroState.update(newAddress); return ""; }
@SuppressWarnings("unchecked") @Test public void testStringDoubleEither() { Either<String, Double>[] testData = new Either[] { Left("banana"), Left(""), Right(32.0), Right(Double.MIN_VALUE), Right(Double.MAX_VALUE)}; EitherTypeInfo<String, Double> eitherTypeInfo = (EitherTypeInfo<String, Double>) new EitherTypeInfo<String, Double>( BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.DOUBLE_TYPE_INFO); EitherSerializer<String, Double> eitherSerializer = (EitherSerializer<String, Double>) eitherTypeInfo.createSerializer(new ExecutionConfig()); SerializerTestInstance<Either<String, Double>> testInstance = new EitherSerializerTestInstance<Either<String, Double>>(eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData); testInstance.testAll(); }
@SuppressWarnings("unchecked") @Test public void testEitherWithTuple() { Either<Tuple2<Long, Long>, Double>[] testData = new Either[] { Either.Left(new Tuple2<>(2L, 9L)), new Left<>(new Tuple2<>(Long.MIN_VALUE, Long.MAX_VALUE)), new Right<>(32.0), Right(Double.MIN_VALUE), Right(Double.MAX_VALUE)}; EitherTypeInfo<Tuple2<Long, Long>, Double> eitherTypeInfo = (EitherTypeInfo<Tuple2<Long, Long>, Double>) new EitherTypeInfo<Tuple2<Long, Long>, Double>( new TupleTypeInfo<Tuple2<Long, Long>>(BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO), BasicTypeInfo.DOUBLE_TYPE_INFO); EitherSerializer<Tuple2<Long, Long>, Double> eitherSerializer = (EitherSerializer<Tuple2<Long, Long>, Double>) eitherTypeInfo.createSerializer(new ExecutionConfig()); SerializerTestInstance<Either<Tuple2<Long, Long>, Double>> testInstance = new EitherSerializerTestInstance<Either<Tuple2<Long, Long>, Double>>( eitherSerializer, eitherTypeInfo.getTypeClass(), -1, testData); testInstance.testAll(); }
@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()); }
@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(); }
@Test public void testSerializeIndividually() throws IOException { 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); TestOutputView out = new TestOutputView(); eitherSerializer.serialize(left, out); eitherSerializer.serialize(right, out); eitherSerializer.serialize(left, out); TestInputView in = out.getInputView(); // the first deserialization creates a new instance of Left Either<LongValue, DoubleValue> copy0 = eitherSerializer.deserialize(right, in); // then the cross-references are used for future copies Either<LongValue, DoubleValue> copy1 = eitherSerializer.deserialize(copy0, in); Either<LongValue, DoubleValue> copy2 = eitherSerializer.deserialize(copy1, in); // 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()); }
@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(); }
@Override public Either<L, R> map2(L value) throws Exception { return Either.Left(value); } }
@Override public void open(Configuration parameters) { outTuple = new Tuple2<>(); nullMessage = Either.Left(NullValue.getInstance()); outTuple.f1 = nullMessage; }
@Override public void open(Configuration parameters) { outTuple = new Tuple2<>(); nullMessage = Either.Left(NullValue.getInstance()); outTuple.f1 = nullMessage; }
@Override public void open(Configuration parameters) { outTuple = new Tuple2<>(); nullMessage = Either.Left(NullValue.getInstance()); outTuple.f1 = nullMessage; }
private void emitTimedOutSequences(Iterable<Tuple2<Map<String, List<IN>>, Long>> timedOutSequences, long timestamp) { StreamRecord<Either<Tuple2<Map<String, List<IN>>, Long>, Map<String, List<IN>>>> streamRecord = new StreamRecord<>(null, timestamp); for (Tuple2<Map<String, List<IN>>, Long> partialPattern: timedOutSequences) { streamRecord.replace(Either.Left(partialPattern)); output.collect(streamRecord); } }
@Override public Either<L, R> deserialize(DataInputView source) throws IOException { boolean isLeft = source.readBoolean(); if (isLeft) { return Left(leftSerializer.deserialize(source)); } else { return Right(rightSerializer.deserialize(source)); } }
@Override public Either<L, R> deserialize(DataInputView source) throws IOException { boolean isLeft = source.readBoolean(); if (isLeft) { return Left(leftSerializer.deserialize(source)); } else { return Right(rightSerializer.deserialize(source)); } }