/** * The actual computation. * * @param socialNetwork social network graph * @return summarized, aggregated graph */ private static LogicalGraph execute(LogicalGraph socialNetwork) { return socialNetwork .subgraph( vertex -> vertex.getLabel().equals("Person"), edge -> edge.getLabel().equals("knows")) .groupBy(Arrays.asList("gender", "city")) .aggregate(new VertexCount(), new EdgeCount()); }
@Override public DataSet<Tuple3<String, Long, Long>> execute(LogicalGraph graph) { LogicalGraph graphWithWccIds = graph.callForGraph(new AnnotateWeaklyConnectedComponents( propertyKey, maxIterations, annotateEdges)); graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccVertices(propertyKey)); if (annotateEdges) { graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccEdges(propertyKey)); } return graphWithWccIds.getGraphHead().flatMap( new GetConnectedComponentDistributionFlatMap(propertyKey, annotateEdges)); }
@Override public DataSet<Tuple3<String, Long, Long>> execute(LogicalGraph graph) { LogicalGraph graphWithWccIds = graph.callForGraph(new AnnotateWeaklyConnectedComponents( propertyKey, maxIterations, annotateEdges)); graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccVertices(propertyKey)); if (annotateEdges) { graphWithWccIds = graphWithWccIds.aggregate(new AggregateListOfWccEdges(propertyKey)); } return graphWithWccIds.getGraphHead().flatMap( new GetConnectedComponentDistributionFlatMap(propertyKey, annotateEdges)); } }
/** * Test using multiple vertex aggregation functions in one call. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphWithMultipleVertexAggregationFunctions() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraph(); SumVertexProperty sumVertexProperty = new SumVertexProperty("age"); MaxVertexProperty maxVertexProperty = new MaxVertexProperty("age"); LogicalGraph expected = graph.aggregate(sumVertexProperty).aggregate(maxVertexProperty); LogicalGraph output = graph.aggregate(sumVertexProperty, maxVertexProperty); collectAndAssertTrue(expected.equalsByData(output)); }
/** * Test using multiple edge aggregation functions in one call. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphWithMultipleEdgeAggregationFunctions() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraph(); SumEdgeProperty sumEdgeProperty = new SumEdgeProperty("since"); MaxEdgeProperty maxEdgeProperty = new MaxEdgeProperty("since"); LogicalGraph expected = graph.aggregate(sumEdgeProperty).aggregate(maxEdgeProperty); LogicalGraph output = graph.aggregate(sumEdgeProperty, maxEdgeProperty); collectAndAssertTrue(expected.equalsByData(output)); }
/** * Test using multiple aggregation functions in one call on an empty graph. * * @throws Exception if the execution or IO fails. */ @Test public void testEmptySingleGraphWithMultipleAggregationFunctions() throws Exception { LogicalGraph graph = getLoaderFromString("g[]").getLogicalGraphByVariable("g"); VertexCount vertexCount = new VertexCount(); Count count = new Count(); MinEdgeProperty minEdgeProperty = new MinEdgeProperty(PROPERTY); LogicalGraph expected = graph.aggregate(vertexCount) .aggregate(minEdgeProperty) .aggregate(count); LogicalGraph output = graph.aggregate(vertexCount, minEdgeProperty, count); collectAndAssertTrue(expected.equalsByData(output)); } }
/** * Test using multiple element aggregation functions in one call. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphWithMultipleElementAggregationFunctions() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraph(); SumProperty sumProperty = new SumProperty("since"); MaxProperty maxProperty = new MaxProperty("since"); LogicalGraph expected = graph.aggregate(sumProperty).aggregate(maxProperty); LogicalGraph output = graph.aggregate(sumProperty, maxProperty); collectAndAssertTrue(expected.equalsByData(output)); }
/** * Test SumProperty, VertexSumProperty and EdgeSumProperty with unsupported property value types. */ @Test public void testGraphUnsupportedPropertyValueType() { FlinkAsciiGraphLoader loader = getLoaderFromString( "g[({p : 0})-[{p : 0.0}]->({p : true})-[{p : \"\"}]->({})]"); LogicalGraph graph = loader.getLogicalGraphByVariable("g"); try { graph .aggregate(new SumVertexProperty(PROPERTY, VERTEX_AGGREGATE_PROPERTY)) .aggregate(new SumEdgeProperty(PROPERTY, EDGE_AGGREGATE_PROPERTY)) .aggregate(new SumProperty(PROPERTY, ELEMENT_AGGREGATE_PROPERTY)) .getGraphHead().print(); } catch (Exception e) { assertTrue( e instanceof JobExecutionException && e.getCause() instanceof UnsupportedTypeException); } }
/** * {@inheritDoc} */ @Override public LogicalGraph execute(LogicalGraph graph) { DataSet<GraphHead> newGraphHead = graph .aggregate(new VertexCount(), new EdgeCount()) .getGraphHead() .map(new CalculateDensity(SamplingEvaluationConstants.PROPERTY_KEY_DENSITY)); return graph.getConfig().getLogicalGraphFactory() .fromDataSets(newGraphHead, graph.getVertices(), graph.getEdges()); }
@Override public LogicalGraph execute(LogicalGraph graph) { DataSet<GraphHead> newGraphHead = graph .aggregate(new VertexCount(), new EdgeCount()) .getGraphHead() .map(new CalculateDensity(SamplingEvaluationConstants.PROPERTY_KEY_DENSITY)); return graph.getConfig().getLogicalGraphFactory() .fromDataSets(newGraphHead, graph.getVertices(), graph.getEdges()); } }
@Override public LogicalGraph execute(LogicalGraph graph) { VertexCount vertexCountAggregate = new VertexCount(); SumVertexProperty localCCAggregate = new SumVertexProperty( ClusteringCoefficientBase.PROPERTY_KEY_LOCAL); graph = new GellyLocalClusteringCoefficientDirected().execute(graph) .aggregate(vertexCountAggregate, localCCAggregate); DataSet<GraphHead> graphHead = graph.getGraphHead().map(new AddAverageCCValueToGraphHeadMap( localCCAggregate.getAggregatePropertyKey(), vertexCountAggregate.getAggregatePropertyKey(), PROPERTY_KEY_AVERAGE)); return graph.getConfig().getLogicalGraphFactory().fromDataSets( graphHead, graph.getVertices(), graph.getEdges()); } }
@Override public LogicalGraph execute(LogicalGraph graph) { VertexCount vertexCountAggregate = new VertexCount(); SumVertexProperty localCCAggregate = new SumVertexProperty( ClusteringCoefficientBase.PROPERTY_KEY_LOCAL); graph = new GellyLocalClusteringCoefficientDirected().execute(graph) .aggregate(vertexCountAggregate, localCCAggregate); DataSet<GraphHead> graphHead = graph.getGraphHead().map(new AddAverageCCValueToGraphHeadMap( localCCAggregate.getAggregatePropertyKey(), vertexCountAggregate.getAggregatePropertyKey(), PROPERTY_KEY_AVERAGE)); return graph.getConfig().getLogicalGraphFactory().fromDataSets( graphHead, graph.getVertices(), graph.getEdges()); }
/** * Test HasEdgeLabel with a single graph and result true. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasEdgeLabelTrue() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasEdgeLabel hasKnows = new HasEdgeLabel("knows"); graph = graph.aggregate(hasKnows); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasEdgeLabel_knows not set", graphHead.hasProperty(hasKnows.getAggregatePropertyKey())); assertTrue("Property hasEdgeLabel_knows is false, should be true", graphHead.getPropertyValue(hasKnows.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasVertexLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasVertexLabelFalse() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasVertexLabel hasNotExistent = new HasVertexLabel("LabelDoesNotExist"); graph = graph.aggregate(hasNotExistent); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasVertexLabel_LabelDoesNotExist not set", graphHead.hasProperty(hasNotExistent.getAggregatePropertyKey())); assertFalse("Property hasVertexLabel_LabelDoesNotExist is true, should be false", graphHead.getPropertyValue(hasNotExistent.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasLabel with a single graph and empty label string. * * @throws Exception if the execution fails. */ @Test public void testSingleGraphHasElementLabelEmptyString() throws Exception { LogicalGraph graph = getLoaderFromString("g0[(v0)-[e0]->(v1)]") .getLogicalGraphByVariable("g0"); HasLabel hasLabel = new HasLabel(""); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_ not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertTrue("Property hasLabel_ is false, should be true", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasVertexLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasVertexLabelTrue() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasVertexLabel hasPerson = new HasVertexLabel("Person"); graph = graph.aggregate(hasPerson); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasVertexLabel_Person not set", graphHead.hasProperty(hasPerson.getAggregatePropertyKey())); assertTrue("Property hasVertexLabel_Person is false, should be true", graphHead.getPropertyValue(hasPerson.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasLabel with a single graph and result true. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasElementLabelTrue() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasLabel hasPerson = new HasLabel("Person"); graph = graph.aggregate(hasPerson); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_Person not set", graphHead.hasProperty(hasPerson.getAggregatePropertyKey())); assertTrue("Property hasLabel_Person is false, should be true", graphHead.getPropertyValue(hasPerson.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasElementLabelFalse() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasLabel hasNotExistent = new HasLabel("LabelDoesNotExist"); graph = graph.aggregate(hasNotExistent); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_LabelDoesNotExist not set", graphHead.hasProperty(hasNotExistent.getAggregatePropertyKey())); assertFalse("Property hasLabel_LabelDoesNotExist is true, should be false", graphHead.getPropertyValue(hasNotExistent.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasEdgeLabel with a single edgeless graph. * * @throws Exception if the execution fails. */ @Test public void testEdgelessGraphHasEdgeLabel() throws Exception { LogicalGraph graph = getLoaderFromString("g0[(v0)(v1)]") .getLogicalGraphByVariable("g0"); HasEdgeLabel hasLabel = new HasEdgeLabel("anyLabel"); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasEdgeLabel_anyLabel not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertNull("Property hasEdgeLabel_anyLabel is not NULL", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getObject()); }
/** * Test HasEdgeLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasEdgeLabelFalse() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasEdgeLabel hasNotExistent = new HasEdgeLabel("LabelDoesNotExist"); graph = graph.aggregate(hasNotExistent); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasEdgeLabel_LabelDoesNotExist not set", graphHead.hasProperty(hasNotExistent.getAggregatePropertyKey())); assertFalse("Property hasEdgeLabel_LabelDoesNotExist is true, should be false", graphHead.getPropertyValue(hasNotExistent.getAggregatePropertyKey()).getBoolean()); }