@Override public Edge readRow(EPGMEdge origin) { return factory.initEdge( origin.getId(), origin.getLabel(), origin.getSourceId(), origin.getTargetId(), origin.getProperties(), origin.getGraphIds()); } }
@Override protected E initFrom(E edge) { return edgeFactory.initEdge( edge.getId(), GradoopConstants.DEFAULT_EDGE_LABEL, edge.getSourceId(), edge.getTargetId(), edge.getGraphIds()); } }
@Test public void createEdgePojoTest() { GradoopId edgeId = GradoopId.get(); GradoopId sourceId = GradoopId.get(); GradoopId targetId = GradoopId.get(); GradoopIdSet graphIds = GradoopIdSet .fromExisting(GradoopId.get(), GradoopId.get()); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMEdge edge = new EdgeFactory() .initEdge(edgeId, label, sourceId, targetId, props, graphIds); assertThat(edge.getId(), is(edgeId)); assertEquals(label, edge.getLabel()); assertThat(edge.getSourceId(), is(sourceId)); assertThat(edge.getTargetId(), is(targetId)); assertThat(edge.getPropertyCount(), is(2)); assertThat(edge.getPropertyValue("k1").getString(), Is.<Object>is("v1")); assertThat(edge.getPropertyValue("k2").getString(), Is.<Object>is("v2")); assertThat(edge.getGraphCount(), is(2)); for (GradoopId graphId : graphIds) { assertTrue(edge.getGraphIds().contains(graphId)); } }
@Override public Mutation writeRow( Mutation mutation, EPGMEdge record ) { mutation.put(AccumuloTables.KEY.LABEL, AccumuloTables.KEY.NONE, record.getLabel()); mutation.put(AccumuloTables.KEY.SOURCE, AccumuloTables.KEY.NONE, record.getSourceId().toString()); mutation.put(AccumuloTables.KEY.TARGET, AccumuloTables.KEY.NONE, record.getTargetId().toString()); //encode properties value bytes as base64 string Iterable<String> keys = record.getPropertyKeys(); if (keys != null) { keys.forEach(key -> mutation.put( /*cf*/AccumuloTables.KEY.PROPERTY, /*cq*/key, /*value*/new Value(record.getPropertyValue(key).getRawBytes()))); } //write graph ids GradoopIdSet ids = record.getGraphIds(); if (ids != null) { ids.forEach( id -> mutation.put(AccumuloTables.KEY.GRAPH, id.toString(), AccumuloTables.KEY.NONE)); } return mutation; }
private static void assertEqualEdges(EPGMEdge a, EPGMEdge b) { Assert.assertEquals(a.getSourceId(), b.getSourceId()); Assert.assertEquals(a.getTargetId(), b.getTargetId()); assertEqualGraphElements(a, b); }
@Test public void createWithIDTest() { GradoopId edgeId = GradoopId.get(); GradoopId sourceId = GradoopId.get(); GradoopId targetId = GradoopId.get(); EPGMEdge e = new EdgeFactory().initEdge(edgeId, sourceId, targetId); assertThat(e.getId(), is(edgeId)); assertThat(e.getSourceId(), is(sourceId)); assertThat(e.getTargetId(), is(targetId)); assertThat(e.getPropertyCount(), is(0)); assertThat(e.getGraphCount(), is(0)); }
@Override public Tuple2<GradoopId, GradoopId> map(E e) throws Exception { return new Tuple2<>(e.getTargetId(), e.getGraphIds().iterator().next()); } }
@Override public GradoopId map(E edge) throws Exception { return edge.getSourceId(); } }
@Override public GradoopId map(E edge) throws Exception { return edge.getTargetId(); } }
@Test public void testEdges() throws Exception { GradoopId edgeId = GradoopId.get(); GradoopId sourceId = GradoopId.get(); GradoopId targetId = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMEdge edge = new EdgeFactory().initEdge(edgeId, label, sourceId, targetId, props); HashMap<String, String> newProps = new HashMap<>(); newProps.put("k1", "new_k1"); TransformationFunction<EPGMEdge> renameFunction = new RenamePropertyKeys<>(newProps); renameFunction.apply(edge, edge); assertThat(edge.getPropertyCount(), is(2)); assertEquals(label, edge.getLabel()); assertThat(edge.getPropertyValue("new_k1").toString(), Is.<Object>is("v1")); assertThat(edge.getPropertyValue("k2").toString(), Is.<Object>is("v2")); assertNull(edge.getPropertyValue("k1")); }
/** * 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; }
@Test public void testEdge() { GradoopId edgeId = GradoopId.get(); GradoopId sourceId = GradoopId.get(); GradoopId targetId = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMEdge edge = new EdgeFactory().initEdge(edgeId, label, sourceId, targetId, props); String newLabel = "B"; TransformationFunction<EPGMEdge> renameFunction = new RenameLabel<>(label, newLabel); renameFunction.apply(edge, edge); assertEquals(newLabel, edge.getLabel()); assertThat(edge.getPropertyValue("k1").toString(), Is.<Object>is("v1")); assertThat(edge.getPropertyValue("k2").toString(), Is.<Object>is("v2")); }
@Override public void writeEdge(@Nonnull final EPGMEdge edgeData) throws IOException { // write to table EdgeHandler edgeHandler = config.getEdgeHandler(); // edge id Put put = new Put(edgeHandler.getRowKey(edgeData.getId())); // write edge data to Put put = edgeHandler.writeEdge(put, edgeData); edgeTable.put(put); if (autoFlush) { admin.flush(edgeTable.getName()); } }
/** * Returns all edges that belong to the given graphs. * * @param graphIds Graph identifiers * @return edges */ public Collection<E> getEdgesByGraphIds(GradoopIdSet graphIds) { Collection<E> result = Sets.newHashSetWithExpectedSize(graphIds.size()); for (E edge : edges.values()) { if (edge.getGraphIds().containsAny(graphIds)) { result.add(edge); } } return result; }
@Test public void createWithMissingLabelTest() { GradoopId edgeId = GradoopId.get(); GradoopId sourceId = GradoopId.get(); GradoopId targetId = GradoopId.get(); EPGMEdge e = new EdgeFactory().initEdge(edgeId, sourceId, targetId); assertThat(e.getLabel(), is(GradoopConstants.DEFAULT_EDGE_LABEL)); }
@Override protected E initFrom(E edge) { return edgeFactory.initEdge( edge.getId(), GradoopConstants.DEFAULT_EDGE_LABEL, edge.getSourceId(), edge.getTargetId(), edge.getGraphIds()); } }
@Override public Put writeEdge(Put put, EPGMEdge edgeData) { writeLabel(put, edgeData); writeSource(put, edgeData.getSourceId()); writeTarget(put, edgeData.getTargetId()); writeProperties(put, edgeData); writeGraphIds(put, edgeData); return put; }
@Override public Tuple2<GradoopId, GradoopId> map(E e) throws Exception { return new Tuple2<>(e.getTargetId(), e.getGraphIds().iterator().next()); } }
@Override public GradoopId map(E edge) throws Exception { return edge.getSourceId(); } }
@Override public GradoopId map(E edge) throws Exception { return edge.getTargetId(); } }