org.apache.flink.graph.utils.Tuple2ToEdgeMap Java Examples

The following examples show how to use org.apache.flink.graph.utils.Tuple2ToEdgeMap. 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: GraphCsvReader.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Graph from CSV input without vertex values or edge values.
 * @param vertexKey the type of the vertex IDs
 * @return a Graph where the vertex IDs are read from the edges input file.
 */
public <K> Graph<K, NullValue, NullValue> keyType(Class<K> vertexKey) {

	if (edgeReader == null) {
		throw new RuntimeException("The edge input file cannot be null!");
	}

	DataSet<Edge<K, NullValue>> edges = edgeReader
		.types(vertexKey, vertexKey)
			.name(GraphCsvReader.class.getName())
		.map(new Tuple2ToEdgeMap<>())
			.name("Type conversion");

	return Graph.fromDataSet(edges, executionContext);
}
 
Example #2
Source File: GraphCsvReader.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Graph from CSV input without edge values.
 * The vertex values are specified through a vertices input file or a user-defined map function.
 * If no vertices input file is provided, the vertex IDs are automatically created from the edges
 * input file.
 * @param vertexKey the type of the vertex IDs
 * @param vertexValue the type of the vertex values
 * @return a Graph where the vertex IDs and vertex values.
 */
@SuppressWarnings({ "serial", "unchecked" })
public <K, VV> Graph<K, VV, NullValue> vertexTypes(Class<K> vertexKey, Class<VV> vertexValue) {

	if (edgeReader == null) {
		throw new RuntimeException("The edge input file cannot be null!");
	}

	DataSet<Edge<K, NullValue>> edges = edgeReader
		.types(vertexKey, vertexKey)
			.name(GraphCsvReader.class.getName())
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	// the vertex value can be provided by an input file or a user-defined mapper
	if (vertexReader != null) {
		DataSet<Vertex<K, VV>> vertices = vertexReader
			.types(vertexKey, vertexValue)
				.name(GraphCsvReader.class.getName())
			.map(new Tuple2ToVertexMap<>())
				.name("Type conversion");

		return Graph.fromDataSet(vertices, edges, executionContext);
	}
	else if (mapper != null) {
		return Graph.fromDataSet(edges, (MapFunction<K, VV>) mapper, executionContext);
	}
	else {
		throw new RuntimeException("Vertex values have to be specified through a vertices input file"
				+ "or a user-defined map function.");
	}
}
 
Example #3
Source File: GraphCsvReader.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Graph from CSV input without vertex values or edge values.
 * @param vertexKey the type of the vertex IDs
 * @return a Graph where the vertex IDs are read from the edges input file.
 */
public <K> Graph<K, NullValue, NullValue> keyType(Class<K> vertexKey) {

	if (edgeReader == null) {
		throw new RuntimeException("The edge input file cannot be null!");
	}

	DataSet<Edge<K, NullValue>> edges = edgeReader
		.types(vertexKey, vertexKey)
			.name(GraphCsvReader.class.getName())
		.map(new Tuple2ToEdgeMap<>())
			.name("Type conversion");

	return Graph.fromDataSet(edges, executionContext);
}
 
Example #4
Source File: GraphCsvReader.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Graph from CSV input without edge values.
 * The vertex values are specified through a vertices input file or a user-defined map function.
 * If no vertices input file is provided, the vertex IDs are automatically created from the edges
 * input file.
 * @param vertexKey the type of the vertex IDs
 * @param vertexValue the type of the vertex values
 * @return a Graph where the vertex IDs and vertex values.
 */
@SuppressWarnings({ "serial", "unchecked" })
public <K, VV> Graph<K, VV, NullValue> vertexTypes(Class<K> vertexKey, Class<VV> vertexValue) {

	if (edgeReader == null) {
		throw new RuntimeException("The edge input file cannot be null!");
	}

	DataSet<Edge<K, NullValue>> edges = edgeReader
		.types(vertexKey, vertexKey)
			.name(GraphCsvReader.class.getName())
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	// the vertex value can be provided by an input file or a user-defined mapper
	if (vertexReader != null) {
		DataSet<Vertex<K, VV>> vertices = vertexReader
			.types(vertexKey, vertexValue)
				.name(GraphCsvReader.class.getName())
			.map(new Tuple2ToVertexMap<>())
				.name("Type conversion");

		return Graph.fromDataSet(vertices, edges, executionContext);
	}
	else if (mapper != null) {
		return Graph.fromDataSet(edges, (MapFunction<K, VV>) mapper, executionContext);
	}
	else {
		throw new RuntimeException("Vertex values have to be specified through a vertices input file"
				+ "or a user-defined map function.");
	}
}
 
Example #5
Source File: GraphCsvReader.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Graph from CSV input without vertex values or edge values.
 * @param vertexKey the type of the vertex IDs
 * @return a Graph where the vertex IDs are read from the edges input file.
 */
public <K> Graph<K, NullValue, NullValue> keyType(Class<K> vertexKey) {

	if (edgeReader == null) {
		throw new RuntimeException("The edge input file cannot be null!");
	}

	DataSet<Edge<K, NullValue>> edges = edgeReader
		.types(vertexKey, vertexKey)
			.name(GraphCsvReader.class.getName())
		.map(new Tuple2ToEdgeMap<>())
			.name("Type conversion");

	return Graph.fromDataSet(edges, executionContext);
}
 
Example #6
Source File: GraphCsvReader.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Graph from CSV input without edge values.
 * The vertex values are specified through a vertices input file or a user-defined map function.
 * If no vertices input file is provided, the vertex IDs are automatically created from the edges
 * input file.
 * @param vertexKey the type of the vertex IDs
 * @param vertexValue the type of the vertex values
 * @return a Graph where the vertex IDs and vertex values.
 */
@SuppressWarnings({ "serial", "unchecked" })
public <K, VV> Graph<K, VV, NullValue> vertexTypes(Class<K> vertexKey, Class<VV> vertexValue) {

	if (edgeReader == null) {
		throw new RuntimeException("The edge input file cannot be null!");
	}

	DataSet<Edge<K, NullValue>> edges = edgeReader
		.types(vertexKey, vertexKey)
			.name(GraphCsvReader.class.getName())
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	// the vertex value can be provided by an input file or a user-defined mapper
	if (vertexReader != null) {
		DataSet<Vertex<K, VV>> vertices = vertexReader
			.types(vertexKey, vertexValue)
				.name(GraphCsvReader.class.getName())
			.map(new Tuple2ToVertexMap<>())
				.name("Type conversion");

		return Graph.fromDataSet(vertices, edges, executionContext);
	}
	else if (mapper != null) {
		return Graph.fromDataSet(edges, (MapFunction<K, VV>) mapper, executionContext);
	}
	else {
		throw new RuntimeException("Vertex values have to be specified through a vertices input file"
				+ "or a user-defined map function.");
	}
}
 
Example #7
Source File: Graph.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a graph from a DataSet of Tuple2 objects for edges.
 * Each Tuple2 will become one Edge, where the source ID will be the first field of the Tuple2
 * and the target ID will be the second field of the Tuple2.
 *
 * <p>Edge value types and Vertex values types will be set to NullValue.
 *
 * @param edges a DataSet of Tuple2.
 * @param context the flink execution environment.
 * @return the newly created graph.
 */
public static <K> Graph<K, NullValue, NullValue> fromTuple2DataSet(DataSet<Tuple2<K, K>> edges,
		ExecutionEnvironment context) {

	DataSet<Edge<K, NullValue>> edgeDataSet = edges
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	return fromDataSet(edgeDataSet, context);
}
 
Example #8
Source File: Graph.java    From Flink-CEPplus with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a graph from a DataSet of Tuple2 objects for edges.
 * Each Tuple2 will become one Edge, where the source ID will be the first field of the Tuple2
 * and the target ID will be the second field of the Tuple2.
 *
 * <p>Edge value types will be set to NullValue.
 * Vertex values can be initialized by applying a user-defined map function on the vertex IDs.
 *
 * @param edges a DataSet of Tuple2, where the first field corresponds to the source ID
 * and the second field corresponds to the target ID.
 * @param vertexValueInitializer the mapper function that initializes the vertex values.
 * It allows to apply a map transformation on the vertex ID to produce an initial vertex value.
 * @param context the flink execution environment.
 * @return the newly created graph.
 */
public static <K, VV> Graph<K, VV, NullValue> fromTuple2DataSet(DataSet<Tuple2<K, K>> edges,
		final MapFunction<K, VV> vertexValueInitializer, ExecutionEnvironment context) {

	DataSet<Edge<K, NullValue>> edgeDataSet = edges
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	return fromDataSet(edgeDataSet, vertexValueInitializer, context);
}
 
Example #9
Source File: Graph.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a graph from a DataSet of Tuple2 objects for edges.
 * Each Tuple2 will become one Edge, where the source ID will be the first field of the Tuple2
 * and the target ID will be the second field of the Tuple2.
 *
 * <p>Edge value types and Vertex values types will be set to NullValue.
 *
 * @param edges a DataSet of Tuple2.
 * @param context the flink execution environment.
 * @return the newly created graph.
 */
public static <K> Graph<K, NullValue, NullValue> fromTuple2DataSet(DataSet<Tuple2<K, K>> edges,
		ExecutionEnvironment context) {

	DataSet<Edge<K, NullValue>> edgeDataSet = edges
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	return fromDataSet(edgeDataSet, context);
}
 
Example #10
Source File: Graph.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a graph from a DataSet of Tuple2 objects for edges.
 * Each Tuple2 will become one Edge, where the source ID will be the first field of the Tuple2
 * and the target ID will be the second field of the Tuple2.
 *
 * <p>Edge value types will be set to NullValue.
 * Vertex values can be initialized by applying a user-defined map function on the vertex IDs.
 *
 * @param edges a DataSet of Tuple2, where the first field corresponds to the source ID
 * and the second field corresponds to the target ID.
 * @param vertexValueInitializer the mapper function that initializes the vertex values.
 * It allows to apply a map transformation on the vertex ID to produce an initial vertex value.
 * @param context the flink execution environment.
 * @return the newly created graph.
 */
public static <K, VV> Graph<K, VV, NullValue> fromTuple2DataSet(DataSet<Tuple2<K, K>> edges,
		final MapFunction<K, VV> vertexValueInitializer, ExecutionEnvironment context) {

	DataSet<Edge<K, NullValue>> edgeDataSet = edges
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	return fromDataSet(edgeDataSet, vertexValueInitializer, context);
}
 
Example #11
Source File: Graph.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a graph from a DataSet of Tuple2 objects for edges.
 * Each Tuple2 will become one Edge, where the source ID will be the first field of the Tuple2
 * and the target ID will be the second field of the Tuple2.
 *
 * <p>Edge value types and Vertex values types will be set to NullValue.
 *
 * @param edges a DataSet of Tuple2.
 * @param context the flink execution environment.
 * @return the newly created graph.
 */
public static <K> Graph<K, NullValue, NullValue> fromTuple2DataSet(DataSet<Tuple2<K, K>> edges,
		ExecutionEnvironment context) {

	DataSet<Edge<K, NullValue>> edgeDataSet = edges
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	return fromDataSet(edgeDataSet, context);
}
 
Example #12
Source File: Graph.java    From flink with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a graph from a DataSet of Tuple2 objects for edges.
 * Each Tuple2 will become one Edge, where the source ID will be the first field of the Tuple2
 * and the target ID will be the second field of the Tuple2.
 *
 * <p>Edge value types will be set to NullValue.
 * Vertex values can be initialized by applying a user-defined map function on the vertex IDs.
 *
 * @param edges a DataSet of Tuple2, where the first field corresponds to the source ID
 * and the second field corresponds to the target ID.
 * @param vertexValueInitializer the mapper function that initializes the vertex values.
 * It allows to apply a map transformation on the vertex ID to produce an initial vertex value.
 * @param context the flink execution environment.
 * @return the newly created graph.
 */
public static <K, VV> Graph<K, VV, NullValue> fromTuple2DataSet(DataSet<Tuple2<K, K>> edges,
		final MapFunction<K, VV> vertexValueInitializer, ExecutionEnvironment context) {

	DataSet<Edge<K, NullValue>> edgeDataSet = edges
		.map(new Tuple2ToEdgeMap<>())
			.name("To Edge");

	return fromDataSet(edgeDataSet, vertexValueInitializer, context);
}