@Override public GradoopId map(E edge) throws Exception { return edge.getSourceId(); } }
@Override public GradoopId map(E edge) throws Exception { return edge.getSourceId(); } }
@Override public GradoopId getKey(E edge) throws Exception { return edge.getSourceId(); }
@Override public GradoopId getKey(E edge) throws Exception { return edge.getSourceId(); }
@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()); } }
private static void assertEqualEdges(EPGMEdge a, EPGMEdge b) { Assert.assertEquals(a.getSourceId(), b.getSourceId()); Assert.assertEquals(a.getTargetId(), b.getTargetId()); assertEqualGraphElements(a, b); }
@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; }
@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())))); }
@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 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; }
@SuppressWarnings("Duplicates") private void validateEdge(HBaseEPGMStore graphStore, Edge originalEdge) throws IOException { EPGMEdge loadedEdge = graphStore.readEdge(originalEdge.getId()); validateEPGMElements(originalEdge, loadedEdge); validateEPGMGraphElements(originalEdge, loadedEdge); assert loadedEdge != null; assertEquals("source vertex mismatch", originalEdge.getSourceId(), loadedEdge.getSourceId()); assertEquals("target vertex mismatch", originalEdge.getTargetId(), loadedEdge.getTargetId()); }
@SuppressWarnings("Duplicates") private void validateEdge( AccumuloEPGMStore graphStore, Edge originalEdge ) throws IOException { EPGMEdge loadedEdge = graphStore.readEdge(originalEdge.getId()); validateEPGMElements(originalEdge, loadedEdge); validateEPGMGraphElements(originalEdge, loadedEdge); assert loadedEdge != null; assertEquals("source vertex mismatch", originalEdge.getSourceId(), loadedEdge.getSourceId()); assertEquals("target vertex mismatch", originalEdge.getTargetId(), loadedEdge.getTargetId()); }
@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)); } }