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

The following examples show how to use org.apache.flink.types.CopyableValue. 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-CEPplus   Source File: JaccardIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param distinctNeighborCount result distinct neighbor count
 * @param sharedNeighborCount result shared neighbor count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long distinctNeighborCount, long sharedNeighborCount) throws Exception {
	DataSet<Result<T>> ji = graph
		.run(new JaccardIndex<T, NullValue, NullValue>()
			.setGroupSize(4));

	List<Result<T>> results = ji.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(distinctNeighborCount, result.getDistinctNeighborCount().getValue());
		assertEquals(sharedNeighborCount, result.getSharedNeighborCount().getValue());
	}
}
 
Example 2
Source Project: flink   Source File: JaccardIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param distinctNeighborCount result distinct neighbor count
 * @param sharedNeighborCount result shared neighbor count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long distinctNeighborCount, long sharedNeighborCount) throws Exception {
	DataSet<Result<T>> ji = graph
		.run(new JaccardIndex<T, NullValue, NullValue>()
			.setGroupSize(4));

	List<Result<T>> results = ji.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(distinctNeighborCount, result.getDistinctNeighborCount().getValue());
		assertEquals(sharedNeighborCount, result.getSharedNeighborCount().getValue());
	}
}
 
Example 3
Source Project: flink   Source File: JaccardIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param distinctNeighborCount result distinct neighbor count
 * @param sharedNeighborCount result shared neighbor count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long distinctNeighborCount, long sharedNeighborCount) throws Exception {
	DataSet<Result<T>> ji = graph
		.run(new JaccardIndex<T, NullValue, NullValue>()
			.setGroupSize(4));

	List<Result<T>> results = ji.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(distinctNeighborCount, result.getDistinctNeighborCount().getValue());
		assertEquals(sharedNeighborCount, result.getSharedNeighborCount().getValue());
	}
}
 
Example 4
Source Project: Flink-CEPplus   Source File: MaxAggregationFunction.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> AggregationFunction<T> createAggregationFunction(Class<T> type) {
	if (Comparable.class.isAssignableFrom(type)) {
		if (ResettableValue.class.isAssignableFrom(type) && CopyableValue.class.isAssignableFrom(type)) {
			return (AggregationFunction<T>) new MutableMaxAgg();
		} else {
			return (AggregationFunction<T>) new ImmutableMaxAgg();
		}
	} else {
		throw new UnsupportedAggregationTypeException("The type " + type.getName() +
			" is not supported for maximum aggregation. " +
			"Maximum aggregatable types must implement the Comparable interface.");
	}
}
 
Example 5
Source Project: Flink-CEPplus   Source File: MinAggregationFunction.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> AggregationFunction<T> createAggregationFunction(Class<T> type) {
	if (Comparable.class.isAssignableFrom(type)) {
		if (ResettableValue.class.isAssignableFrom(type) && CopyableValue.class.isAssignableFrom(type)) {
			return (AggregationFunction<T>) new MutableMinAgg();
		} else {
			return (AggregationFunction<T>) new ImmutableMinAgg();
		}
	} else {
		throw new UnsupportedAggregationTypeException("The type " + type.getName() +
			" is not supported for minimum aggregation. " +
			"Minimum aggregatable types must implement the Comparable interface.");
	}
}
 
Example 6
Source Project: Flink-CEPplus   Source File: CopyableValueComparator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
	if (tempReference == null) {
		tempReference = InstantiationUtil.instantiate(type, CopyableValue.class);
	}
	
	reference.read(firstSource);
	tempReference.read(secondSource);
	int comp = reference.compareTo(tempReference);
	return ascendingComparison ? comp : -comp;
}
 
Example 7
Source Project: Flink-CEPplus   Source File: CopyableValueComparator.java    License: Apache License 2.0 5 votes vote down vote up
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
	// read basic object and the type
	s.defaultReadObject();
	
	this.reference = InstantiationUtil.instantiate(type, CopyableValue.class);
	this.tempReference = null;
}
 
Example 8
Source Project: Flink-CEPplus   Source File: AdamicAdarTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param score result score
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, double score) throws Exception {
	DataSet<Result<T>> aa = graph
		.run(new AdamicAdar<>());

	List<Result<T>> results = aa.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(score, result.getAdamicAdarScore().getValue(), ACCURACY);
	}
}
 
Example 9
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param vertexCount result vertex count
 * @param averageClusteringCoefficient result average clustering coefficient
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long vertexCount, double averageClusteringCoefficient) throws Exception {
	Result result = new AverageClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(vertexCount, result.getNumberOfVertices());
	assertEquals(averageClusteringCoefficient, result.getAverageClusteringCoefficient(), ACCURACY);
}
 
Example 10
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param degree result degree
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long degree, long triangleCount) throws Exception {
	DataSet<Result<T>> cc = graph
		.run(new LocalClusteringCoefficient<>());

	List<Result<T>> results = cc.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(degree, result.getDegree().getValue());
		assertEquals(triangleCount, result.getTriangleCount().getValue());
	}
}
 
Example 11
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param tripletCount result triplet count
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long tripletCount, long triangleCount) throws Exception {
	Result result = new GlobalClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(tripletCount, result.getNumberOfTriplets());
	assertEquals(triangleCount, result.getNumberOfTriangles());
}
 
Example 12
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param vertexCount result vertex count
 * @param averageClusteringCoefficient result average clustering coefficient
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long vertexCount, double averageClusteringCoefficient) throws Exception {
	Result result = new AverageClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(vertexCount, result.getNumberOfVertices());
	assertEquals(averageClusteringCoefficient, result.getAverageClusteringCoefficient(), ACCURACY);
}
 
Example 13
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param degree result degree
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long degree, long triangleCount) throws Exception {
	DataSet<Result<T>> cc = graph
		.run(new LocalClusteringCoefficient<>());

	List<Result<T>> results = cc.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(degree, result.getDegree().getValue());
		assertEquals(triangleCount, result.getTriangleCount().getValue());
	}
}
 
Example 14
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param tripletCount result triplet count
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long tripletCount, long triangleCount) throws Exception {
	Result result = new GlobalClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(tripletCount, result.getNumberOfTriplets());
	assertEquals(triangleCount, result.getNumberOfTriangles());
}
 
Example 15
Source Project: flink   Source File: MaxAggregationFunction.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> AggregationFunction<T> createAggregationFunction(Class<T> type) {
	if (Comparable.class.isAssignableFrom(type)) {
		if (ResettableValue.class.isAssignableFrom(type) && CopyableValue.class.isAssignableFrom(type)) {
			return (AggregationFunction<T>) new MutableMaxAgg();
		} else {
			return (AggregationFunction<T>) new ImmutableMaxAgg();
		}
	} else {
		throw new UnsupportedAggregationTypeException("The type " + type.getName() +
			" is not supported for maximum aggregation. " +
			"Maximum aggregatable types must implement the Comparable interface.");
	}
}
 
Example 16
Source Project: flink   Source File: MinAggregationFunction.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> AggregationFunction<T> createAggregationFunction(Class<T> type) {
	if (Comparable.class.isAssignableFrom(type)) {
		if (ResettableValue.class.isAssignableFrom(type) && CopyableValue.class.isAssignableFrom(type)) {
			return (AggregationFunction<T>) new MutableMinAgg();
		} else {
			return (AggregationFunction<T>) new ImmutableMinAgg();
		}
	} else {
		throw new UnsupportedAggregationTypeException("The type " + type.getName() +
			" is not supported for minimum aggregation. " +
			"Minimum aggregatable types must implement the Comparable interface.");
	}
}
 
Example 17
Source Project: flink   Source File: CopyableValueComparator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
	if (tempReference == null) {
		tempReference = InstantiationUtil.instantiate(type, CopyableValue.class);
	}
	
	reference.read(firstSource);
	tempReference.read(secondSource);
	int comp = reference.compareTo(tempReference);
	return ascendingComparison ? comp : -comp;
}
 
Example 18
Source Project: flink   Source File: CopyableValueComparator.java    License: Apache License 2.0 5 votes vote down vote up
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
	// read basic object and the type
	s.defaultReadObject();
	
	this.reference = InstantiationUtil.instantiate(type, CopyableValue.class);
	this.tempReference = null;
}
 
Example 19
Source Project: flink   Source File: AdamicAdarTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param score result score
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, double score) throws Exception {
	DataSet<Result<T>> aa = graph
		.run(new AdamicAdar<>());

	List<Result<T>> results = aa.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(score, result.getAdamicAdarScore().getValue(), ACCURACY);
	}
}
 
Example 20
Source Project: flink   Source File: AverageClusteringCoefficientTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param vertexCount result vertex count
 * @param averageClusteringCoefficient result average clustering coefficient
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long vertexCount, double averageClusteringCoefficient) throws Exception {
	Result result = new AverageClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(vertexCount, result.getNumberOfVertices());
	assertEquals(averageClusteringCoefficient, result.getAverageClusteringCoefficient(), ACCURACY);
}
 
Example 21
Source Project: flink   Source File: LocalClusteringCoefficientTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param degree result degree
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long degree, long triangleCount) throws Exception {
	DataSet<Result<T>> cc = graph
		.run(new LocalClusteringCoefficient<>());

	List<Result<T>> results = cc.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(degree, result.getDegree().getValue());
		assertEquals(triangleCount, result.getTriangleCount().getValue());
	}
}
 
Example 22
Source Project: flink   Source File: GlobalClusteringCoefficientTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param tripletCount result triplet count
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long tripletCount, long triangleCount) throws Exception {
	Result result = new GlobalClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(tripletCount, result.getNumberOfTriplets());
	assertEquals(triangleCount, result.getNumberOfTriangles());
}
 
Example 23
Source Project: flink   Source File: AverageClusteringCoefficientTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param vertexCount result vertex count
 * @param averageClusteringCoefficient result average clustering coefficient
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long vertexCount, double averageClusteringCoefficient) throws Exception {
	Result result = new AverageClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(vertexCount, result.getNumberOfVertices());
	assertEquals(averageClusteringCoefficient, result.getAverageClusteringCoefficient(), ACCURACY);
}
 
Example 24
Source Project: flink   Source File: LocalClusteringCoefficientTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param degree result degree
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, long degree, long triangleCount) throws Exception {
	DataSet<Result<T>> cc = graph
		.run(new LocalClusteringCoefficient<>());

	List<Result<T>> results = cc.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(degree, result.getDegree().getValue());
		assertEquals(triangleCount, result.getTriangleCount().getValue());
	}
}
 
Example 25
Source Project: flink   Source File: GlobalClusteringCoefficientTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test result.
 *
 * @param graph input graph
 * @param tripletCount result triplet count
 * @param triangleCount result triangle count
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends Comparable<T> & CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long tripletCount, long triangleCount) throws Exception {
	Result result = new GlobalClusteringCoefficient<T, NullValue, NullValue>()
		.run(graph)
		.execute();

	assertEquals(tripletCount, result.getNumberOfTriplets());
	assertEquals(triangleCount, result.getNumberOfTriangles());
}
 
Example 26
Source Project: flink   Source File: MaxAggregationFunction.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> AggregationFunction<T> createAggregationFunction(Class<T> type) {
	if (Comparable.class.isAssignableFrom(type)) {
		if (ResettableValue.class.isAssignableFrom(type) && CopyableValue.class.isAssignableFrom(type)) {
			return (AggregationFunction<T>) new MutableMaxAgg();
		} else {
			return (AggregationFunction<T>) new ImmutableMaxAgg();
		}
	} else {
		throw new UnsupportedAggregationTypeException("The type " + type.getName() +
			" is not supported for maximum aggregation. " +
			"Maximum aggregatable types must implement the Comparable interface.");
	}
}
 
Example 27
Source Project: flink   Source File: MinAggregationFunction.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public <T> AggregationFunction<T> createAggregationFunction(Class<T> type) {
	if (Comparable.class.isAssignableFrom(type)) {
		if (ResettableValue.class.isAssignableFrom(type) && CopyableValue.class.isAssignableFrom(type)) {
			return (AggregationFunction<T>) new MutableMinAgg();
		} else {
			return (AggregationFunction<T>) new ImmutableMinAgg();
		}
	} else {
		throw new UnsupportedAggregationTypeException("The type " + type.getName() +
			" is not supported for minimum aggregation. " +
			"Minimum aggregatable types must implement the Comparable interface.");
	}
}
 
Example 28
Source Project: flink   Source File: CopyableValueComparator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
	if (tempReference == null) {
		tempReference = InstantiationUtil.instantiate(type, CopyableValue.class);
	}
	
	reference.read(firstSource);
	tempReference.read(secondSource);
	int comp = reference.compareTo(tempReference);
	return ascendingComparison ? comp : -comp;
}
 
Example 29
Source Project: flink   Source File: CopyableValueComparator.java    License: Apache License 2.0 5 votes vote down vote up
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {
	// read basic object and the type
	s.defaultReadObject();
	
	this.reference = InstantiationUtil.instantiate(type, CopyableValue.class);
	this.tempReference = null;
}
 
Example 30
Source Project: flink   Source File: AdamicAdarTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validate a test where each result has the same values.
 *
 * @param graph input graph
 * @param count number of results
 * @param score result score
 * @param <T> graph ID type
 * @throws Exception on error
 */
private static <T extends CopyableValue<T>> void validate(
		Graph<T, NullValue, NullValue> graph, long count, double score) throws Exception {
	DataSet<Result<T>> aa = graph
		.run(new AdamicAdar<>());

	List<Result<T>> results = aa.collect();

	assertEquals(count, results.size());

	for (Result<T> result : results) {
		assertEquals(score, result.getAdamicAdarScore().getValue(), ACCURACY);
	}
}