/** * 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)); }
collectAndAssertTrue(output.equalsByGraphData(expected));
@Test public void testVertexOnlyTransformation() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString(testGraphString); GraphCollection inputCollection = loader .getGraphCollectionByVariables("g0", "g1"); GraphCollection expectedCollection = loader .getGraphCollectionByVariables("g03", "g13"); GraphCollection outputCollection = inputCollection .apply(new ApplyTransformation(null, TransformationTest::transformVertex, null)); collectAndAssertTrue( outputCollection.equalsByGraphData(expectedCollection)); }
@Test public void testGraphHeadOnlyTransformation() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString(testGraphString); GraphCollection inputCollection = loader.getGraphCollectionByVariables("g0", "g1"); GraphCollection expectedCollection = loader.getGraphCollectionByVariables("g02", "g12"); GraphCollection outputCollection = inputCollection .apply(new ApplyTransformation(TransformationTest::transformGraphHead, null, null)); collectAndAssertTrue( outputCollection.equalsByGraphData(expectedCollection)); }
@Test public void testEdgeOnlyTransformation() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString(testGraphString); GraphCollection inputCollection = loader .getGraphCollectionByVariables("g0", "g1"); GraphCollection expectedCollection = loader .getGraphCollectionByVariables("g04", "g14"); GraphCollection outputCollection = inputCollection.apply( new ApplyTransformation(null, null, TransformationTest::transformEdge)); collectAndAssertTrue( outputCollection.equalsByGraphData(expectedCollection)); } }
@Test public void testDataEquality() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString(testGraphString); GraphCollection inputCollection = loader .getGraphCollectionByVariables("g0", "g1"); GraphCollection expectedCollection = loader .getGraphCollectionByVariables("g01", "g11"); GraphCollection outputCollection = inputCollection .apply(new ApplyTransformation( TransformationTest::transformGraphHead, TransformationTest::transformVertex, TransformationTest::transformEdge)); collectAndAssertTrue( outputCollection.equalsByGraphData(expectedCollection)); }
collectAndAssertTrue(gRef.equalsByGraphData(gDiffId)); collectAndAssertFalse(gRef.equalsByGraphData(gClone)); collectAndAssertFalse(gRef.equalsByGraphData(gDiffData)); collectAndAssertFalse(gRef.equalsByGraphData(gSmall)); collectAndAssertFalse(gRef.equalsByGraphData(gEmpty));
@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 using multiple edge aggregation functions on a graph collection * * @throws Exception if the execution or IO fails. */ @Test public void testCollectionWithMultipleEdgeAggregationFunctions() throws Exception { GraphCollection collection = getSocialNetworkLoader() .getGraphCollectionByVariables("g0", "g1", "g2", "g3"); SumEdgeProperty sumEdgeProperty = new SumEdgeProperty("since"); MaxEdgeProperty maxEdgeProperty = new MaxEdgeProperty("since"); GraphCollection expected = collection.apply(new ApplyAggregation(sumEdgeProperty)) .apply(new ApplyAggregation(maxEdgeProperty)); GraphCollection output = collection.apply(new ApplyAggregation(sumEdgeProperty, maxEdgeProperty)); collectAndAssertTrue(expected.equalsByGraphData(output)); }
/** * Test using multiple element aggregation functions on a graph collection * * @throws Exception if the execution or IO fails. */ @Test public void testCollectionWithMultipleElementAggregationFunctions() throws Exception { GraphCollection collection = getSocialNetworkLoader() .getGraphCollectionByVariables("g0", "g1", "g2", "g3"); SumProperty sumProperty = new SumProperty("since"); MaxProperty maxProperty = new MaxProperty("since"); GraphCollection expected = collection.apply(new ApplyAggregation(sumProperty)) .apply(new ApplyAggregation(maxProperty)); GraphCollection output = collection.apply(new ApplyAggregation(sumProperty, maxProperty)); collectAndAssertTrue(expected.equalsByGraphData(output)); }
@Test public void testRead() throws Exception { String tlfFile = getFilePath("/data/tlf/io_test_string.tlf"); // create datasource DataSource dataSource = new TLFDataSource(tlfFile, getConfig()); // get transactions DataSet<GraphTransaction> transactions = dataSource.getGraphCollection().getGraphTransactions(); String asciiGraphs = "" + "g1[(v1:A)-[:a]->(v2:B)-[:b]->(v1)]" + "g2[(v1:A)-[:a]->(v2:B)<-[:b]-(v1)]"; FlinkAsciiGraphLoader loader = getLoaderFromString(asciiGraphs); collectAndAssertTrue( loader.getGraphCollectionByVariables("g1", "g2").equalsByGraphData( getConfig().getGraphCollectionFactory().fromTransactions(transactions) ) ); }
/** * Test using multiple vertex aggregation functions on a graph collection * * @throws Exception if the execution or IO fails. */ @Test public void testCollectionWithMultipleVertexAggregationFunctions() throws Exception { GraphCollection collection = getSocialNetworkLoader() .getGraphCollectionByVariables("g0", "g1", "g2", "g3"); SumVertexProperty sumVertexProperty = new SumVertexProperty("age"); MaxVertexProperty maxVertexProperty = new MaxVertexProperty("age"); GraphCollection expected = collection.apply(new ApplyAggregation(sumVertexProperty)) .apply(new ApplyAggregation(maxVertexProperty)); GraphCollection output = collection.apply(new ApplyAggregation(sumVertexProperty, maxVertexProperty)); collectAndAssertTrue(expected.equalsByGraphData(output)); }
@Test public void testReadWithoutEdges() throws Exception { String tlfFile = getFilePath("/data/tlf/io_test_string_without_edges.tlf"); // create datasource DataSource dataSource = new TLFDataSource(tlfFile, getConfig()); // get transactions DataSet<GraphTransaction> transactions = dataSource.getGraphCollection().getGraphTransactions(); String asciiGraphs = "" + "g1[(v1:A),(v2:B)]" + "g2[(v1:A),(v2:B)]"; FlinkAsciiGraphLoader loader = getLoaderFromString(asciiGraphs); collectAndAssertTrue( loader.getGraphCollectionByVariables("g1", "g2").equalsByGraphData( getConfig().getGraphCollectionFactory().fromTransactions(transactions) ) ); }
@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)); }
@Test public void testWithSubsetGraphContainment() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); loader.appendToDatabaseFromString("g1[(eve)]"); GraphCollection originalCollection = loader.getGraphCollectionByVariables("g1"); 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)); } }
loader.getGraphCollectionByVariables( "expected0", "expected1", "expected4"))); collectAndAssertTrue(result.equalsByGraphData( loader.getGraphCollectionByVariables( "expected0", "expected1", "expected4")));
@Test public void testReadWithDictionary() throws Exception { String tlfFile = getFilePath("/data/tlf/io_test.tlf"); String tlfVertexDictionaryFile = getFilePath("/data/tlf/io_test_vertex_dictionary.tlf"); String tlfEdgeDictionaryFile = getFilePath("/data/tlf/io_test_edge_dictionary.tlf"); // create datasource DataSource dataSource = new TLFDataSource(tlfFile, tlfVertexDictionaryFile, tlfEdgeDictionaryFile, getConfig()); // get transactions DataSet<GraphTransaction> transactions = dataSource.getGraphCollection().getGraphTransactions(); String asciiGraphs = "" + "g1[(v1:A)-[:a]->(v2:B)-[:b]->(v1)]" + "g2[(v1:A)-[:a]->(v2:B)<-[:b]-(v1)]"; FlinkAsciiGraphLoader loader = getLoaderFromString(asciiGraphs); collectAndAssertTrue( loader.getGraphCollectionByVariables("g1", "g2").equalsByGraphData( getConfig().getGraphCollectionFactory().fromTransactions(transactions) ) ); } }
@Test public void testCollectionEdgeInducedSubgraph() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); loader.appendToDatabaseFromString( "expected0[" + "(eve)-[ekb]->(bob)" + "]" ); loader.appendToDatabaseFromString( "expected1[" + "(frank)-[fkc]->(carol)" + "(frank)-[fkd]->(dave)" + "]" ); loader.appendToDatabaseFromString( "expected2[]" ); GraphCollection input = loader.getGraphCollectionByVariables("g0", "g1", "g2"); GraphCollection result = input .apply(new ApplySubgraph(null, e -> e.getPropertyValue("since").getInt() == 2015)); collectAndAssertTrue(result.equalsByGraphElementIds( loader.getGraphCollectionByVariables( "expected0", "expected1", "expected2"))); collectAndAssertTrue(result.equalsByGraphData( loader.getGraphCollectionByVariables( "expected0", "expected1", "expected2"))); }
/** * Test using multiple aggregation functions on an empty graph collection * * @throws Exception if the execution or IO fails. */ @Test public void testEmptyCollectionWithMultipleAggregationFunctions() throws Exception { FlinkAsciiGraphLoader loader = getSocialNetworkLoader(); GraphCollection collection = loader.getGraphCollectionByVariables("g0") .difference(loader.getGraphCollectionByVariables("g1")); VertexCount vertexCount = new VertexCount(); EdgeCount edgeCount = new EdgeCount(); Count count = new Count(); GraphCollection expected = collection .apply(new ApplyAggregation(vertexCount)) .apply(new ApplyAggregation(edgeCount)) .apply(new ApplyAggregation(count)); GraphCollection output = collection.apply(new ApplyAggregation(vertexCount, edgeCount, count)); collectAndAssertTrue(expected.equalsByGraphData(output)); } }
/** * Test using multiple vertex and edge aggregation functions on a graph collection * * @throws Exception if the execution or IO fails. */ @Test public void testCollectionWithMultipleDifferentAggregationFunctions() throws Exception { GraphCollection collection = getSocialNetworkLoader() .getGraphCollectionByVariables("g0", "g1", "g2", "g3"); VertexCount vertexCount = new VertexCount(); EdgeCount edgeCount = new EdgeCount(); Count count = new Count(); MaxEdgeProperty maxEdgeProperty = new MaxEdgeProperty("since"); GraphCollection expected = collection .apply(new ApplyAggregation(vertexCount)) .apply(new ApplyAggregation(edgeCount)) .apply(new ApplyAggregation(count)) .apply(new ApplyAggregation(maxEdgeProperty)); GraphCollection output = collection.apply(new ApplyAggregation(vertexCount, edgeCount, count, maxEdgeProperty)); collectAndAssertTrue(expected.equalsByGraphData(output)); }