/** * Builds a {@link GraphCollection} from the graph referenced by the given * graph variables. * * @param variables graph variables used in GDL script * @return GraphCollection */ public GraphCollection getGraphCollectionByVariables(String... variables) { Collection<GraphHead> graphHeads = getGraphHeadsByVariables(variables); Collection<Vertex> vertices = getVerticesByGraphVariables(variables); Collection<Edge> edges = getEdgesByGraphVariables(variables); return config.getGraphCollectionFactory().fromCollections(graphHeads, vertices, edges); }
/** * Builds a {@link GraphCollection} from the graph referenced by the given * graph variables. * * @param variables graph variables used in GDL script * @return GraphCollection */ public GraphCollection getGraphCollectionByVariables(String... variables) { Collection<GraphHead> graphHeads = getGraphHeadsByVariables(variables); Collection<Vertex> vertices = getVerticesByGraphVariables(variables); Collection<Edge> edges = getEdgesByGraphVariables(variables); return config.getGraphCollectionFactory().fromCollections(graphHeads, vertices, edges); }
/** * Builds a {@link LogicalGraph} from the graph referenced by the given * graph variable. * * @param variable graph variable used in GDL script * @return LogicalGraph */ public LogicalGraph getLogicalGraphByVariable(String variable) { GraphHead graphHead = getGraphHeadByVariable(variable); Collection<Vertex> vertices = getVerticesByGraphVariables(variable); Collection<Edge> edges = getEdgesByGraphVariables(variable); return config.getLogicalGraphFactory().fromCollections(graphHead, vertices, edges); }
/** * Builds a {@link LogicalGraph} from the graph referenced by the given * graph variable. * * @param variable graph variable used in GDL script * @return LogicalGraph */ public LogicalGraph getLogicalGraphByVariable(String variable) { GraphHead graphHead = getGraphHeadByVariable(variable); Collection<Vertex> vertices = getVerticesByGraphVariables(variable); Collection<Edge> edges = getEdgesByGraphVariables(variable); return config.getLogicalGraphFactory().fromCollections(graphHead, vertices, edges); }
@Test public void testFromIndexedDataSets() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphHead g0 = loader.getGraphHeadByVariable("g0"); Map<String, DataSet<GraphHead>> indexedGraphHead = Maps.newHashMap(); indexedGraphHead.put(g0.getLabel(), getExecutionEnvironment().fromElements(g0)); Map<String, DataSet<Vertex>> indexedVertices = loader.getVerticesByGraphVariables("g0").stream() .collect(Collectors.groupingBy(Vertex::getLabel)).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> getExecutionEnvironment().fromCollection(e.getValue()))); Map<String, DataSet<Edge>> indexedEdges = loader.getEdgesByGraphVariables("g0").stream() .collect(Collectors.groupingBy(Edge::getLabel)).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> getExecutionEnvironment().fromCollection(e.getValue()))); LogicalGraphLayout<GraphHead, Vertex, Edge> logicalGraphLayout = getFactory() .fromIndexedDataSets(indexedGraphHead, indexedVertices, indexedEdges); Collection<GraphHead> loadedGraphHeads = Lists.newArrayList(); Collection<Vertex> loadedVertices = Lists.newArrayList(); Collection<Edge> loadedEdges = Lists.newArrayList(); logicalGraphLayout.getGraphHead().output(new LocalCollectionOutputFormat<>( loadedGraphHeads)); logicalGraphLayout.getVertices().output(new LocalCollectionOutputFormat<>( loadedVertices)); logicalGraphLayout.getEdges().output(new LocalCollectionOutputFormat<>( loadedEdges)); getExecutionEnvironment().execute(); validateEPGMElements(g0, loadedGraphHeads.iterator().next()); validateEPGMElementCollections(loader.getVerticesByGraphVariables("g0"), loadedVertices); validateEPGMElementCollections(loader.getEdgesByGraphVariables("g0"), loadedEdges); validateEPGMGraphElementCollections(loader.getVerticesByGraphVariables("g0"), loadedVertices); validateEPGMGraphElementCollections(loader.getEdgesByGraphVariables("g0"), loadedEdges); }
@Test public void testFromGraphTransactions() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphTransaction g0 = new GraphTransaction(loader.getGraphHeadByVariable("g0"), Sets.newHashSet(loader.getVerticesByGraphVariables("g0")), Sets.newHashSet(loader.getEdgesByGraphVariables("g0"))); GraphTransaction g1 = new GraphTransaction(loader.getGraphHeadByVariable("g1"), Sets.newHashSet(loader.getVerticesByGraphVariables("g1")), Sets.newHashSet(loader.getEdgesByGraphVariables("g1"))); GraphTransaction g2 = new GraphTransaction(loader.getGraphHeadByVariable("g2"), Sets.newHashSet(loader.getVerticesByGraphVariables("g2")), Sets.newHashSet(loader.getEdgesByGraphVariables("g2"))); DataSet<GraphTransaction> transactions = getExecutionEnvironment().fromElements(g0, g1, g2); GraphCollectionLayout<GraphHead, Vertex, Edge> collectionLayout = getFactory().fromTransactions(transactions); Collection<GraphHead> loadedGraphHeads = Lists.newArrayList(); Collection<Vertex> loadedVertices = Lists.newArrayList(); Collection<Edge> loadedEdges = Lists.newArrayList(); collectionLayout.getGraphHeads().output(new LocalCollectionOutputFormat<>(loadedGraphHeads)); collectionLayout.getVertices().output(new LocalCollectionOutputFormat<>(loadedVertices)); collectionLayout.getEdges().output(new LocalCollectionOutputFormat<>(loadedEdges)); getExecutionEnvironment().execute(); validateEPGMElementCollections(loader.getGraphHeadsByVariables("g0", "g1", "g2"), loadedGraphHeads); validateEPGMElementCollections(loader.getVerticesByGraphVariables("g0", "g1", "g2"), loadedVertices); validateEPGMElementCollections(loader.getEdgesByGraphVariables("g0", "g1", "g2"), loadedEdges); validateEPGMGraphElementCollections(loader.getVerticesByGraphVariables("g0", "g1", "g2"), loadedVertices); validateEPGMGraphElementCollections(loader.getEdgesByGraphVariables("g0", "g1", "g2"), loadedEdges); }
@Test public void testFromCollectionsWithGraphHead() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphHead graphHead = loader.getGraphHeadByVariable("g0"); LogicalGraphLayout<GraphHead, Vertex, Edge> logicalGraphLayout = getFactory() .fromCollections(graphHead, loader.getVerticesByGraphVariables("g0"), loader.getEdgesByGraphVariables("g0")); Collection<GraphHead> loadedGraphHeads = Lists.newArrayList(); Collection<Vertex> loadedVertices = Lists.newArrayList(); Collection<Edge> loadedEdges = Lists.newArrayList(); logicalGraphLayout.getGraphHead().output(new LocalCollectionOutputFormat<>(loadedGraphHeads)); logicalGraphLayout.getVertices().output(new LocalCollectionOutputFormat<>(loadedVertices)); logicalGraphLayout.getEdges().output(new LocalCollectionOutputFormat<>(loadedEdges)); getExecutionEnvironment().execute(); validateEPGMElements(graphHead, loadedGraphHeads.iterator().next()); validateEPGMElementCollections(loader.getVerticesByGraphVariables("g0"), loadedVertices); validateEPGMElementCollections(loader.getEdgesByGraphVariables("g0"), loadedEdges); validateEPGMGraphElementCollections(loader.getVerticesByGraphVariables("g0"), loadedVertices); validateEPGMGraphElementCollections(loader.getEdgesByGraphVariables("g0"), loadedEdges); }
@Test public void testFromDataSets() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphHead graphHead = loader.getGraphHeadByVariable("g0"); Collection<Vertex> vertices = loader.getVerticesByGraphVariables("g0"); Collection<Edge> edges = loader.getEdgesByGraphVariables("g0"); DataSet<GraphHead> graphHeadDataSet = getExecutionEnvironment().fromElements(graphHead); DataSet<Vertex> vertexDataSet = getExecutionEnvironment().fromCollection(vertices); DataSet<Edge> edgeDataSet = getExecutionEnvironment().fromCollection(edges); LogicalGraphLayout<GraphHead, Vertex, Edge> logicalGraphLayout = getFactory() .fromDataSets(graphHeadDataSet, vertexDataSet, edgeDataSet); Collection<GraphHead> loadedGraphHeads = Lists.newArrayList(); Collection<Vertex> loadedVertices = Lists.newArrayList(); Collection<Edge> loadedEdges = Lists.newArrayList(); logicalGraphLayout.getGraphHead().output(new LocalCollectionOutputFormat<>( loadedGraphHeads)); logicalGraphLayout.getVertices().output(new LocalCollectionOutputFormat<>( loadedVertices)); logicalGraphLayout.getEdges().output(new LocalCollectionOutputFormat<>( loadedEdges)); getExecutionEnvironment().execute(); validateEPGMElements(graphHead, loadedGraphHeads.iterator().next()); validateEPGMElementCollections(vertices, loadedVertices); validateEPGMElementCollections(edges, loadedEdges); validateEPGMGraphElementCollections(vertices, loadedVertices); validateEPGMGraphElementCollections(edges, loadedEdges); }