@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())))); }
@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 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 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")); }
@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)); } }
@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")); }