Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1354] Assign graph id to newly created elements #1365

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -30,6 +30,8 @@
import org.gradoop.flink.model.api.operators.UnaryGraphToGraphOperator;
import org.gradoop.flink.model.impl.epgm.LogicalGraph;
import org.gradoop.flink.model.impl.functions.epgm.ByLabel;
import org.gradoop.flink.model.impl.functions.epgm.Id;
import org.gradoop.flink.model.impl.functions.graphcontainment.AddToGraphBroadcast;
import org.gradoop.flink.model.impl.functions.tuple.Value0Of2;

import java.util.List;
Expand Down Expand Up @@ -152,8 +154,11 @@ public LogicalGraph execute(LogicalGraph logicalGraph) {
newPropertyName));
}


DataSet<EPGMVertex> vertices = newVerticesAndOriginIds
.map(new Value0Of2<>())
.map(new AddToGraphBroadcast<>())
.withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID)
.union(logicalGraph.getVertices());

// the newly created vertices should be linked to the original vertices
Expand All @@ -162,6 +167,8 @@ public LogicalGraph execute(LogicalGraph logicalGraph) {
edges = newVerticesAndOriginIds
.flatMap(new CreateNewEdges(logicalGraph.getFactory().getEdgeFactory(), edgeDirection,
edgeLabel))
.map(new AddToGraphBroadcast<>())
.withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID)
.union(edges);
}

Expand Down
Expand Up @@ -31,13 +31,13 @@
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
import java.util.Set;

/**
* Tests for the {@link ExtractPropertyFromVertex} operator.
Expand Down Expand Up @@ -110,7 +110,7 @@ public void edgeCreationBidirectionalTest() throws Exception {
/**
* A private convenience method for easier testing of different setups in the edge creation process.
*
* @param graph The input graph for the tests.
* @param graph The input graph for the tests.
* @param direction The edge direction the graph is tested for.
* @throws Exception Is thrown if the process cant be executed properly.
*/
Expand Down Expand Up @@ -174,7 +174,8 @@ public void nonDeduplicationTest() throws Exception {

// this operation should create 6 vertices with the property values:
// 'Berlin', 3 times 'Dresden', 2 times 'Leipzig'
ExtractPropertyFromVertex extract = new ExtractPropertyFromVertex("Person", "city", "City", "name");
ExtractPropertyFromVertex extract = new ExtractPropertyFromVertex("Person", "city",
"City", "name");
extract.setCondensation(false);

LogicalGraph extractedGraph = social.callForGraph(extract);
Expand Down Expand Up @@ -229,4 +230,44 @@ public void listPropertyTest() throws Exception {
Assert.assertTrue(properties.containsAll(Arrays.asList("m", "n", "x", "y", "z")));
}

/**
* Tests graph head ids get assigned to newly created elements.
*
* @throws Exception If collect doesn't work as expected.
*/
@Test
public void containGraphHeadIdTest() throws Exception {
LogicalGraph socialGraph = getSocialNetworkLoader().getLogicalGraph();

// this operation should create 6 vertices with the property values:
// 'Berlin', 3 times 'Dresden', 2 times 'Leipzig'
ExtractPropertyFromVertex extract = new ExtractPropertyFromVertex("Person", "city",
"City", "name", EdgeDirection.ORIGIN_TO_NEWVERTEX, "livesIn");

LogicalGraph extractedGraph = socialGraph.callForGraph(extract);

List<EPGMVertex> createdVertices = new ArrayList<>();
extractedGraph
.getVerticesByLabel("City")
.output(new LocalCollectionOutputFormat<>(createdVertices));

List<EPGMEdge> createdEdges = new ArrayList<>();
extractedGraph
.getEdgesByLabel("livesIn")
.output(new LocalCollectionOutputFormat<>(createdEdges));

getConfig().getExecutionEnvironment().execute();

// get only graph id from graph head
GradoopId socialGraphId = socialGraph.getGraphHead().collect().get(0).getId();
Rascat marked this conversation as resolved.
Show resolved Hide resolved

// check if the id of the original graph is assigned to the newly created elements
for (EPGMVertex vertex: createdVertices) {
Assert.assertTrue(vertex.getGraphIds().contains(socialGraphId));
}
for (EPGMEdge edge: createdEdges) {
Assert.assertTrue(edge.getGraphIds().contains(socialGraphId));
}
}

}