@Test(expected = NullPointerException.class) public void createWithNullIDTest() { GradoopId sourceId = GradoopId.get(); GradoopId targetId = GradoopId.get(); new EdgeFactory().initEdge(null, sourceId, targetId); }
protected DataSet<Edge> createEdgesWithProperties(List<String> propertyNames) { Properties properties = getProperties(propertyNames); EdgeFactory edgeFactory = new EdgeFactory(); List<Edge> edges = Lists.newArrayList( edgeFactory.createEdge("Label1", GradoopId.get(), GradoopId.get(), properties), edgeFactory.createEdge("Label2", GradoopId.get(), GradoopId.get(), properties) ); return getExecutionEnvironment().fromCollection(edges); }
@Override public Edge initEdge(final GradoopId id, final GradoopId sourceVertexId, final GradoopId targetVertexId) { return initEdge(id, GradoopConstants.DEFAULT_EDGE_LABEL, sourceVertexId, targetVertexId); }
@Override public void flatMap(Tuple2<Vertex, List<GradoopId>> value, Collector<Edge> out) { for (GradoopId sourceId : value.f1) { if (edgeDirection.equals(EdgeDirection.BIDIRECTIONAL) || edgeDirection.equals(EdgeDirection.NEWVERTEX_TO_ORIGIN)) { out.collect(edgeFactory.createEdge(edgeLabel, value.f0.getId(), sourceId)); } if (edgeDirection.equals(EdgeDirection.BIDIRECTIONAL) || edgeDirection.equals(EdgeDirection.ORIGIN_TO_NEWVERTEX)) { out.collect(edgeFactory.createEdge(edgeLabel, sourceId, value.f0.getId())); } } } }
@Override protected void initiate() { iterator = new GradoopEdgeIterator(); handler = new AccumuloEdgeHandler(new EdgeFactory()); }
/** * Extracts a {@link GraphCollection} from a set of {@link Element}. * * @param elements EPGM elements * @param config Gradoop Flink config * @param mayOverlap elements may be contained in multiple graphs * @return Graph collection */ @SuppressWarnings("unchecked") public static GraphCollection extractGraphCollection( DataSet<Element> elements, GradoopFlinkConfig config, boolean mayOverlap) { Class<GraphHead> graphHeadType = config.getGraphHeadFactory().getType(); Class<Vertex> vertexType = config.getVertexFactory().getType(); Class<Edge> edgeType = config.getEdgeFactory().getType(); return config.getGraphCollectionFactory().fromDataSets( extractGraphHeads(elements, graphHeadType), extractVertices(elements, vertexType, mayOverlap), extractEdges(elements, edgeType, mayOverlap) ); }
@Test public void testFilterEdgesByLabel() throws Exception { CNF predicates = predicateFromQuery("MATCH ()-[a:likes]->()"); EdgeFactory edgeFactory = new EdgeFactory(); Edge e1 = edgeFactory.createEdge("likes", GradoopId.get(), GradoopId.get()); Edge e2 = edgeFactory.createEdge("knows", GradoopId.get(), GradoopId.get()); DataSet<Edge> edges = getExecutionEnvironment().fromElements(e1, e2); List<Embedding> result = new FilterAndProjectEdges(edges, predicates, new ArrayList<>(), false) .evaluate() .collect(); assertEquals(1, result.size()); assertEquals(result.get(0).getId(1), e1.getId()); }
@Override public Edge initEdge(final GradoopId id, final String label, final GradoopId sourceVertexId, final GradoopId targetVertexId) { return initEdge(id, label, sourceVertexId, targetVertexId, null, null); }
/** * Creates a new EPGMEdge from the GDL Loader. * * @param e edge from GDL loader * @return EPGM edge */ private E initEdge(Edge e) { E edge; if (!edgeIds.containsKey(e.getId())) { edge = (E) config.getEdgeFactory().createEdge( e.getLabel(), vertexIds.get(e.getSourceVertexId()), vertexIds.get(e.getTargetVertexId()), Properties.createFromMap(e.getProperties()), createGradoopIdSet(e)); edgeIds.put(e.getId(), edge.getId()); edges.put(edge.getId(), edge); } else { edge = edges.get(edgeIds.get(e.getId())); edge.setGraphIds(createGradoopIdSet(e)); } return edge; }
/** * Creates a new Configuration. */ @SuppressWarnings("unchecked") protected GradoopConfig() { this.graphHeadFactory = new GraphHeadFactory(); this.vertexFactory = new VertexFactory(); this.edgeFactory = new EdgeFactory(); }
/** * Extracts a {@link GraphCollection} from a set of {@link Element}. * * @param elements EPGM elements * @param config Gradoop Flink config * @param mayOverlap elements may be contained in multiple graphs * @return Graph collection */ @SuppressWarnings("unchecked") public static GraphCollection extractGraphCollection( DataSet<Element> elements, GradoopFlinkConfig config, boolean mayOverlap) { Class<GraphHead> graphHeadType = config.getGraphHeadFactory().getType(); Class<Vertex> vertexType = config.getVertexFactory().getType(); Class<Edge> edgeType = config.getEdgeFactory().getType(); return config.getGraphCollectionFactory().fromDataSets( extractGraphHeads(elements, graphHeadType), extractVertices(elements, vertexType, mayOverlap), extractEdges(elements, edgeType, mayOverlap) ); }
@Test public void testEdgeSerialization() throws Exception { EPGMEdge edgeIn = new EdgeFactory().createEdge( "knows", GradoopId.get(), GradoopId.get(), Properties.createFromMap(GradoopTestUtils.SUPPORTED_PROPERTIES), GradoopIdSet.fromExisting(GradoopId.get(), GradoopId.get())); Assert.assertEquals("EPGMEdge POJOs were not equal", edgeIn, GradoopFlinkTestUtils.writeAndRead(edgeIn)); }
@Test(expected = NullPointerException.class) public void createWithNullSourceIdTest() { GradoopId edgeId = GradoopId.get(); GradoopId targetId = GradoopId.get(); new EdgeFactory().initEdge(edgeId, null, targetId); }
@Override public Edge initEdge(final GradoopId id, final String label, final GradoopId sourceVertexId, final GradoopId targetVertexId, GradoopIdSet graphs) { return initEdge(id, label, sourceVertexId, targetVertexId, null, graphs); }
/** * Creates an edge dataset from a given collection. * Encapsulates the workaround for dataset creation from an empty collection. * * @param edges edge collection * @return edge dataset */ protected DataSet<Edge> createEdgeDataSet(Collection<Edge> edges) { ExecutionEnvironment env = getConfig().getExecutionEnvironment(); DataSet<Edge> edgeSet; if (edges.isEmpty()) { GradoopId dummyId = GradoopId.get(); edgeSet = env .fromElements(getConfig().getEdgeFactory().createEdge(dummyId, dummyId)) .filter(new False<>()); } else { edgeSet = env.fromCollection(edges); } return edgeSet; } }
@Before public void setUp() throws Exception { this.vertexFactory = new VertexFactory(); this.edgeFactory = new EdgeFactory(); }
@Override public GraphCollection getGraphCollection() { GradoopFlinkConfig config = getFlinkConfig(); HBaseEPGMStore store = getStore(); DataSet<GraphHead> graphHeads = config.getExecutionEnvironment() .createInput(new GraphHeadTableInputFormat( getHBaseConfig().getGraphHeadHandler().applyQuery(graphHeadQuery), store.getGraphHeadName()), new TupleTypeInfo<>(TypeExtractor.createTypeInfo(config.getGraphHeadFactory().getType()))) .map(new ValueOf1<>()); DataSet<Vertex> vertices = config.getExecutionEnvironment() .createInput(new VertexTableInputFormat( getHBaseConfig().getVertexHandler().applyQuery(vertexQuery), store.getVertexTableName()), new TupleTypeInfo<>(TypeExtractor.createTypeInfo(config.getVertexFactory().getType()))) .map(new ValueOf1<>()); DataSet<Edge> edges = config.getExecutionEnvironment() .createInput(new EdgeTableInputFormat( getHBaseConfig().getEdgeHandler().applyQuery(edgeQuery), store.getEdgeTableName()), new TupleTypeInfo<>(TypeExtractor.createTypeInfo(config.getEdgeFactory().getType()))) .map(new ValueOf1<>()); return config.getGraphCollectionFactory().fromDataSets(graphHeads, vertices, edges); }
@Test public void testFilterWithNoPredicates() throws Exception { CNF predicates = predicateFromQuery("MATCH ()-[a]->()"); EdgeFactory edgeFactory = new EdgeFactory(); Properties properties = Properties.create(); properties.set("name", "Anton"); Edge e1 = edgeFactory.createEdge("knows", GradoopId.get(), GradoopId.get(), properties); DataSet<Edge> edges = getExecutionEnvironment().fromElements(e1); List<Embedding> result = new FilterAndProjectEdges(edges, predicates, new ArrayList<>(), false) .evaluate() .collect(); assertEquals(1, result.size()); assertEquals(result.get(0).getId(1), e1.getId()); }
@Test(expected = NullPointerException.class) public void createWithNullTargetIdTest() { GradoopId edgeId = GradoopId.get(); GradoopId sourceId = GradoopId.get(); new EdgeFactory().initEdge(edgeId, sourceId, null); }
@Override public Edge initEdge( GradoopId id, String label, GradoopId sourceVertexId, GradoopId targetVertexId, Properties properties) { return initEdge(id, label, sourceVertexId, targetVertexId, properties, null); }