/** * Test writing an indexed csv graph collection. * * @throws Exception if the execution or IO fails. */ @Test public void testWrite() throws Exception { String tmpPath = temporaryFolder.getRoot().getPath(); GraphCollection input = getSocialNetworkLoader().getGraphCollection(); checkIndexedCSVWrite(tmpPath, input); }
/** * Test getting a graph collection from the loader * * @throws Exception on failure */ @Test public void testGetGraphCollection() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection collectionFromLoader = loader.getGraphCollectionByVariables("g0", "g1", "g2", "g3"); GraphCollection collectionFromDb = loader.getGraphCollection(); // heads <> heads collectAndAssertTrue(collectionFromLoader.equalsByGraphIds(collectionFromDb)); // elements <> elements collectAndAssertTrue(collectionFromLoader.equalsByGraphElementIds(collectionFromDb)); }
/** * Executes a rollUp on edges using a single grouping key and checks if the result * is correct. * * @throws Exception If the execution fails. */ @Test public void testEdgeRollUpWithSingleGroupingKey() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); LogicalGraph input = loader.getGraphCollectionByVariables("g0", "g1", "g2", "g3") .reduce(new ReduceCombination()); //expected loader.initDatabaseFromString("g0 {edgeRollUpGroupingKeys:\":label\"}[" + "(v0)" + "(v0)-[e_0:knows{count:10L}]->(v0)" + "(v0)-[e_1:hasModerator{count:1L}]->(v0)" + "(v0)-[e_2:hasMember{count:2L}]->(v0)" + "]"); GraphCollection expected = loader.getGraphCollection(); List<String> vertexGK = Collections.emptyList(); List<AggregateFunction> vertexAGG = Collections.emptyList(); List<String> edgeGK = Collections.singletonList(Grouping.LABEL_SYMBOL); List<AggregateFunction> edgeAGG = Collections.singletonList(new Count("count")); GraphCollection output = input.groupEdgesByRollUp(vertexGK, vertexAGG, edgeGK, edgeAGG); collectAndAssertTrue(output.equalsByGraphData(expected)); }
@Test public void testWrite() throws Exception { String tmpPath = temporaryFolder.getRoot().getPath(); GraphCollection graphCollection = getSocialNetworkLoader().getGraphCollection(); checkCSVWrite(tmpPath, graphCollection); }
"(v1)-[e7]->(v3)" + "]"); GraphCollection expected = loader.getGraphCollection();
/** * 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 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 testDirected() throws Exception { FlinkAsciiGraphLoader loader = new FlinkAsciiGraphLoader(getConfig()); loader.initDatabaseFromFile(getFilePath("/data/gdl/cam_test.gdl")); GraphCollection g = loader.getGraphCollection(); CanonicalAdjacencyMatrixBuilder cam = new CanonicalAdjacencyMatrixBuilder( new GraphHeadToDataString(), new VertexToDataString(), new EdgeToDataString(), true); String result = cam.execute(g).collect().get(0); String expectation = FileUtils.readFileToString( FileUtils.getFile(getFilePath("/data/expected/cam_test_directed"))); assertEquals(expectation, result); }
"(v1)-[e_12:knows{count:10L}]->(v1)" + "]"); GraphCollection expected = loader.getGraphCollection();
@Test public void testWrite() throws Exception { String tmpDir = temporaryFolder.getRoot().toString(); final String vertexFile = tmpDir + "/nodes.json"; final String edgeFile = tmpDir + "/edges.json"; final String graphFile = tmpDir + "/graphs.json"; GraphCollection input = getSocialNetworkLoader().getGraphCollection(); // write to JSON input.writeTo(new JSONDataSink(graphFile, vertexFile, edgeFile, getConfig())); getExecutionEnvironment().execute(); // read from JSON GraphCollection output = new JSONDataSource( graphFile, vertexFile, edgeFile, getConfig()).getGraphCollection(); collectAndAssertTrue(output.equalsByGraphElementData(input)); } }
"(v16)-[e29]->(v15)" + "]"); GraphCollection expected = loader.getGraphCollection();
@Test public void testUndirected() throws Exception { FlinkAsciiGraphLoader loader = new FlinkAsciiGraphLoader(getConfig()); loader.initDatabaseFromFile(getFilePath("/data/gdl/cam_test.gdl")); GraphCollection g = loader.getGraphCollection(); CanonicalAdjacencyMatrixBuilder cam = new CanonicalAdjacencyMatrixBuilder( new GraphHeadToDataString(), new VertexToDataString(), new EdgeToDataString(), false); String result = cam.execute(g).collect().get(0); String expectation = FileUtils.readFileToString( FileUtils.getFile(getFilePath("/data/expected/cam_test_undirected"))); assertEquals(expectation, result); } }
@Test public void testTransformation() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection originalCollection = loader.getGraphCollection(); DataSet<GraphTransaction> transactions = originalCollection.getGraphTransactions(); GraphCollection restoredCollection = getConfig().getGraphCollectionFactory() .fromTransactions(transactions); collectAndAssertTrue( originalCollection.equalsByGraphIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphElementIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphData(restoredCollection)); }
@Test public void testTransformationWithCustomReducer() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection originalCollection = loader.getGraphCollection(); DataSet<GraphTransaction> transactions = originalCollection.getGraphTransactions(); GraphCollection restoredCollection = getConfig().getGraphCollectionFactory() .fromTransactions(transactions, new First<>(), new First<>()); collectAndAssertTrue( originalCollection.equalsByGraphIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphElementIds(restoredCollection)); collectAndAssertTrue( originalCollection.equalsByGraphData(restoredCollection)); }