@Override public boolean filter(Edge edge) { PropertyValue value = edge.getPropertyValue("count"); return value.getLong() > 500; } }
@Override public Edge join(Edge edge, Vertex vertex) throws Exception { PropertyValue newEdgeValue = vertex.getPropertyValue(propertyKey); if (edge.hasProperty(propertyKey)) { if (edge.getPropertyValue(propertyKey).compareTo(newEdgeValue) < 0) { return edge; } } edge.setProperty(propertyKey, newEdgeValue); return edge; } }
@Override public Edge join(Edge edge, Vertex vertex) throws Exception { PropertyValue newEdgeValue = vertex.getPropertyValue(propertyKey); if (edge.hasProperty(propertyKey)) { if (edge.getPropertyValue(propertyKey).compareTo(newEdgeValue) < 0) { return edge; } } edge.setProperty(propertyKey, newEdgeValue); return edge; } }
@Override public org.apache.flink.graph.Edge<GradoopId, PropertyValue> map(Edge epgmEdge) { reuseEdge.setSource(epgmEdge.getSourceId()); reuseEdge.setTarget(epgmEdge.getTargetId()); reuseEdge.setValue(epgmEdge.getPropertyValue(propertyKey)); return reuseEdge; } }
@Override public org.apache.flink.graph.Edge<GradoopId, PropertyValue> map(Edge epgmEdge) { reuseEdge.setSource(epgmEdge.getSourceId()); reuseEdge.setTarget(epgmEdge.getTargetId()); reuseEdge.setValue(epgmEdge.getPropertyValue(propertyKey)); return reuseEdge; } }
.filter(e -> e.getPropertyValue(PROP_STATUS).getString().matches(PATTERN_EDGE_PROP.pattern())) .collect(Collectors.toList());
.filter(e -> e.getPropertyValue(PROP_STATUS).getString().matches(PATTERN_EDGE_PROP.pattern())) .collect(Collectors.toList());
@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()); } }
.stream() .filter(e -> e.hasProperty(PROP_SINCE)) .filter(e -> e.getPropertyValue(PROP_SINCE).equals(propertyValueSince)) .collect(Collectors.toList());
.filter(e -> e.getPropertyValue(PROP_SINCE).compareTo(propertyValueSince) > 0) .collect(Collectors.toList());
.stream() .filter(e -> e.getLabel().matches(PATTERN_EDGE.pattern()) || (e.hasProperty(PROP_SINCE) && e.getPropertyValue(PROP_SINCE).getInt() < 2015)) .collect(Collectors.toList());
@Override public Edge<GradoopId, Double> map(org.gradoop.common.model.impl.pojo.Edge epgmEdge) throws Exception { reuseEdge.setSource(epgmEdge.getSourceId()); reuseEdge.setTarget(epgmEdge.getTargetId()); //cast incoming numeric value to double PropertyValue value = epgmEdge.getPropertyValue(propertyKey); if (value.isDouble()) { reuseEdge.setValue(value.getDouble()); } else if (value.isFloat()) { reuseEdge.setValue((double) value.getFloat()); } else if (value.isInt()) { reuseEdge.setValue((double) value.getInt()); } else if (value.isLong()) { reuseEdge.setValue((double) value.getLong()); } return reuseEdge; } }
@Override public Edge<GradoopId, Double> map(org.gradoop.common.model.impl.pojo.Edge epgmEdge) throws Exception { reuseEdge.setSource(epgmEdge.getSourceId()); reuseEdge.setTarget(epgmEdge.getTargetId()); //cast incoming numeric value to double PropertyValue value = epgmEdge.getPropertyValue(propertyKey); if (value.isDouble()) { reuseEdge.setValue(value.getDouble()); } else if (value.isFloat()) { reuseEdge.setValue((double) value.getFloat()); } else if (value.isInt()) { reuseEdge.setValue((double) value.getInt()); } else if (value.isLong()) { reuseEdge.setValue((double) value.getLong()); } return reuseEdge; } }
.stream() .filter(e -> e.hasProperty(PROP_SINCE)) .filter(e -> e.getPropertyValue(PROP_SINCE).equals(propertyValueSince)) .collect(Collectors.toList());
.filter(e -> e.getPropertyValue(PROP_SINCE).compareTo(propertyValueSince) > 0) .collect(Collectors.toList());
.stream() .filter(e -> e.getLabel().matches(PATTERN_EDGE.pattern()) || (e.hasProperty(PROP_SINCE) && e.getPropertyValue(PROP_SINCE).getInt() < 2015)) .collect(Collectors.toList());
if (e.getPropertyValue("since").getInt() == 2016) { return true;
@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"))); }
LogicalGraph searchGraph = sourceGraph.reduce(new ReduceCombination()); GraphCollection patternGraph = sourceGraph .apply(new ApplySubgraph(null, edge -> edge.getPropertyValue("difference").getInt() == 0)) .apply(new ApplyTransformation((gh, plain) -> { gh.setLabel("Combined");