@Override public GraphHead readRow(EPGMGraphHead origin) { return factory.initGraphHead( /*edge id*/origin.getId(), /*label*/origin.getLabel(), /*properties*/origin.getProperties()); }
@Override public Mutation writeRow( Mutation mutation, EPGMGraphHead record ) { mutation.put(AccumuloTables.KEY.LABEL, AccumuloTables.KEY.NONE, record.getLabel()); 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()))); } return mutation; }
@Nonnull @Override public Pair<Key, Value> toRow(@Nonnull EPGMGraphHead record) throws IOException { //write to content return new Pair<>(new Key(record.getId().toString()), new Value(KryoUtils.dumps(factory.initGraphHead( record.getId(), record.getLabel(), record.getProperties())))); }
@Test public void createWithMissingLabelTest() { GradoopId graphID = GradoopId.get(); EPGMGraphHead g = new GraphHeadFactory().initGraphHead(graphID); assertThat(g.getLabel(), is(GradoopConstants.DEFAULT_GRAPH_LABEL)); }
@Test public void createDefaultGraphTest() { GradoopId graphID = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMGraphHead graphHead = new GraphHeadFactory().initGraphHead(graphID, label, props); assertThat(graphHead.getId(), is(graphID)); assertEquals(label, graphHead.getLabel()); assertThat(graphHead.getPropertyCount(), is(2)); assertThat(graphHead.getPropertyValue("k1").getString(), Is.<Object>is("v1")); assertThat(graphHead.getPropertyValue("k2").getString(), Is.<Object>is("v2")); }
@Test public void testGraphHead() throws Exception { GradoopId graphID = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMGraphHead graphHead = new GraphHeadFactory().initGraphHead(graphID, label, props); HashMap<String, String> newProps = new HashMap<>(); newProps.put("k1", "new_k1"); TransformationFunction<EPGMGraphHead> renameFunction = new RenamePropertyKeys<>(newProps); renameFunction.apply(graphHead, graphHead); assertThat(graphHead.getPropertyCount(), is(2)); assertEquals(label, graphHead.getLabel()); assertThat(graphHead.getPropertyValue("new_k1").toString(), Is.<Object>is("v1")); assertThat(graphHead.getPropertyValue("k2").toString(), Is.<Object>is("v2")); assertNull(graphHead.getPropertyValue("k1")); }
@Test public void testGraphHead() { GradoopId graphId = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMGraphHead graphHead = new GraphHeadFactory().initGraphHead(graphId, label, props); String newLabel = "B"; TransformationFunction<EPGMGraphHead> renameFunction = new RenameLabel<>(label, newLabel); renameFunction.apply(graphHead, graphHead); assertEquals(newLabel, graphHead.getLabel()); assertThat(graphHead.getPropertyValue("k1").toString(), Is.<Object>is("v1")); assertThat(graphHead.getPropertyValue("k2").toString(), Is.<Object>is("v2")); }