/** * 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 testGetGraphHead() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphHead inputGraphHead = loader.getGraphHeadByVariable("g0"); GraphHead outputGraphHead = loader.getLogicalGraphByVariable("g0") .getGraphHead().collect().get(0); assertEquals("GraphHeads were not equal", inputGraphHead, outputGraphHead); }
@Test public void testReduceCollection() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString("" + "g1[(a)-[e1]->(b)]" + "g2[(b)-[e2]->(c)]" + "g3[(c)-[e3]->(d)]" + "g4[(a)-[e4]->(b)]" + "exp12[(a)]" + "exp13[(a)-[e1]->(b)]" + "exp14[]"); checkExpectationsEqualResults(loader, new ReduceExclusion(loader .getGraphHeadByVariable("g1").getId())); } }
@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 getting a graph collection by variables from the loader * * @throws Exception on failure */ @Test public void testGetGraphCollectionByVariables() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); String[] graphVariables = new String[]{"g0", "g1", "g2"}; List<GradoopId> graphIds = Lists.newArrayList(); for (String graphVariable : graphVariables) { graphIds.add(loader.getGraphHeadByVariable(graphVariable).getId()); } GradoopIdSet graphIdSet = GradoopIdSet.fromExisting(graphIds); GraphCollection collectionFromLoader = loader.getGraphCollectionByVariables(graphVariables); GraphCollection collectionFromDbViaSet = loader.getGraphCollection().getGraphs(graphIdSet); // heads <> heads collectAndAssertTrue(collectionFromLoader.equalsByGraphIds(collectionFromDbViaSet)); // elements <> elements collectAndAssertTrue(collectionFromLoader.equalsByGraphElementIds(collectionFromDbViaSet)); } }
@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 getting a logical graph by variable from the loader * * @throws Exception on failure */ @Test public void testGetLogicalGraphByVariable() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); String graphVariable = "g1"; GradoopId graphId = loader.getGraphHeadByVariable(graphVariable).getId(); LogicalGraph graphFromLoader = loader.getLogicalGraphByVariable(graphVariable); LogicalGraph graphFromCollection = loader.getGraphCollection().getGraph(graphId); collectAndAssertTrue(graphFromLoader.equalsByElementData(graphFromCollection)); }
@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); }
.apply(new ApplyAggregation(count)); GradoopId g0Id = loader.getGraphHeadByVariable("g0").getId(); GradoopId g1Id = loader.getGraphHeadByVariable("g1").getId(); GradoopId g2Id = loader.getGraphHeadByVariable("g2").getId(); GradoopId g3Id = loader.getGraphHeadByVariable("g3").getId();
.apply(new ApplyAggregation(sumProperty)); GradoopId g0Id = loader.getGraphHeadByVariable("g0").getId(); GradoopId g1Id = loader.getGraphHeadByVariable("g1").getId(); GradoopId g2Id = loader.getGraphHeadByVariable("g2").getId();
.apply(new ApplyAggregation(sumProperty)); GradoopId g0Id = loader.getGraphHeadByVariable("g0").getId(); GradoopId g1Id = loader.getGraphHeadByVariable("g1").getId(); GradoopId g2Id = loader.getGraphHeadByVariable("g2").getId();
.apply(new ApplyAggregation(minProperty)); GradoopId g0Id = loader.getGraphHeadByVariable("g0").getId(); GradoopId g1Id = loader.getGraphHeadByVariable("g1").getId(); GradoopId g2Id = loader.getGraphHeadByVariable("g2").getId();
.apply(new ApplyAggregation(maxProperty)); GradoopId g0Id = loader.getGraphHeadByVariable("g0").getId(); GradoopId g1Id = loader.getGraphHeadByVariable("g1").getId(); GradoopId g2Id = loader.getGraphHeadByVariable("g2").getId();