@Test public void listPropertyTest() throws Exception { VertexFactory<EPGMVertex> vf = getConfig().getLogicalGraphFactory().getVertexFactory(); EPGMVertex v1 = vf.createVertex("foo"); v1.setProperty("a", PropertyValue.create(Arrays.asList(PropertyValue.create("m"), PropertyValue.create("n")))); EPGMVertex v2 = vf.createVertex("foo"); v2.setProperty("a", PropertyValue.create(Arrays.asList(PropertyValue.create("x"), PropertyValue.create("y"), PropertyValue.create("z")))); LogicalGraph input = getConfig().getLogicalGraphFactory().fromCollections( Arrays.asList(v1, v2), Collections.emptyList()); ExtractPropertyFromVertex ext = new ExtractPropertyFromVertex("foo", "a", "A", "key"); LogicalGraph output = input.callForGraph(ext); List<EPGMVertex> createdVertices = new ArrayList<>(); output.getVertices() .filter(new ByLabel<>("A")) .output(new LocalCollectionOutputFormat<>(createdVertices)); input.getConfig().getExecutionEnvironment().execute(); ArrayList<String> properties = new ArrayList<>(); createdVertices.forEach(v -> properties.add(v.getPropertyValue("key").getString())); Assert.assertTrue(properties.containsAll(Arrays.asList("m", "n", "x", "y", "z"))); }
@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);  }