org.apache.flink.types.DoubleValue Java Examples

The following examples show how to use org.apache.flink.types.DoubleValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SummaryAggregatorFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreate() throws Exception {
	// supported primitive types
	Assert.assertEquals(StringSummaryAggregator.class, SummaryAggregatorFactory.create(String.class).getClass());
	Assert.assertEquals(ShortSummaryAggregator.class, SummaryAggregatorFactory.create(Short.class).getClass());
	Assert.assertEquals(IntegerSummaryAggregator.class, SummaryAggregatorFactory.create(Integer.class).getClass());
	Assert.assertEquals(LongSummaryAggregator.class, SummaryAggregatorFactory.create(Long.class).getClass());
	Assert.assertEquals(FloatSummaryAggregator.class, SummaryAggregatorFactory.create(Float.class).getClass());
	Assert.assertEquals(DoubleSummaryAggregator.class, SummaryAggregatorFactory.create(Double.class).getClass());
	Assert.assertEquals(BooleanSummaryAggregator.class, SummaryAggregatorFactory.create(Boolean.class).getClass());

	// supported value types
	Assert.assertEquals(ValueSummaryAggregator.StringValueSummaryAggregator.class, SummaryAggregatorFactory.create(StringValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.ShortValueSummaryAggregator.class, SummaryAggregatorFactory.create(ShortValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.IntegerValueSummaryAggregator.class, SummaryAggregatorFactory.create(IntValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.LongValueSummaryAggregator.class, SummaryAggregatorFactory.create(LongValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.FloatValueSummaryAggregator.class, SummaryAggregatorFactory.create(FloatValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.DoubleValueSummaryAggregator.class, SummaryAggregatorFactory.create(DoubleValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.BooleanValueSummaryAggregator.class, SummaryAggregatorFactory.create(BooleanValue.class).getClass());

	// some not well supported types - these fallback to ObjectSummaryAggregator
	Assert.assertEquals(ObjectSummaryAggregator.class, SummaryAggregatorFactory.create(Object.class).getClass());
	Assert.assertEquals(ObjectSummaryAggregator.class, SummaryAggregatorFactory.create(List.class).getClass());
}
 
Example #2
Source File: TypeExtractorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testFunctionDependingPartialOnInput2() {
	RichMapFunction<DoubleValue, ?> function = new OneAppender<DoubleValue>();

	TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, new ValueTypeInfo<DoubleValue>(DoubleValue.class));

	Assert.assertTrue(ti.isTupleType());
	Assert.assertEquals(2, ti.getArity());
	TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;

	Assert.assertTrue(tti.getTypeAt(0) instanceof ValueTypeInfo<?>);
	ValueTypeInfo<?> vti = (ValueTypeInfo<?>) tti.getTypeAt(0);
	Assert.assertEquals(DoubleValue.class, vti.getTypeClass());
	
	Assert.assertTrue(tti.getTypeAt(1).isBasicType());
	Assert.assertEquals(Integer.class , tti.getTypeAt(1).getTypeClass());
}
 
Example #3
Source File: DoubleValueSummaryAggregatorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for summarizing a list of values.
 *
 * <p>This method breaks the rule of "testing only one thing" by aggregating and combining
 * a bunch of different ways.
 */
protected NumericColumnSummary<Double> summarize(Double... values) {

	DoubleValue[] doubleValues = new DoubleValue[values.length];
	for (int i = 0; i < values.length; i++) {
		if (values[i] != null) {
			doubleValues[i] = new DoubleValue(values[i]);
		}
	}

	return new AggregateCombineHarness<DoubleValue, NumericColumnSummary<Double>, ValueSummaryAggregator.DoubleValueSummaryAggregator>() {

		@Override
		protected void compareResults(NumericColumnSummary<Double> result1, NumericColumnSummary<Double> result2) {
			Assert.assertEquals(result1.getMin(), result2.getMin(), 0.0);
			Assert.assertEquals(result1.getMax(), result2.getMax(), 0.0);
			Assert.assertEquals(result1.getMean(), result2.getMean(), 1e-12d);
			Assert.assertEquals(result1.getVariance(), result2.getVariance(), 1e-9d);
			Assert.assertEquals(result1.getStandardDeviation(), result2.getStandardDeviation(), 1e-12d);
		}

	}.summarize(doubleValues);
}
 
Example #4
Source File: PageRank.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void coGroup(Iterable<Tuple2<T, DoubleValue>> vertex, Iterable<Edge<T, LongValue>> edges, Collector<Tuple2<T, DoubleValue>> out)
		throws Exception {
	Iterator<Edge<T, LongValue>> edgeIterator = edges.iterator();

	if (edgeIterator.hasNext()) {
		Edge<T, LongValue> edge = edgeIterator.next();

		output.f0 = edge.f1;
		output.f1.setValue(vertex.iterator().next().f1.getValue() / edge.f2.getValue());
		out.collect(output);

		while (edgeIterator.hasNext()) {
			edge = edgeIterator.next();
			output.f0 = edge.f1;
			out.collect(output);
		}
	}
}
 
Example #5
Source File: ValueArrayFactory.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Produce a {@code ValueArray} for the given {@code Value} type with the
 * given bounded size.
 *
 * @param cls {@code Value} class
 * @param bytes limit the array to the given number of bytes
 * @return {@code ValueArray} for given {@code Value} class
 */
@SuppressWarnings("unchecked")
public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls, int bytes) {
	if (ByteValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new ByteValueArray(bytes);
	} else if (CharValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new CharValueArray(bytes);
	} else if (DoubleValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new DoubleValueArray(bytes);
	} else if (FloatValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new FloatValueArray(bytes);
	} else if (IntValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new IntValueArray(bytes);
	} else if (LongValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new LongValueArray(bytes);
	} else if (NullValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new NullValueArray(bytes);
	} else if (ShortValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new ShortValueArray(bytes);
	} else if (StringValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new StringValueArray(bytes);
	} else {
		throw new IllegalArgumentException("Unable to create bounded ValueArray for type " + cls);
	}
}
 
Example #6
Source File: DoubleValueArray.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public boolean addAll(ValueArray<DoubleValue> other) {
	DoubleValueArray source = (DoubleValueArray) other;

	int sourceSize = source.position;
	int newPosition = position + sourceSize;

	if (newPosition > data.length) {
		if (isBounded) {
			return false;
		} else {
			ensureCapacity(newPosition);
		}
	}

	System.arraycopy(source.data, 0, data, position, sourceSize);
	position = newPosition;

	return true;
}
 
Example #7
Source File: EitherSerializerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #8
Source File: DoubleValueSummaryAggregatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for summarizing a list of values.
 *
 * <p>This method breaks the rule of "testing only one thing" by aggregating and combining
 * a bunch of different ways.
 */
protected NumericColumnSummary<Double> summarize(Double... values) {

	DoubleValue[] doubleValues = new DoubleValue[values.length];
	for (int i = 0; i < values.length; i++) {
		if (values[i] != null) {
			doubleValues[i] = new DoubleValue(values[i]);
		}
	}

	return new AggregateCombineHarness<DoubleValue, NumericColumnSummary<Double>, ValueSummaryAggregator.DoubleValueSummaryAggregator>() {

		@Override
		protected void compareResults(NumericColumnSummary<Double> result1, NumericColumnSummary<Double> result2) {
			Assert.assertEquals(result1.getMin(), result2.getMin(), 0.0);
			Assert.assertEquals(result1.getMax(), result2.getMax(), 0.0);
			Assert.assertEquals(result1.getMean(), result2.getMean(), 1e-12d);
			Assert.assertEquals(result1.getVariance(), result2.getVariance(), 1e-9d);
			Assert.assertEquals(result1.getStandardDeviation(), result2.getStandardDeviation(), 1e-12d);
		}

	}.summarize(doubleValues);
}
 
Example #9
Source File: DoubleValueParser.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delimiter, DoubleValue reusable) {
	final int endPos = nextStringEndPos(bytes, startPos, limit, delimiter);
	if (endPos < 0) {
		return -1;
	}

	if (endPos > startPos &&
			(Character.isWhitespace(bytes[startPos]) || Character.isWhitespace(bytes[(endPos - 1)]))) {
		setErrorState(ParseErrorState.NUMERIC_VALUE_ILLEGAL_CHARACTER);
		return -1;
	}

	String str = new String(bytes, startPos, endPos - startPos, ConfigConstants.DEFAULT_CHARSET);
	try {
		double value = Double.parseDouble(str);
		reusable.setValue(value);
		this.result = reusable;
		return (endPos == limit) ? limit : endPos + delimiter.length;
	}
	catch (NumberFormatException e) {
		setErrorState(ParseErrorState.NUMERIC_VALUE_FORMAT_ERROR);
		return -1;
	}
}
 
Example #10
Source File: PageRank.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void coGroup(Iterable<Tuple2<T, DoubleValue>> vertex, Iterable<Edge<T, LongValue>> edges, Collector<Tuple2<T, DoubleValue>> out)
		throws Exception {
	Iterator<Edge<T, LongValue>> edgeIterator = edges.iterator();

	if (edgeIterator.hasNext()) {
		Edge<T, LongValue> edge = edgeIterator.next();

		output.f0 = edge.f1;
		output.f1.setValue(vertex.iterator().next().f1.getValue() / edge.f2.getValue());
		out.collect(output);

		while (edgeIterator.hasNext()) {
			edge = edgeIterator.next();
			output.f0 = edge.f1;
			out.collect(output);
		}
	}
}
 
Example #11
Source File: TypeExtractorTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testFunctionDependingPartialOnInput2() {
	RichMapFunction<DoubleValue, ?> function = new OneAppender<DoubleValue>();

	TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, new ValueTypeInfo<DoubleValue>(DoubleValue.class));

	Assert.assertTrue(ti.isTupleType());
	Assert.assertEquals(2, ti.getArity());
	TupleTypeInfo<?> tti = (TupleTypeInfo<?>) ti;

	Assert.assertTrue(tti.getTypeAt(0) instanceof ValueTypeInfo<?>);
	ValueTypeInfo<?> vti = (ValueTypeInfo<?>) tti.getTypeAt(0);
	Assert.assertEquals(DoubleValue.class, vti.getTypeClass());
	
	Assert.assertTrue(tti.getTypeAt(1).isBasicType());
	Assert.assertEquals(Integer.class , tti.getTypeAt(1).getTypeClass());
}
 
Example #12
Source File: DoubleValueArray.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public boolean add(DoubleValue value) {
	int newPosition = position + 1;

	if (newPosition > data.length) {
		if (isBounded) {
			return false;
		} else {
			ensureCapacity(newPosition);
		}
	}

	data[position] = value.getValue();
	position = newPosition;

	return true;
}
 
Example #13
Source File: DoubleValueComparatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected DoubleValue[] getSortedTestData() {
	Random rnd = new Random(874597969123412338L);
	double rndDouble = rnd.nextDouble();
	if (rndDouble < 0) {
		rndDouble = -rndDouble;
	}
	if (rndDouble == Double.MAX_VALUE) {
		rndDouble -= 3;
	}
	if (rndDouble <= 2) {
		rndDouble += 3;
	}
	return new DoubleValue[]{
		new DoubleValue(-rndDouble),
		new DoubleValue(-1.0D),
		new DoubleValue(0.0D),
		new DoubleValue(2.0D),
		new DoubleValue(rndDouble),
		new DoubleValue(Double.MAX_VALUE)};
}
 
Example #14
Source File: DoubleValueParser.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delimiter, DoubleValue reusable) {
	final int endPos = nextStringEndPos(bytes, startPos, limit, delimiter);
	if (endPos < 0) {
		return -1;
	}

	if (endPos > startPos &&
			(Character.isWhitespace(bytes[startPos]) || Character.isWhitespace(bytes[(endPos - 1)]))) {
		setErrorState(ParseErrorState.NUMERIC_VALUE_ILLEGAL_CHARACTER);
		return -1;
	}

	String str = new String(bytes, startPos, endPos - startPos, ConfigConstants.DEFAULT_CHARSET);
	try {
		double value = Double.parseDouble(str);
		reusable.setValue(value);
		this.result = reusable;
		return (endPos == limit) ? limit : endPos + delimiter.length;
	}
	catch (NumberFormatException e) {
		setErrorState(ParseErrorState.NUMERIC_VALUE_FORMAT_ERROR);
		return -1;
	}
}
 
Example #15
Source File: SummaryAggregatorFactoryTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreate() throws Exception {
	// supported primitive types
	Assert.assertEquals(StringSummaryAggregator.class, SummaryAggregatorFactory.create(String.class).getClass());
	Assert.assertEquals(ShortSummaryAggregator.class, SummaryAggregatorFactory.create(Short.class).getClass());
	Assert.assertEquals(IntegerSummaryAggregator.class, SummaryAggregatorFactory.create(Integer.class).getClass());
	Assert.assertEquals(LongSummaryAggregator.class, SummaryAggregatorFactory.create(Long.class).getClass());
	Assert.assertEquals(FloatSummaryAggregator.class, SummaryAggregatorFactory.create(Float.class).getClass());
	Assert.assertEquals(DoubleSummaryAggregator.class, SummaryAggregatorFactory.create(Double.class).getClass());
	Assert.assertEquals(BooleanSummaryAggregator.class, SummaryAggregatorFactory.create(Boolean.class).getClass());

	// supported value types
	Assert.assertEquals(ValueSummaryAggregator.StringValueSummaryAggregator.class, SummaryAggregatorFactory.create(StringValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.ShortValueSummaryAggregator.class, SummaryAggregatorFactory.create(ShortValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.IntegerValueSummaryAggregator.class, SummaryAggregatorFactory.create(IntValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.LongValueSummaryAggregator.class, SummaryAggregatorFactory.create(LongValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.FloatValueSummaryAggregator.class, SummaryAggregatorFactory.create(FloatValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.DoubleValueSummaryAggregator.class, SummaryAggregatorFactory.create(DoubleValue.class).getClass());
	Assert.assertEquals(ValueSummaryAggregator.BooleanValueSummaryAggregator.class, SummaryAggregatorFactory.create(BooleanValue.class).getClass());

	// some not well supported types - these fallback to ObjectSummaryAggregator
	Assert.assertEquals(ObjectSummaryAggregator.class, SummaryAggregatorFactory.create(Object.class).getClass());
	Assert.assertEquals(ObjectSummaryAggregator.class, SummaryAggregatorFactory.create(List.class).getClass());
}
 
Example #16
Source File: DoubleValueSummaryAggregatorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method for summarizing a list of values.
 *
 * <p>This method breaks the rule of "testing only one thing" by aggregating and combining
 * a bunch of different ways.
 */
protected NumericColumnSummary<Double> summarize(Double... values) {

	DoubleValue[] doubleValues = new DoubleValue[values.length];
	for (int i = 0; i < values.length; i++) {
		if (values[i] != null) {
			doubleValues[i] = new DoubleValue(values[i]);
		}
	}

	return new AggregateCombineHarness<DoubleValue, NumericColumnSummary<Double>, ValueSummaryAggregator.DoubleValueSummaryAggregator>() {

		@Override
		protected void compareResults(NumericColumnSummary<Double> result1, NumericColumnSummary<Double> result2) {
			Assert.assertEquals(result1.getMin(), result2.getMin(), 0.0);
			Assert.assertEquals(result1.getMax(), result2.getMax(), 0.0);
			Assert.assertEquals(result1.getMean(), result2.getMean(), 1e-12d);
			Assert.assertEquals(result1.getVariance(), result2.getVariance(), 1e-9d);
			Assert.assertEquals(result1.getStandardDeviation(), result2.getStandardDeviation(), 1e-12d);
		}

	}.summarize(doubleValues);
}
 
Example #17
Source File: DoubleValueArray.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void copyTo(ValueArray<DoubleValue> target) {
	DoubleValueArray other = (DoubleValueArray) target;

	other.position = position;
	other.mark = mark;

	other.ensureCapacity(position);
	System.arraycopy(data, 0, other.data, 0, position);
}
 
Example #18
Source File: ValueArrayTypeInfo.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public TypeComparator<ValueArray<T>> createComparator(boolean sortOrderAscending, ExecutionConfig executionConfig) {
	Preconditions.checkNotNull(type, "TypeInformation type class is required");

	if (ByteValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new ByteValueArrayComparator(sortOrderAscending);
	} else if (CharValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new CharValueArrayComparator(sortOrderAscending);
	} else if (DoubleValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new DoubleValueArrayComparator(sortOrderAscending);
	} else if (FloatValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new FloatValueArrayComparator(sortOrderAscending);
	} else if (IntValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new IntValueArrayComparator(sortOrderAscending);
	} else if (LongValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new LongValueArrayComparator(sortOrderAscending);
	} else if (NullValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new NullValueArrayComparator(sortOrderAscending);
	} else if (ShortValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new ShortValueArrayComparator(sortOrderAscending);
	} else if (StringValue.class.isAssignableFrom(type)) {
		return (TypeComparator<ValueArray<T>>) (TypeComparator<?>) new StringValueArrayComparator(sortOrderAscending);
	} else {
		throw new InvalidTypesException("No ValueArray class exists for " + type);
	}
}
 
Example #19
Source File: InstantiationUtilTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationToByteArray() throws IOException {
	final DoubleValue toSerialize = new DoubleValue(Math.random());
	final DoubleValueSerializer serializer = new DoubleValueSerializer();

	byte[] serialized = InstantiationUtil.serializeToByteArray(serializer, toSerialize);

	DoubleValue deserialized = InstantiationUtil.deserializeFromByteArray(serializer, serialized);

	assertEquals("Serialized record is not equal after serialization.", toSerialize, deserialized);
}
 
Example #20
Source File: PageRank.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void flatMap(Vertex<T, Degrees> vertex, Collector<Tuple2<T, DoubleValue>> out)
		throws Exception {
	if (vertex.f1.getInDegree().getValue() == 0) {
		output.f0 = vertex.f0;
		out.collect(output);
	}
}
 
Example #21
Source File: HITS.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple3<T, DoubleValue, DoubleValue> join(Tuple3<T, DoubleValue, DoubleValue> first, Tuple3<T, DoubleValue, DoubleValue> second)
		throws Exception {
	if (!isInitialSuperstep) {
		changeInScores += Math.abs(second.f1.getValue() - first.f1.getValue());
		changeInScores += Math.abs(second.f2.getValue() - first.f2.getValue());
	}

	return second;
}
 
Example #22
Source File: HITS.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(Configuration parameters) throws Exception {
	super.open(parameters);

	Collection<DoubleValue> hubbinessSumSquared = getRuntimeContext().getBroadcastVariable(HUBBINESS_SUM_SQUARED);
	Iterator<DoubleValue> hubbinessSumSquaredIterator = hubbinessSumSquared.iterator();
	this.hubbinessRootSumSquared = hubbinessSumSquaredIterator.hasNext() ? Math.sqrt(hubbinessSumSquaredIterator.next().getValue()) : Double.NaN;

	Collection<DoubleValue> authoritySumSquared = getRuntimeContext().getBroadcastVariable(AUTHORITY_SUM_SQUARED);
	Iterator<DoubleValue> authoritySumSquaredIterator = authoritySumSquared.iterator();
	authorityRootSumSquared = authoritySumSquaredIterator.hasNext() ? Math.sqrt(authoritySumSquaredIterator.next().getValue()) : Double.NaN;
}
 
Example #23
Source File: CsvReaderITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testValueTypes() throws Exception {
	final String inputData = "ABC,true,1,2,3,4,5.0,6.0\nBCD,false,1,2,3,4,5.0,6.0";
	final String dataPath = createInputData(inputData);
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> data =
			env.readCsvFile(dataPath).types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	List<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> result = data.collect();

	expected = inputData;
	compareResultAsTuples(result, expected);
}
 
Example #24
Source File: HITS.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple3<T, DoubleValue, DoubleValue> join(Tuple2<T, DoubleValue> hubbiness, Tuple2<T, DoubleValue> authority)
		throws Exception {
	output.f0 = (authority == null) ? hubbiness.f0 : authority.f0;
	output.f1.setValue(hubbiness == null ? 0.0 : hubbiness.f1.getValue() / hubbinessRootSumSquared);
	output.f2.setValue(authority == null ? 0.0 : authority.f1.getValue() / authorityRootSumSquared);
	return output;
}
 
Example #25
Source File: GraphKeyTypeTransform.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public LongValueWithProperHashCode translate(DoubleValue value, LongValueWithProperHashCode reuse)
		throws Exception {
	if (reuse == null) {
		reuse = new LongValueWithProperHashCode();
	}

	reuse.setValue(Double.doubleToRawLongBits(value.getValue()));
	return reuse;
}
 
Example #26
Source File: HITS.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Tuple3<T, DoubleValue, DoubleValue> join(Tuple3<T, DoubleValue, DoubleValue> first, Tuple3<T, DoubleValue, DoubleValue> second)
		throws Exception {
	if (!isInitialSuperstep) {
		changeInScores += Math.abs(second.f1.getValue() - first.f1.getValue());
		changeInScores += Math.abs(second.f2.getValue() - first.f2.getValue());
	}

	return second;
}
 
Example #27
Source File: DoubleValueParserTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleValue[] getValidTestResults() {
	return new DoubleValue[] {
		new DoubleValue(0d), new DoubleValue(0.0d), new DoubleValue(123.4d), new DoubleValue(0.124d),
		new DoubleValue(.623d), new DoubleValue(1234d), new DoubleValue(-12.34d),
		new DoubleValue(Double.MAX_VALUE), new DoubleValue(Double.MIN_VALUE),
		new DoubleValue(Double.NEGATIVE_INFINITY), new DoubleValue(Double.POSITIVE_INFINITY),
		new DoubleValue(Double.NaN),
		new DoubleValue(1.234E2), new DoubleValue(1.234e3), new DoubleValue(1.234E-2), new DoubleValue(1239d)
	};
}
 
Example #28
Source File: GraphKeyTypeTransformTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromDoubleValue() throws Exception {
	TranslateFunction<DoubleValue, LongValueWithProperHashCode> translator = new DoubleValueToLongValueWithProperHashCode();

	Assert.assertEquals(new LongValueWithProperHashCode(0L),
		translator.translate(new DoubleValue(Double.longBitsToDouble(0L)), longValueWithProperHashCode));

	Assert.assertEquals(new LongValueWithProperHashCode(Long.MIN_VALUE),
		translator.translate(new DoubleValue(Double.longBitsToDouble(Long.MIN_VALUE)), longValueWithProperHashCode));

	Assert.assertEquals(new LongValueWithProperHashCode(Long.MAX_VALUE),
		translator.translate(new DoubleValue(Double.longBitsToDouble(Long.MAX_VALUE)), longValueWithProperHashCode));
}
 
Example #29
Source File: CsvReaderITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testValueTypes() throws Exception {
	final String inputData = "ABC,true,1,2,3,4,5.0,6.0\nBCD,false,1,2,3,4,5.0,6.0";
	final String dataPath = createInputData(inputData);
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

	DataSet<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> data =
			env.readCsvFile(dataPath).types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	List<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> result = data.collect();

	expected = inputData;
	compareResultAsTuples(result, expected);
}
 
Example #30
Source File: EitherSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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());
}