@Override protected G initFrom(G graphHead) { return graphHeadFactory.initGraphHead(graphHead.getId(), GradoopConstants.DEFAULT_GRAPH_LABEL); } }
@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; }
assertTrue("edge sum not set", graphHead.hasProperty( sumEdgeProperty.getAggregatePropertyKey())); assertTrue("vertex sum not set", graphHead.hasProperty( sumVertexProperty.getAggregatePropertyKey())); assertTrue("element sum not set", graphHead.hasProperty( sumProperty.getAggregatePropertyKey())); graphHead.getPropertyValue(sumVertexProperty.getAggregatePropertyKey()); PropertyValue edgeAggregate = graphHead.getPropertyValue(sumEdgeProperty.getAggregatePropertyKey()); PropertyValue elementAggregate = graphHead.getPropertyValue(sumProperty.getAggregatePropertyKey()); if (graphHead.getId().equals(g0Id)) { assertEquals(1.5f, vertexAggregate.getFloat(), 0.00001); assertEquals( elementAggregate.getBigDecimal() .round(new MathContext(2, RoundingMode.HALF_UP))); } else if (graphHead.getId().equals(g1Id)) { assertEquals(0.5f, vertexAggregate.getFloat(), 0.00001); assertEquals(2L, edgeAggregate.getLong()); assertEquals(2.5f, elementAggregate.getFloat(), 0.00001); } else if (graphHead.getId().equals(g2Id)) { assertEquals(PropertyValue.NULL_VALUE, vertexAggregate); assertEquals(PropertyValue.NULL_VALUE, edgeAggregate);
@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 HasVertexLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasVertexLabelFalse() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasVertexLabel hasNotExistent = new HasVertexLabel("LabelDoesNotExist"); graph = graph.aggregate(hasNotExistent); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasVertexLabel_LabelDoesNotExist not set", graphHead.hasProperty(hasNotExistent.getAggregatePropertyKey())); assertFalse("Property hasVertexLabel_LabelDoesNotExist is true, should be false", graphHead.getPropertyValue(hasNotExistent.getAggregatePropertyKey()).getBoolean()); }
@Test public void createWithIDTest() { GradoopId graphID = GradoopId.get(); EPGMGraphHead g = new GraphHeadFactory().initGraphHead(graphID); assertThat(g.getId(), is(graphID)); assertThat(g.getPropertyCount(), is(0)); }
@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")); }
assertTrue("vertex count not set", graphHead.hasProperty( vertexCount.getAggregatePropertyKey())); assertTrue("edge count not set", graphHead.hasProperty( edgeCount.getAggregatePropertyKey())); assertTrue("element count not set", graphHead.hasProperty( count.getAggregatePropertyKey())); if (graphHead.getId().equals(g0Id)) { assertCounts(graphHead, 3, 2); } else if (graphHead.getId().equals(g1Id)) { assertCounts(graphHead, 4, 3); } else if (graphHead.getId().equals(g2Id)) { assertCounts(graphHead, 2, 1); } else if (graphHead .getId().equals(g3Id)) { assertCounts(graphHead, 0, 0); } else {
@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")); }
@Test public void createWithMissingLabelTest() { GradoopId graphID = GradoopId.get(); EPGMGraphHead g = new GraphHeadFactory().initGraphHead(graphID); assertThat(g.getLabel(), is(GradoopConstants.DEFAULT_GRAPH_LABEL)); }
/** * Helper function to test count aggregators. * Asserts the count for vertices, edges and all elements. * * @param graphHead graph head containing the aggregate properties * @param expectedVertexCount expected vertex count * @param expectedEdgeCount expected edge count */ void assertCounts(EPGMGraphHead graphHead, long expectedVertexCount, long expectedEdgeCount) { assertEquals("wrong vertex count", expectedVertexCount, graphHead.getPropertyValue(new VertexCount().getAggregatePropertyKey()).getLong()); assertEquals("wrong edge count", expectedEdgeCount, graphHead.getPropertyValue(new EdgeCount().getAggregatePropertyKey()).getLong()); assertEquals("wrong element count", expectedEdgeCount + expectedVertexCount, graphHead.getPropertyValue(new Count().getAggregatePropertyKey()).getLong()); }
assertTrue("edge minimum not set", graphHead.hasProperty (minEdgeProperty.getAggregatePropertyKey())); assertTrue("vertex minimum not set", graphHead.hasProperty (minVertexProperty.getAggregatePropertyKey())); assertTrue("element minimum not set", graphHead.hasProperty (minProperty.getAggregatePropertyKey())); graphHead.getPropertyValue(minEdgeProperty.getAggregatePropertyKey()); PropertyValue vertexAggregate = graphHead.getPropertyValue(minVertexProperty.getAggregatePropertyKey()); PropertyValue elementAggregate = graphHead.getPropertyValue(minProperty.getAggregatePropertyKey()); if (graphHead.getId().equals(g0Id)) { assertEquals(2, edgeAggregate.getLong()); assertEquals(0.1f, vertexAggregate.getFloat(), 0.00001); assertEquals(0.1f, elementAggregate.getFloat(), 0.00001); } else if (graphHead.getId().equals(g1Id)) { assertEquals(2, edgeAggregate.getLong()); assertEquals(0.3f, vertexAggregate.getFloat(), 0.00001); assertEquals(0.3f, elementAggregate.getFloat(), 0.00001); } else if (graphHead.getId().equals(g2Id)) { assertEquals(PropertyValue.NULL_VALUE, edgeAggregate); assertEquals(PropertyValue.NULL_VALUE, vertexAggregate);
/** * Test HasEdgeLabel with a single graph and result true. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasEdgeLabelTrue() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasEdgeLabel hasKnows = new HasEdgeLabel("knows"); graph = graph.aggregate(hasKnows); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasEdgeLabel_knows not set", graphHead.hasProperty(hasKnows.getAggregatePropertyKey())); assertTrue("Property hasEdgeLabel_knows is false, should be true", graphHead.getPropertyValue(hasKnows.getAggregatePropertyKey()).getBoolean()); }
graphHead.hasProperty(maxEdgeProperty.getAggregatePropertyKey())); assertTrue("vertex maximum not set", graphHead.hasProperty(maxVertexProperty.getAggregatePropertyKey())); assertTrue("element maximum not set", graphHead.hasProperty(maxVertexProperty.getAggregatePropertyKey())); graphHead.getPropertyValue(maxEdgeProperty.getAggregatePropertyKey()); PropertyValue vertexAggregate = graphHead.getPropertyValue(maxVertexProperty.getAggregatePropertyKey()); PropertyValue elementAggregate = graphHead.getPropertyValue(maxProperty.getAggregatePropertyKey()); if (graphHead.getId().equals(g0Id)) { assertEquals(2L, edgeAggregate.getLong()); assertEquals(0.5f, vertexAggregate.getFloat(), 0.00001); assertEquals(2L, elementAggregate.getLong()); } else if (graphHead.getId().equals(g1Id)) { assertEquals(2L, edgeAggregate.getLong()); assertEquals(0.5f, vertexAggregate.getFloat(), 0.00001); assertEquals(2L, elementAggregate.getLong()); } else if (graphHead.getId().equals(g2Id)) { assertEquals(PropertyValue.NULL_VALUE, edgeAggregate); assertEquals(PropertyValue.NULL_VALUE, vertexAggregate);
/** * Test HasLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasElementLabelFalse() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasLabel hasNotExistent = new HasLabel("LabelDoesNotExist"); graph = graph.aggregate(hasNotExistent); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_LabelDoesNotExist not set", graphHead.hasProperty(hasNotExistent.getAggregatePropertyKey())); assertFalse("Property hasLabel_LabelDoesNotExist is true, should be false", graphHead.getPropertyValue(hasNotExistent.getAggregatePropertyKey()).getBoolean()); }
@Override protected G initFrom(G graphHead) { return graphHeadFactory.initGraphHead(graphHead.getId(), GradoopConstants.DEFAULT_GRAPH_LABEL); } }
@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())))); }
assertTrue("vertex sum not set", graphHead.hasProperty( sumVertexProperty.getAggregatePropertyKey())); assertTrue("edge sum not set", graphHead.hasProperty( sumEdgeProperty.getAggregatePropertyKey())); assertTrue("element sum not set", graphHead.hasProperty( sumProperty.getAggregatePropertyKey())); graphHead.getPropertyValue(sumVertexProperty.getAggregatePropertyKey()); PropertyValue edgeAggregate = graphHead.getPropertyValue(sumEdgeProperty.getAggregatePropertyKey()); PropertyValue elementAggregate = graphHead.getPropertyValue(sumProperty.getAggregatePropertyKey()); if (graphHead.getId().equals(g0Id)) { assertEquals(2, edgeAggregate.getLong()); assertEquals(0.9f, vertexAggregate.getFloat(), 0.00001); assertEquals(2.9f, elementAggregate.getFloat(), 0.00001); } else if (graphHead.getId().equals(g1Id)) { assertEquals(2, edgeAggregate.getLong()); assertEquals(0.8f, vertexAggregate.getFloat(), 0.00001); assertEquals(2.8f, elementAggregate.getFloat(), 0.00001); } else if (graphHead.getId().equals(g2Id)) { assertEquals(PropertyValue.NULL_VALUE, edgeAggregate); assertEquals(PropertyValue.NULL_VALUE, vertexAggregate);
/** * Test HasEdgeLabel with a single edgeless graph. * * @throws Exception if the execution fails. */ @Test public void testEdgelessGraphHasEdgeLabel() throws Exception { LogicalGraph graph = getLoaderFromString("g0[(v0)(v1)]") .getLogicalGraphByVariable("g0"); HasEdgeLabel hasLabel = new HasEdgeLabel("anyLabel"); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasEdgeLabel_anyLabel not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertNull("Property hasEdgeLabel_anyLabel is not NULL", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getObject()); }