/** * Returns a logical graph containing the complete vertex and edge space of * the database. * * @param withGraphContainment true, if vertices and edges shall be updated to * be contained in the logical graph representing * the database * @return logical graph of vertex and edge space */ public LogicalGraph getLogicalGraph(boolean withGraphContainment) { if (withGraphContainment) { return config.getLogicalGraphFactory().fromCollections(getVertices(), getEdges()) .transformGraphHead(new RenameLabel<>(GradoopConstants.DEFAULT_GRAPH_LABEL, GradoopConstants.DB_GRAPH_LABEL)); } else { GraphHead graphHead = config.getGraphHeadFactory() .createGraphHead(GradoopConstants.DB_GRAPH_LABEL); return config.getLogicalGraphFactory().fromCollections(graphHead, getVertices(), getEdges()); } }
/** * Returns a logical graph containing the complete vertex and edge space of * the database. * * @param withGraphContainment true, if vertices and edges shall be updated to * be contained in the logical graph representing * the database * @return logical graph of vertex and edge space */ public LogicalGraph getLogicalGraph(boolean withGraphContainment) { if (withGraphContainment) { return config.getLogicalGraphFactory().fromCollections(getVertices(), getEdges()) .transformGraphHead(new RenameLabel<>(GradoopConstants.DEFAULT_GRAPH_LABEL, GradoopConstants.DB_GRAPH_LABEL)); } else { GraphHead graphHead = config.getGraphHeadFactory() .createGraphHead(GradoopConstants.DB_GRAPH_LABEL); return config.getLogicalGraphFactory().fromCollections(graphHead, getVertices(), getEdges()); } }
@Test public void testFromIndexedDataSets() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); Map<String, DataSet<GraphHead>> indexedGraphHeads = loader.getGraphHeads().stream() .collect(Collectors.groupingBy(GraphHead::getLabel)).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> getExecutionEnvironment().fromCollection(e.getValue()))); Map<String, DataSet<Vertex>> indexedVertices = loader.getVertices().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.getEdges().stream() .collect(Collectors.groupingBy(Edge::getLabel)).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> getExecutionEnvironment().fromCollection(e.getValue()))); GraphCollectionLayout<GraphHead, Vertex, Edge> collectionLayout = getFactory() .fromIndexedDataSets(indexedGraphHeads, indexedVertices, indexedEdges); 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.getGraphHeads(), loadedGraphHeads); validateEPGMElementCollections(loader.getVertices(), loadedVertices); validateEPGMElementCollections(loader.getEdges(), loadedEdges); validateEPGMGraphElementCollections(loader.getVertices(), loadedVertices); validateEPGMGraphElementCollections(loader.getEdges(), loadedEdges); }
/** * Returns a collection of all logical graph contained in the database. * * @return collection of all logical graphs */ public GraphCollection getGraphCollection() { ExecutionEnvironment env = config.getExecutionEnvironment(); DataSet<Vertex> newVertices = env.fromCollection(getVertices()) .filter(vertex -> vertex.getGraphCount() > 0); DataSet<Edge> newEdges = env.fromCollection(getEdges()) .filter(edge -> edge.getGraphCount() > 0); return config.getGraphCollectionFactory() .fromDataSets(env.fromCollection(getGraphHeads()), newVertices, newEdges); }
/** * Returns a collection of all logical graph contained in the database. * * @return collection of all logical graphs */ public GraphCollection getGraphCollection() { ExecutionEnvironment env = config.getExecutionEnvironment(); DataSet<Vertex> newVertices = env.fromCollection(getVertices()) .filter(vertex -> vertex.getGraphCount() > 0); DataSet<Edge> newEdges = env.fromCollection(getEdges()) .filter(edge -> edge.getGraphCount() > 0); return config.getGraphCollectionFactory() .fromDataSets(env.fromCollection(getGraphHeads()), newVertices, newEdges); }
@Test public void testGetVertices() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); Collection<Vertex> inputVertices = loader.getVertices(); List<Vertex> outputVertices = loader.getLogicalGraph(false).getVertices().collect(); validateEPGMElementCollections(inputVertices, outputVertices); validateEPGMGraphElementCollections(inputVertices, outputVertices); }
@Test public void testFromCollections() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollectionLayout<GraphHead, Vertex, Edge> collectionLayout = getFactory() .fromCollections(loader.getGraphHeads(), loader.getVertices(), loader.getEdges()); 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.getGraphHeads(), loadedGraphHeads); validateEPGMElementCollections(loader.getVertices(), loadedVertices); validateEPGMElementCollections(loader.getEdges(), loadedEdges); validateEPGMGraphElementCollections(loader.getVertices(), loadedVertices); validateEPGMGraphElementCollections(loader.getEdges(), loadedEdges); }
@Test public void testFromDataSetsWithoutGraphHead() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString("()-->()<--()-->()"); LogicalGraphLayout<GraphHead, Vertex, Edge> logicalGraphLayout = getFactory() .fromDataSets( getExecutionEnvironment().fromCollection(loader.getVertices()), getExecutionEnvironment().fromCollection(loader.getEdges())); Collection<GraphHead> loadedGraphHead = Lists.newArrayList(); Collection<Vertex> loadedVertices = Lists.newArrayList(); Collection<Edge> loadedEdges = Lists.newArrayList(); logicalGraphLayout.getGraphHead().output(new LocalCollectionOutputFormat<>(loadedGraphHead)); logicalGraphLayout.getVertices().output(new LocalCollectionOutputFormat<>(loadedVertices)); logicalGraphLayout.getEdges().output(new LocalCollectionOutputFormat<>(loadedEdges)); getExecutionEnvironment().execute(); GraphHead newGraphHead = loadedGraphHead.iterator().next(); validateEPGMElementCollections(loadedVertices, loader.getVertices()); validateEPGMElementCollections(loadedEdges, loader.getEdges()); Collection<GraphElement> epgmElements = new ArrayList<>(); epgmElements.addAll(loadedVertices); epgmElements.addAll(loadedEdges); for (GraphElement loadedVertex : epgmElements) { assertEquals("graph element has wrong graph count", 1, loadedVertex.getGraphCount()); assertTrue("graph element was not in new graph", loadedVertex.getGraphIds().contains(newGraphHead.getId())); } }
@Test public void testFromDataSetsWithoutGraphHead() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString("()-[]->(),[()]"); GraphCollectionLayout<GraphHead, Vertex, Edge> collectionLayout = getFactory() .fromDataSets( getExecutionEnvironment().fromCollection(loader.getGraphHeads()), getExecutionEnvironment().fromCollection(loader.getVertices()), getExecutionEnvironment().fromCollection(loader.getEdges())); 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.getGraphHeads(), loadedGraphHeads); validateEPGMElementCollections(loader.getVertices(), loadedVertices); validateEPGMElementCollections(loader.getEdges(), loadedEdges); validateEPGMGraphElementCollections(loader.getVertices(), loadedVertices); validateEPGMGraphElementCollections(loader.getEdges(), loadedEdges); }
@Test public void write() throws Exception { AccumuloEPGMStore accumuloStore = new AccumuloEPGMStore(AccumuloTestSuite.getAcConfig(TEST_02)); FlinkAsciiGraphLoader loader = new FlinkAsciiGraphLoader( GradoopFlinkConfig.createConfig(getExecutionEnvironment())); InputStream inputStream = getClass().getResourceAsStream( GradoopTestUtils.SOCIAL_NETWORK_GDL_FILE); loader.initDatabaseFromStream(inputStream); GradoopFlinkConfig flinkConfig = GradoopFlinkConfig.createConfig(getExecutionEnvironment()); new AccumuloDataSink(accumuloStore, flinkConfig) .write(flinkConfig.getGraphCollectionFactory() .fromCollections( loader.getGraphHeads(), loader.getVertices(), loader.getEdges())); getExecutionEnvironment().execute(); accumuloStore.flush(); validateEPGMElementCollections(loader.getGraphHeads(), accumuloStore.getGraphSpace().readRemainsAndClose()); validateEPGMElementCollections(loader.getVertices(), accumuloStore.getVertexSpace().readRemainsAndClose()); validateEPGMGraphElementCollections(loader.getVertices(), accumuloStore.getVertexSpace().readRemainsAndClose()); validateEPGMElementCollections(loader.getEdges(), accumuloStore.getEdgeSpace().readRemainsAndClose()); validateEPGMGraphElementCollections(loader.getEdges(), accumuloStore.getEdgeSpace().readRemainsAndClose()); accumuloStore.close(); }
@Test public void testFromDataSets() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); Collection<GraphHead> graphHeads = loader.getGraphHeads(); Collection<Vertex> vertices = loader.getVertices(); Collection<Edge> edges = loader.getEdges(); DataSet<GraphHead> graphHeadDataSet = getExecutionEnvironment() .fromCollection(graphHeads); DataSet<Vertex> vertexDataSet = getExecutionEnvironment() .fromCollection(vertices); DataSet<Edge> edgeDataSet = getExecutionEnvironment() .fromCollection(edges); GraphCollectionLayout<GraphHead, Vertex, Edge> collectionLayout = getFactory() .fromDataSets(graphHeadDataSet, vertexDataSet, edgeDataSet); 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(graphHeads, loadedGraphHeads); validateEPGMElementCollections(vertices, loadedVertices); validateEPGMElementCollections(edges, loadedEdges); validateEPGMGraphElementCollections(vertices, loadedVertices); validateEPGMGraphElementCollections(edges, loadedEdges); }
.fromCollections( loader.getGraphHeads(), loader.getVertices(), loader.getEdges())); loader.getVertices(), newStore.getVertexSpace().readRemainsAndClose() ); validateEPGMGraphElementCollections( loader.getVertices(), newStore.getVertexSpace().readRemainsAndClose() );
/** * Check if the {@link LogicalGraphLayoutFactory#fromCollections(Collection, Collection)} * method returns the same graph as * {@link LogicalGraphLayoutFactory#fromDataSets(DataSet, DataSet)} using datasets * created from the same collections. * * @throws Exception on failure. */ @Test public void testFromCollectionsWithoutGraphHead() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); Collection<Vertex> vertices = loader.getVertices(); Collection<Edge> edges = loader.getEdges(); LogicalGraphLayout<GraphHead, Vertex, Edge> fromCollections = getFactory() .fromCollections(vertices, edges); DataSet<Vertex> vertexDataSet = getExecutionEnvironment().fromCollection(vertices); DataSet<Edge> edgeDataSet = getExecutionEnvironment().fromCollection(edges); LogicalGraphLayout<GraphHead, Vertex, Edge> fromDataSets = getFactory() .fromDataSets(vertexDataSet, edgeDataSet); LogicalGraph graphFromCollections = getConfig().getLogicalGraphFactory() .fromDataSets(fromCollections.getGraphHead(), fromCollections.getVertices(), fromCollections.getEdges()); LogicalGraph graphFromDataSets = getConfig().getLogicalGraphFactory() .fromDataSets(fromDataSets.getGraphHead(), fromDataSets.getVertices(), fromDataSets.getEdges()); collectAndAssertTrue(graphFromCollections.equalsByData(graphFromDataSets)); }