org.apache.flink.types.CopyableValue Java Examples

The following examples show how to use org.apache.flink.types.CopyableValue. 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: JaccardIndexTest.java    From flink with 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 File: JaccardIndexTest.java    From Flink-CEPplus with 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 File: JaccardIndexTest.java    From flink with 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 File: CopyableValueComparator.java    From flink with 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 #5
Source File: AdamicAdarTest.java    From flink with 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 #6
Source File: AverageClusteringCoefficientTest.java    From flink with 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 #7
Source File: LocalClusteringCoefficientTest.java    From flink with 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 #8
Source File: GlobalClusteringCoefficientTest.java    From flink with 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 #9
Source File: AverageClusteringCoefficientTest.java    From flink with 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 #10
Source File: LocalClusteringCoefficientTest.java    From flink with 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 #11
Source File: GlobalClusteringCoefficientTest.java    From flink with 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 #12
Source File: MaxAggregationFunction.java    From flink with 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 #13
Source File: MinAggregationFunction.java    From flink with 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 #14
Source File: GlobalClusteringCoefficientTest.java    From flink with 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 #15
Source File: CopyableValueComparator.java    From flink with 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 #16
Source File: AdamicAdarTest.java    From flink with 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 #17
Source File: AverageClusteringCoefficientTest.java    From flink with 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 #18
Source File: LocalClusteringCoefficientTest.java    From flink with 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 #19
Source File: GlobalClusteringCoefficientTest.java    From flink with 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 #20
Source File: AverageClusteringCoefficientTest.java    From flink with 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 File: LocalClusteringCoefficientTest.java    From flink with 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 File: MaxAggregationFunction.java    From Flink-CEPplus with 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 #23
Source File: LocalClusteringCoefficientTest.java    From Flink-CEPplus with 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 #24
Source File: MinAggregationFunction.java    From Flink-CEPplus with 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 #25
Source File: CopyableValueComparator.java    From Flink-CEPplus with 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 #26
Source File: CopyableValueComparator.java    From Flink-CEPplus with 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 #27
Source File: AdamicAdarTest.java    From Flink-CEPplus with 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 #28
Source File: AverageClusteringCoefficientTest.java    From Flink-CEPplus with 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 #29
Source File: GlobalClusteringCoefficientTest.java    From Flink-CEPplus with 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 #30
Source File: AverageClusteringCoefficientTest.java    From Flink-CEPplus with 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);
}