/** * 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 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)); }
/** * 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 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 SumProperty, SumVertexProperty and SumEdgeProperty with a graph collection * and unsupported property types. */ @Test public void testCollectionUnsupportedPropertyValueType() { FlinkAsciiGraphLoader loader = getLoaderFromString( "g[({p : 0})-[{p : 0.0}]->({p : true})-[{p : \"\"}]->({})]"); GraphCollection collection = loader.getGraphCollectionByVariables("g"); try { collection .apply(new ApplyAggregation(new SumVertexProperty(PROPERTY, VERTEX_AGGREGATE_PROPERTY))) .apply(new ApplyAggregation(new SumEdgeProperty(PROPERTY, EDGE_AGGREGATE_PROPERTY))) .apply(new ApplyAggregation(new SumProperty(PROPERTY, ELEMENT_AGGREGATE_PROPERTY))) .getGraphHeads().print(); } catch (Exception e) { assertTrue( e instanceof JobExecutionException && e.getCause() instanceof UnsupportedTypeException); } }
@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)); } }
.apply(new ApplyAggregation(new VertexCount()))
@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)); }
@Test public void testKeepOnlyRelevantVertices() throws Exception { FlinkAsciiGraphLoader loader = getLoaderFromString("source:G {source : \"graph\"}[" + " (a:Patent {author : \"asdf\", year: 2000, title: \"P1\"})-[:cite {difference : 0}]->(b:Patent {author : \"asdf\", year: 2000, title: \"P2\"})" + " (a)-[:cite {difference : 0}]->(c:Patent {author : \"asdf\", year: 2000, title: \"P3\"})" + " (b)-[:cite {difference : 0}]->(c)\n" + " (a)-[:cite {difference : 5}]->(d:Patent {author : \"zxcv\", year: 1995, title: \"Earlier...\"})" + " (b)-[:cite {difference : 5}]->(d)" + " (e:Patent {author : \"kdkdkd\", year: 1997, title: \"Once upon a time\"})-[e_d:cite {difference : 2}]->(d)" + "]"); GraphCollection sourceGraph = loader.getGraphCollectionByVariables("source"); // Caution: We can't use result.equalsByGraphElementIds because it internally uses a cross join // with equality of elements, which means, it ignores elements that are not within the other dataset // This means, the test would succeed even though we have too many vertices as a result of the // subgraph operator. org.junit.Assert.assertEquals(3, sourceGraph .apply(new ApplySubgraph(null, edge -> edge.getPropertyValue("difference").getInt() == 0)) .getVertices() .collect().size()); } }
.apply(new ApplySubgraph(vertexFilterFunction, null));
.apply(new ApplyTransformation( TransformationTest::transformGraphHead, TransformationTest::transformVertex,
@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"))); }