/** * 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; }
@Override public Tuple2<GradoopId, GradoopId> map(E e) throws Exception { return new Tuple2<>(e.getTargetId(), e.getGraphIds().iterator().next()); } }
@Override public Tuple2<GradoopId, GradoopId> map(E e) throws Exception { return new Tuple2<>(e.getTargetId(), e.getGraphIds().iterator().next()); } }
@Override protected E initFrom(E edge) { return edgeFactory.initEdge( edge.getId(), GradoopConstants.DEFAULT_EDGE_LABEL, edge.getSourceId(), edge.getTargetId(), edge.getGraphIds()); } }
@Override protected E initFrom(E edge) { return edgeFactory.initEdge( edge.getId(), GradoopConstants.DEFAULT_EDGE_LABEL, edge.getSourceId(), edge.getTargetId(), edge.getGraphIds()); } }
@Override public Edge readRow(EPGMEdge origin) { return factory.initEdge( origin.getId(), origin.getLabel(), origin.getSourceId(), origin.getTargetId(), origin.getProperties(), origin.getGraphIds()); } }
@Nonnull @Override public Pair<Key, Value> toRow(@Nonnull EPGMEdge record) throws IOException { //write to content return new Pair<>(new Key(record.getId().toString()), new Value(KryoUtils.dumps(factory.initEdge( record.getId(), record.getLabel(), record.getSourceId(), record.getTargetId(), record.getProperties(), record.getGraphIds())))); }
@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; }
@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)); } }