Java Code Examples for org.apache.flink.types.FloatValue

The following examples show how to use org.apache.flink.types.FloatValue. These examples are extracted from open source projects. 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 Project: flink   Source File: FloatValueComparatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected FloatValue[] getSortedTestData() {
	Random rnd = new Random(874597969123412338L);
	float rndFloat = rnd.nextFloat();
	if (rndFloat < 0) {
		rndFloat = -rndFloat;
	}
	if (rndFloat == Float.MAX_VALUE) {
		rndFloat -= 3;
	}
	if (rndFloat <= 2) {
		rndFloat += 3;
	}
	return new FloatValue[]{
		new FloatValue(-rndFloat),
		new FloatValue(-1.0F),
		new FloatValue(0.0F),
		new FloatValue(2.0F),
		new FloatValue(rndFloat),
		new FloatValue(Float.MAX_VALUE)};
}
 
Example 2
/**
 * 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.
 */
@Override
protected NumericColumnSummary<Float> summarize(Float... values) {

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

	return new AggregateCombineHarness<FloatValue, NumericColumnSummary<Float>, ValueSummaryAggregator.FloatValueSummaryAggregator>() {

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

	}.summarize(floatValues);
}
 
Example 3
Source Project: flink   Source File: AdamicAdar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Tuple3<T, T, FloatValue>> values, Collector<Tuple4<IntValue, T, T, FloatValue>> out)
		throws Exception {
	int groupCount = 0;
	int groupSpans = 1;

	groupSpansValue.setValue(groupSpans);

	for (Tuple3<T, T, FloatValue> edge : values) {
		output.f1 = edge.f0;
		output.f2 = edge.f1;
		output.f3 = edge.f2;

		out.collect(output);

		if (++groupCount == GROUP_SIZE) {
			groupCount = 0;
			groupSpansValue.setValue(++groupSpans);
		}
	}
}
 
Example 4
Source Project: flink   Source File: ValueArrayFactory.java    License: 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 5
Source Project: Flink-CEPplus   Source File: ValueArrayFactory.java    License: 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 Project: Flink-CEPplus   Source File: AdamicAdar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Tuple3<T, T, FloatValue>> values, Collector<Tuple4<IntValue, T, T, FloatValue>> out)
		throws Exception {
	int groupCount = 0;
	int groupSpans = 1;

	groupSpansValue.setValue(groupSpans);

	for (Tuple3<T, T, FloatValue> edge : values) {
		output.f1 = edge.f0;
		output.f2 = edge.f1;
		output.f3 = edge.f2;

		out.collect(output);

		if (++groupCount == GROUP_SIZE) {
			groupCount = 0;
			groupSpansValue.setValue(++groupSpans);
		}
	}
}
 
Example 7
Source Project: flink   Source File: ValueArrayFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Produce a {@code ValueArray} for the given {@code Value} type.
 *
 * @param cls {@code Value} class
 * @return {@code ValueArray} for given {@code Value} class
 */
@SuppressWarnings("unchecked")
public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls) {
	if (ByteValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new ByteValueArray();
	} else if (CharValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new CharValueArray();
	} else if (DoubleValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new DoubleValueArray();
	} else if (FloatValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new FloatValueArray();
	} else if (IntValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new IntValueArray();
	} else if (LongValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new LongValueArray();
	} else if (NullValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new NullValueArray();
	} else if (ShortValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new ShortValueArray();
	} else if (StringValue.class.isAssignableFrom(cls)) {
		return (ValueArray<T>) new StringValueArray();
	} else {
		throw new IllegalArgumentException("Unable to create unbounded ValueArray for type " + cls);
	}
}
 
Example 8
Source Project: Flink-CEPplus   Source File: AdamicAdar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void reduce(Iterable<Tuple3<T, T, FloatValue>> values, Collector<Result<T>> out)
		throws Exception {
	double sum = 0;
	Tuple3<T, T, FloatValue> edge = null;

	for (Tuple3<T, T, FloatValue> next : values) {
		edge = next;
		sum += next.f2.getValue();
	}

	if (sum >= minimumScore) {
		output.setVertexId0(edge.f0);
		output.setVertexId1(edge.f1);
		output.setAdamicAdarScore((float) sum);
		out.collect(output);
	}
}
 
Example 9
Source Project: flink   Source File: FloatValueArray.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void copyTo(ValueArray<FloatValue> target) {
	FloatValueArray other = (FloatValueArray) target;

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

	other.ensureCapacity(position);
	System.arraycopy(data, 0, other.data, 0, position);
}
 
Example 10
Source Project: flink   Source File: AdamicAdar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reduce(Iterable<Tuple4<IntValue, T, T, FloatValue>> values, Collector<Tuple3<T, T, FloatValue>> out)
		throws Exception {
	int visitedCount = 0;

	for (Tuple4<IntValue, T, T, FloatValue> edge : values) {
		output.f1 = edge.f2;
		output.f2 = edge.f3;

		for (int i = 0; i < visitedCount; i++) {
			output.f0 = visited.get(i);
			out.collect(output);
		}

		if (visitedCount < GROUP_SIZE) {
			if (!initialized) {
				initialized = true;

				for (int i = 0; i < GROUP_SIZE; i++) {
					visited.add(edge.f2.copy());
				}
			} else {
				edge.f2.copyTo(visited.get(visitedCount));
			}

			visitedCount += 1;
		}
	}
}
 
Example 11
Source Project: flink   Source File: GraphKeyTypeTransformTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFromFloatValue() throws Exception {
	TranslateFunction<FloatValue, LongValueWithProperHashCode> translator = new UnsignedFloatValueToLongValueWithProperHashCode();

	Assert.assertEquals(new LongValueWithProperHashCode(0L),
		translator.translate(new FloatValue(Float.intBitsToFloat(0)), longValueWithProperHashCode));

	Assert.assertEquals(new LongValueWithProperHashCode((long) Integer.MAX_VALUE + 1),
		translator.translate(new FloatValue(Float.intBitsToFloat(Integer.MIN_VALUE)), longValueWithProperHashCode));

	Assert.assertEquals(new LongValueWithProperHashCode(LongValueToUnsignedFloatValue.MAX_VERTEX_COUNT - 1),
		translator.translate(new FloatValue(Float.intBitsToFloat(-1)), longValueWithProperHashCode));
}
 
Example 12
Source Project: flink   Source File: FloatValueParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FloatValue[] getValidTestResults() {
	return new FloatValue[] {
		new FloatValue(0f), new FloatValue(0.0f), new FloatValue(123.4f),
		new FloatValue(0.124f), new FloatValue(.623f), new FloatValue(1234f), new FloatValue(-12.34f), 
		new FloatValue(Float.MAX_VALUE), new FloatValue(Float.MIN_VALUE),
		new FloatValue(Float.NEGATIVE_INFINITY), new FloatValue(Float.POSITIVE_INFINITY),
		new FloatValue(Float.NaN),
		new FloatValue(1.234E2f), new FloatValue(1.234e3f), new FloatValue(1.234E-2f), new FloatValue(1239f)
	};
}
 
Example 13
Source Project: flink   Source File: ValueArrayTypeInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public TypeSerializer<ValueArray<T>> createSerializer(ExecutionConfig executionConfig) {
	Preconditions.checkNotNull(type, "TypeInformation type class is required");

	if (ByteValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new ByteValueArraySerializer();
	} else if (CharValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new CharValueArraySerializer();
	} else if (DoubleValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new DoubleValueArraySerializer();
	} else if (FloatValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new FloatValueArraySerializer();
	} else if (IntValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new IntValueArraySerializer();
	} else if (LongValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new LongValueArraySerializer();
	} else if (NullValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new NullValueArraySerializer();
	} else if (ShortValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new ShortValueArraySerializer();
	} else if (StringValue.class.isAssignableFrom(type)) {
		return (TypeSerializer<ValueArray<T>>) (TypeSerializer<?>) new StringValueArraySerializer();
	} else {
		throw new InvalidTypesException("No ValueArray class exists for " + type);
	}
}
 
Example 14
Source Project: flink   Source File: GraphKeyTypeTransformTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFromFloatValue() throws Exception {
	TranslateFunction<FloatValue, LongValueWithProperHashCode> translator = new UnsignedFloatValueToLongValueWithProperHashCode();

	Assert.assertEquals(new LongValueWithProperHashCode(0L),
		translator.translate(new FloatValue(Float.intBitsToFloat(0)), longValueWithProperHashCode));

	Assert.assertEquals(new LongValueWithProperHashCode((long) Integer.MAX_VALUE + 1),
		translator.translate(new FloatValue(Float.intBitsToFloat(Integer.MIN_VALUE)), longValueWithProperHashCode));

	Assert.assertEquals(new LongValueWithProperHashCode(LongValueToUnsignedFloatValue.MAX_VERTEX_COUNT - 1),
		translator.translate(new FloatValue(Float.intBitsToFloat(-1)), longValueWithProperHashCode));
}
 
Example 15
Source Project: flink   Source File: AdamicAdar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Tuple3<T, LongValue, FloatValue> map(Vertex<T, LongValue> value)
		throws Exception {
	output.f0 = value.f0;
	output.f1 = value.f1;

	long degree = value.f1.getValue();
	// when the degree is one the logarithm is zero so avoid dividing by this value
	float inverseLogDegree = (degree == 1) ? 0.0f : 1.0f / (float) Math.log(value.f1.getValue());
	output.f2.setValue(inverseLogDegree);

	return output;
}
 
Example 16
Source Project: Flink-CEPplus   Source File: GraphKeyTypeTransform.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public LongValueWithProperHashCode translate(FloatValue value, LongValueWithProperHashCode reuse)
		throws Exception {
	if (reuse == null) {
		reuse = new LongValueWithProperHashCode();
	}

	reuse.setValue(0xffffffffL & Float.floatToRawIntBits(value.getValue()));
	return reuse;
}
 
Example 17
Source Project: flink   Source File: CsvReaderITCase.java    License: 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 18
Source Project: flink   Source File: GraphKeyTypeTransformTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testToFloatValue() throws Exception {
	TranslateFunction<LongValue, FloatValue> translator = new LongValueToUnsignedFloatValue();

	Assert.assertEquals(new FloatValue(Float.intBitsToFloat(0)),
		translator.translate(new LongValue(0L), floatValue));

	Assert.assertEquals(new FloatValue(Float.intBitsToFloat(Integer.MIN_VALUE)),
		translator.translate(new LongValue((long) Integer.MAX_VALUE + 1), floatValue));

	Assert.assertEquals(new FloatValue(Float.intBitsToFloat(-1)),
		translator.translate(new LongValue(LongValueToUnsignedFloatValue.MAX_VERTEX_COUNT - 1), floatValue));
}
 
Example 19
Source Project: flink   Source File: CSVReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithValueType() throws Exception {
	CsvReader reader = getCsvReader();
	DataSource<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> items =
			reader.types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	TypeInformation<?> info = items.getType();

	Assert.assertEquals(true, info.isTupleType());
	Assert.assertEquals(Tuple8.class, info.getTypeClass());
}
 
Example 20
Source Project: flink   Source File: GraphKeyTypeTransform.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public LongValueWithProperHashCode translate(FloatValue value, LongValueWithProperHashCode reuse)
		throws Exception {
	if (reuse == null) {
		reuse = new LongValueWithProperHashCode();
	}

	reuse.setValue(0xffffffffL & Float.floatToRawIntBits(value.getValue()));
	return reuse;
}
 
Example 21
Source Project: flink   Source File: AdamicAdar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void flatMap(Tuple4<IntValue, T, T, FloatValue> value, Collector<Tuple4<IntValue, T, T, FloatValue>> out)
		throws Exception {
	int spans = value.f0.getValue();

	for (int idx = 0; idx < spans; idx++) {
		value.f0.setValue(idx);
		out.collect(value);
	}
}
 
Example 22
Source Project: flink   Source File: ValueArrayTypeInfo.java    License: 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 23
Source Project: flink   Source File: ToNullValueTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testTranslation() throws Exception {
	NullValue reuse = NullValue.getInstance();

	assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new DoubleValue(), reuse));
	assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new FloatValue(), reuse));
	assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new IntValue(), reuse));
	assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new LongValue(), reuse));
	assertEquals(NullValue.getInstance(), new ToNullValue<>().translate(new StringValue(), reuse));
}
 
Example 24
Source Project: flink   Source File: AdamicAdar.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void reduce(Iterable<Tuple4<IntValue, T, T, FloatValue>> values, Collector<Tuple3<T, T, FloatValue>> out)
		throws Exception {
	int visitedCount = 0;

	for (Tuple4<IntValue, T, T, FloatValue> edge : values) {
		output.f1 = edge.f2;
		output.f2 = edge.f3;

		for (int i = 0; i < visitedCount; i++) {
			output.f0 = visited.get(i);
			out.collect(output);
		}

		if (visitedCount < GROUP_SIZE) {
			if (!initialized) {
				initialized = true;

				for (int i = 0; i < GROUP_SIZE; i++) {
					visited.add(edge.f2.copy());
				}
			} else {
				edge.f2.copyTo(visited.get(visitedCount));
			}

			visitedCount += 1;
		}
	}
}
 
Example 25
Source Project: flink   Source File: GraphKeyTypeTransform.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public LongValueWithProperHashCode translate(FloatValue value, LongValueWithProperHashCode reuse)
		throws Exception {
	if (reuse == null) {
		reuse = new LongValueWithProperHashCode();
	}

	reuse.setValue(0xffffffffL & Float.floatToRawIntBits(value.getValue()));
	return reuse;
}
 
Example 26
Source Project: flink   Source File: FloatValueArrayComparatorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected FloatValueArray[] getSortedTestData() {
	FloatValueArray lva0 = new FloatValueArray();

	FloatValueArray lva1 = new FloatValueArray();
	lva1.add(new FloatValue(5));

	FloatValueArray lva2 = new FloatValueArray();
	lva2.add(new FloatValue(5));
	lva2.add(new FloatValue(10));

	return new FloatValueArray[]{ lva0, lva1 };
}
 
Example 27
Source Project: flink   Source File: CSVReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWithValueType() throws Exception {
	CsvReader reader = getCsvReader();
	DataSource<Tuple8<StringValue, BooleanValue, ByteValue, ShortValue, IntValue, LongValue, FloatValue, DoubleValue>> items =
			reader.types(StringValue.class, BooleanValue.class, ByteValue.class, ShortValue.class, IntValue.class, LongValue.class, FloatValue.class, DoubleValue.class);
	TypeInformation<?> info = items.getType();

	Assert.assertEquals(true, info.isTupleType());
	Assert.assertEquals(Tuple8.class, info.getTypeClass());
}
 
Example 28
Source Project: Flink-CEPplus   Source File: SumAggregationFunction.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void aggregate(FloatValue value) {
	agg += value.getValue();
}
 
Example 29
Source Project: flink   Source File: FloatValueSerializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TypeSerializerSnapshot<FloatValue> snapshotConfiguration() {
	return new FloatValueSerializerSnapshot();
}
 
Example 30
Source Project: Flink-CEPplus   Source File: SummaryAggregatorFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Create a SummaryAggregator for the supplied type.
 * @param <T> the type to aggregate
 * @param <R> the result type of the aggregation
 */
@SuppressWarnings("unchecked")
public static <T, R> Aggregator<T, R> create(Class<T> type) {
	if (type == Long.class) {
		return (Aggregator<T, R>) new LongSummaryAggregator();
	}
	else if (type == LongValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.LongValueSummaryAggregator();
	}
	else if (type == Integer.class) {
		return (Aggregator<T, R>) new IntegerSummaryAggregator();
	}
	else if (type == IntValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.IntegerValueSummaryAggregator();
	}
	else if (type == Double.class) {
		return (Aggregator<T, R>) new DoubleSummaryAggregator();
	}
	else if (type == DoubleValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.DoubleValueSummaryAggregator();
	}
	else if (type == Float.class) {
		return (Aggregator<T, R>) new FloatSummaryAggregator();
	}
	else if (type == FloatValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.FloatValueSummaryAggregator();
	}
	else if (type == Short.class) {
		return (Aggregator<T, R>) new ShortSummaryAggregator();
	}
	else if (type == ShortValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.ShortValueSummaryAggregator();
	}
	else if (type == Boolean.class) {
		return (Aggregator<T, R>) new BooleanSummaryAggregator();
	}
	else if (type == BooleanValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.BooleanValueSummaryAggregator();
	}
	else if (type == String.class) {
		return (Aggregator<T, R>) new StringSummaryAggregator();
	}
	else if (type == StringValue.class) {
		return (Aggregator<T, R>) new ValueSummaryAggregator.StringValueSummaryAggregator();
	}
	else {
		// rather than error for unsupported types do something very generic
		return (Aggregator<T, R>) new ObjectSummaryAggregator();
	}
}