@Override public Vertex readRow(EPGMVertex origin) { return factory.initVertex( origin.getId(), origin.getLabel(), origin.getProperties(), origin.getGraphIds() ); }
@Override public boolean filter(V v) throws Exception { return v.getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY) .getString().equals( BusinessTransactionGraphs.SUPERCLASS_VALUE_TRANSACTIONAL); } }
@Override public V join(V element, Tuple2<GradoopId, GradoopIdSet> mapping) throws Exception { element.setGraphIds(mapping.f1); return element; } }
@Override protected V initFrom(V element) { return vertexFactory.initVertex( element.getId(), GradoopConstants.DEFAULT_VERTEX_LABEL, element.getGraphIds()); } }
@Test public void createVertexPojoTest() { GradoopId vertexID = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); GradoopId graphId1 = GradoopId.get(); GradoopId graphId2 = GradoopId.get(); GradoopIdSet graphIds = new GradoopIdSet(); graphIds.add(graphId1); graphIds.add(graphId2); EPGMVertex vertex = new VertexFactory() .initVertex(vertexID, label, props, graphIds); assertThat(vertex.getId(), is(vertexID)); assertEquals(label, vertex.getLabel()); assertThat(vertex.getPropertyCount(), is(2)); assertThat(vertex.getPropertyValue("k1").getString(), Is.<Object>is("v1")); assertThat(vertex.getPropertyValue("k2").getString(), Is.<Object>is("v2")); assertThat(vertex.getGraphCount(), is(2)); assertTrue(vertex.getGraphIds().contains(graphId1)); assertTrue(vertex.getGraphIds().contains(graphId2)); }
@Override public Mutation writeRow( Mutation mutation, EPGMVertex record ) { mutation.put(AccumuloTables.KEY.LABEL, AccumuloTables.KEY.NONE, record.getLabel()); //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 testVertex() throws Exception { GradoopId vertexId = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMVertex vertex = new VertexFactory().initVertex(vertexId, label, props); HashMap<String, String> newProps = new HashMap<>(); newProps.put("k1", "new_k1"); TransformationFunction<EPGMVertex> renameFunction = new RenamePropertyKeys<>(newProps); renameFunction.apply(vertex, vertex); assertThat(vertex.getPropertyCount(), is(2)); assertEquals(label, vertex.getLabel()); assertThat(vertex.getPropertyValue("new_k1").toString(), Is.<Object>is("v1")); assertThat(vertex.getPropertyValue("k2").toString(), Is.<Object>is("v2")); assertNull(vertex.getPropertyValue("k1")); } }
/** * Check if two vertices are equal. * Elements should be considered equal here if their properties and label are equal. * * @param expected The expectedValue vertex value. * @param actual The actual vertex value. */ private void assertVertexEquals(EPGMVertex expected, EPGMVertex actual) { assertNotNull(expected); assertNotNull(actual); assertEquals(expected.getLabel(), actual.getLabel()); assertEquals(expected.getPropertyCount(), actual.getPropertyCount()); if (expected.getPropertyCount() > 0) { assertEquals(expected.getProperties(), actual.getProperties()); } } }
@Test public void createWithIDTest() { GradoopId vertexID = GradoopId.get(); EPGMVertex v = new VertexFactory().initVertex(vertexID); assertThat(v.getId(), is(vertexID)); assertThat(v.getPropertyCount(), is(0)); assertThat(v.getGraphCount(), is(0)); }
/** * Creates a new EPGMVertex from the GDL Loader or updates an existing one. * * @param v vertex from GDL Loader * @return EPGM vertex */ private V initVertex(Vertex v) { V vertex; if (!vertexIds.containsKey(v.getId())) { vertex = (V) config.getVertexFactory().createVertex( v.getLabel(), Properties.createFromMap(v.getProperties()), createGradoopIdSet(v)); vertexIds.put(v.getId(), vertex.getId()); vertices.put(vertex.getId(), vertex); } else { vertex = vertices.get(vertexIds.get(v.getId())); vertex.setGraphIds(createGradoopIdSet(v)); } return vertex; }
@Test public void testVertex() { GradoopId vertexId = GradoopId.get(); String label = "A"; Properties props = Properties.create(); props.set("k1", "v1"); props.set("k2", "v2"); EPGMVertex vertex = new VertexFactory().initVertex(vertexId, label, props); String newLabel = "B"; TransformationFunction<EPGMVertex> renameFunction = new RenameLabel<>(label, newLabel); renameFunction.apply(vertex, vertex); assertEquals(newLabel, vertex.getLabel()); assertThat(vertex.getPropertyValue("k1").toString(), Is.<Object>is("v1")); assertThat(vertex.getPropertyValue("k2").toString(), Is.<Object>is("v2")); } }
@Override public void writeVertex(@Nonnull final EPGMVertex vertexData) throws IOException { VertexHandler vertexHandler = config.getVertexHandler(); // vertex id Put put = new Put(vertexHandler.getRowKey(vertexData.getId())); // write vertex data to Put put = vertexHandler.writeVertex(put, vertexData); // write to table vertexTable.put(put); if (autoFlush) { admin.flush(vertexTable.getName()); } }
/** * Returns all vertices that belong to the given graphs. * * @param graphIds graph identifiers * @return vertices that are contained in the graphs */ public Collection<V> getVerticesByGraphIds(GradoopIdSet graphIds) { Collection<V> result = Sets.newHashSetWithExpectedSize(graphIds.size()); for (V vertex : vertices.values()) { if (vertex.getGraphIds().containsAny(graphIds)) { result.add(vertex); } } return result; }
@Override protected V initFrom(V element) { return vertexFactory.initVertex( element.getId(), GradoopConstants.DEFAULT_VERTEX_LABEL, element.getGraphIds()); } }
@Test public void createWithMissingLabelTest() { GradoopId vertexID = GradoopId.get(); EPGMVertex v = new VertexFactory().initVertex(vertexID); assertThat(v.getLabel(), is(GradoopConstants.DEFAULT_VERTEX_LABEL)); }
@Nonnull @Override public Pair<Key, Value> toRow(@Nonnull EPGMVertex record) throws IOException { //write to content return new Pair<>(new Key(record.getId().toString()), new Value(KryoUtils.dumps(factory.initVertex( record.getId(), record.getLabel(), record.getProperties(), record.getGraphIds())))); }
@Override public boolean filter(V v) throws Exception { return v.getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY) .getString().equals( BusinessTransactionGraphs.SUPERCLASS_VALUE_MASTER); } }
@Override public V join(V element, Tuple2<GradoopId, GradoopIdSet> mapping) throws Exception { element.setGraphIds(mapping.f1); return element; } }