@Test public void containGraphHeadIdTest() throws Exception { LogicalGraph socialGraph = getSocialNetworkLoader().getLogicalGraph(); 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)); List<EPGMGraphHead> graphHeads = new ArrayList<>(); socialGraph.getGraphHead().output(new LocalCollectionOutputFormat<>(graphHeads)); getConfig().getExecutionEnvironment().execute(); for (EPGMGraphHead graphHead: graphHeads) { for (EPGMVertex vertex: createdVertices) { Assert.assertTrue(vertex.getGraphIds().contains(graphHead.getId())); } for (EPGMEdge edge: createdEdges) { Assert.assertTrue(edge.getGraphIds().contains(graphHead.getId())); } } }
@Override public LogicalGraph execute(LogicalGraph logicalGraph) { DataSet<EPGMVertex> filteredVertices = logicalGraph .getVertices() .filter(new ByLabel<>(forVerticesOfLabel)); DataSet<Tuple2<PropertyValue, GradoopId>> candidates = filteredVertices .flatMap(new ExtractPropertyWithOriginId(originalPropertyName)); DataSet<Tuple2<EPGMVertex, List<GradoopId>>> newVerticesAndOriginIds; if (condense) { newVerticesAndOriginIds = candidates .groupBy(0) .reduceGroup(new CreateNewVertexWithEqualityCondense( logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } else { newVerticesAndOriginIds = candidates .map(new CreateNewVertex(logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } DataSet<EPGMVertex> vertices = newVerticesAndOriginIds .map(new Value0Of2<>()) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(logicalGraph.getVertices()); DataSet<EPGMEdge> edges = logicalGraph.getEdges(); if (!edgeDirection.equals(EdgeDirection.NONE)) { edges = newVerticesAndOriginIds .flatMap(new CreateNewEdges(logicalGraph.getFactory().getEdgeFactory(), edgeDirection, edgeLabel)) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(edges); } return logicalGraph.getFactory() .fromDataSets(logicalGraph.getGraphHead(), vertices, edges); }
ExtractPropertyFromVertex implements UnaryGraphToGraphOperator { @Override public LogicalGraph execute(LogicalGraph logicalGraph) { DataSet<EPGMVertex> filteredVertices = logicalGraph .getVertices() .filter(new ByLabel<>(forVerticesOfLabel)); DataSet<Tuple2<PropertyValue, GradoopId>> candidates = filteredVertices .flatMap(new ExtractPropertyWithOriginId(originalPropertyName)); DataSet<Tuple2<EPGMVertex, List<GradoopId>>> newVerticesAndOriginIds; if (condense) { newVerticesAndOriginIds = candidates .groupBy(0) .reduceGroup(new CreateNewVertexWithEqualityCondense( logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } else { newVerticesAndOriginIds = candidates .map(new CreateNewVertex(logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } DataSet<EPGMVertex> vertices = newVerticesAndOriginIds .map(new Value0Of2<>()) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(logicalGraph.getVertices()); DataSet<EPGMEdge> edges = logicalGraph.getEdges(); if (!edgeDirection.equals(EdgeDirection.NONE)) { edges = newVerticesAndOriginIds .flatMap(new CreateNewEdges(logicalGraph.getFactory().getEdgeFactory(), edgeDirection, edgeLabel)) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(edges); } return logicalGraph.getFactory() .fromDataSets(logicalGraph.getGraphHead(), vertices, edges); } }
ExtractPropertyFromVertex implements UnaryGraphToGraphOperator { @Override public LogicalGraph execute(LogicalGraph logicalGraph) { DataSet<EPGMVertex> filteredVertices = logicalGraph .getVertices() .filter(new ByLabel<>(forVerticesOfLabel)); DataSet<Tuple2<PropertyValue, GradoopId>> candidates = filteredVertices .flatMap(new ExtractPropertyWithOriginId(originalPropertyName)); DataSet<Tuple2<EPGMVertex, List<GradoopId>>> newVerticesAndOriginIds; if (condense) { newVerticesAndOriginIds = candidates .groupBy(0) .reduceGroup(new CreateNewVertexWithEqualityCondense( logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } else { newVerticesAndOriginIds = candidates .map(new CreateNewVertex(logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } DataSet<EPGMVertex> vertices = newVerticesAndOriginIds .map(new Value0Of2<>()) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(logicalGraph.getVertices()); DataSet<EPGMEdge> edges = logicalGraph.getEdges(); if (!edgeDirection.equals(EdgeDirection.NONE)) { edges = newVerticesAndOriginIds .flatMap(new CreateNewEdges(logicalGraph.getFactory().getEdgeFactory(), edgeDirection, edgeLabel)) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(edges); } return logicalGraph.getFactory() .fromDataSets(logicalGraph.getGraphHead(), vertices, edges); } ExtractPropertyFromVertex(String forVerticesOfLabel, String originalPropertyName,
                                   String newVertexLabel, String newPropertyName);  ExtractPropertyFromVertex(String forVerticesOfLabel, String originalPropertyName,
                                   String newVertexLabel, String newPropertyName,
                                   EdgeDirection edgeDirection, String edgeLabel); }
ExtractPropertyFromVertex implements UnaryGraphToGraphOperator { @Override public LogicalGraph execute(LogicalGraph logicalGraph) { DataSet<EPGMVertex> filteredVertices = logicalGraph .getVertices() .filter(new ByLabel<>(forVerticesOfLabel)); DataSet<Tuple2<PropertyValue, GradoopId>> candidates = filteredVertices .flatMap(new ExtractPropertyWithOriginId(originalPropertyName)); DataSet<Tuple2<EPGMVertex, List<GradoopId>>> newVerticesAndOriginIds; if (condense) { newVerticesAndOriginIds = candidates .groupBy(0) .reduceGroup(new CreateNewVertexWithEqualityCondense( logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } else { newVerticesAndOriginIds = candidates .map(new CreateNewVertex(logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } DataSet<EPGMVertex> vertices = newVerticesAndOriginIds .map(new Value0Of2<>()) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(logicalGraph.getVertices()); DataSet<EPGMEdge> edges = logicalGraph.getEdges(); if (!edgeDirection.equals(EdgeDirection.NONE)) { edges = newVerticesAndOriginIds .flatMap(new CreateNewEdges(logicalGraph.getFactory().getEdgeFactory(), edgeDirection, edgeLabel)) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(edges); } return logicalGraph.getFactory() .fromDataSets(logicalGraph.getGraphHead(), vertices, edges); } ExtractPropertyFromVertex(String forVerticesOfLabel, String originalPropertyName,
                                   String newVertexLabel, String newPropertyName);  ExtractPropertyFromVertex(String forVerticesOfLabel, String originalPropertyName,
                                   String newVertexLabel, String newPropertyName,
                                   EdgeDirection edgeDirection, String edgeLabel); void setCondensation(boolean condense); @Override LogicalGraph execute(LogicalGraph logicalGraph); }
ExtractPropertyFromVertex implements UnaryGraphToGraphOperator { @Override public LogicalGraph execute(LogicalGraph logicalGraph) { DataSet<EPGMVertex> filteredVertices = logicalGraph .getVertices() .filter(new ByLabel<>(forVerticesOfLabel)); DataSet<Tuple2<PropertyValue, GradoopId>> candidates = filteredVertices .flatMap(new ExtractPropertyWithOriginId(originalPropertyName)); DataSet<Tuple2<EPGMVertex, List<GradoopId>>> newVerticesAndOriginIds; if (condense) { newVerticesAndOriginIds = candidates .groupBy(0) .reduceGroup(new CreateNewVertexWithEqualityCondense( logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } else { newVerticesAndOriginIds = candidates .map(new CreateNewVertex(logicalGraph.getFactory().getVertexFactory(), newVertexLabel, newPropertyName)); } DataSet<EPGMVertex> vertices = newVerticesAndOriginIds .map(new Value0Of2<>()) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(logicalGraph.getVertices()); DataSet<EPGMEdge> edges = logicalGraph.getEdges(); if (!edgeDirection.equals(EdgeDirection.NONE)) { edges = newVerticesAndOriginIds .flatMap(new CreateNewEdges(logicalGraph.getFactory().getEdgeFactory(), edgeDirection, edgeLabel)) .map(new AddToGraphBroadcast<>()) .withBroadcastSet(logicalGraph.getGraphHead().map(new Id<>()), AddToGraphBroadcast.GRAPH_ID) .union(edges); } return logicalGraph.getFactory() .fromDataSets(logicalGraph.getGraphHead(), vertices, edges); } ExtractPropertyFromVertex(String forVerticesOfLabel, String originalPropertyName,
                                   String newVertexLabel, String newPropertyName);  ExtractPropertyFromVertex(String forVerticesOfLabel, String originalPropertyName,
                                   String newVertexLabel, String newPropertyName,
                                   EdgeDirection edgeDirection, String edgeLabel); void setCondensation(boolean condense); @Override LogicalGraph execute(LogicalGraph logicalGraph);  }