@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; }
/** * 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()); }
@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 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() { 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 HasVertexLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasVertexLabelTrue() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasVertexLabel hasPerson = new HasVertexLabel("Person"); graph = graph.aggregate(hasPerson); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasVertexLabel_Person not set", graphHead.hasProperty(hasPerson.getAggregatePropertyKey())); assertTrue("Property hasVertexLabel_Person is false, should be true", graphHead.getPropertyValue(hasPerson.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasLabel with a single graph and result true. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasElementLabelTrue() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasLabel hasPerson = new HasLabel("Person"); graph = graph.aggregate(hasPerson); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_Person not set", graphHead.hasProperty(hasPerson.getAggregatePropertyKey())); assertTrue("Property hasLabel_Person is false, should be true", graphHead.getPropertyValue(hasPerson.getAggregatePropertyKey()).getBoolean()); }
/** * 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()); }
/** * 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 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()); }
/** * 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()); }
/** * Test HasLabel with a single graph and empty label string. * * @throws Exception if the execution fails. */ @Test public void testSingleGraphHasElementLabelEmptyString() throws Exception { LogicalGraph graph = getLoaderFromString("g0[(v0)-[e0]->(v1)]") .getLogicalGraphByVariable("g0"); HasLabel hasLabel = new HasLabel(""); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_ not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertTrue("Property hasLabel_ is false, should be true", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasEdgeLabel with a single graph and result false. * * @throws Exception if the execution or IO fails. */ @Test public void testSingleGraphHasEdgeLabelFalse() throws Exception { LogicalGraph graph = getSocialNetworkLoader().getLogicalGraphByVariable("g2"); HasEdgeLabel hasNotExistent = new HasEdgeLabel("LabelDoesNotExist"); graph = graph.aggregate(hasNotExistent); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasEdgeLabel_LabelDoesNotExist not set", graphHead.hasProperty(hasNotExistent.getAggregatePropertyKey())); assertFalse("Property hasEdgeLabel_LabelDoesNotExist is true, should be false", graphHead.getPropertyValue(hasNotExistent.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasVertexLabel with a single graph and empty label string. * * @throws Exception if the execution fails. */ @Test public void testSingleGraphHasVertexLabelEmptyString() throws Exception { LogicalGraph graph = getLoaderFromString("g0[(v0)-[e0]->(v1)]") .getLogicalGraphByVariable("g0"); HasVertexLabel hasLabel = new HasVertexLabel(""); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasVertexLabel_ not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertTrue("Property hasVertexLabel_ is false, should be true", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getBoolean()); }
/** * Test HasLabel with a single empty graph. * * @throws Exception if the execution fails. */ @Test public void testEmptyGraphHasElementLabel() throws Exception { LogicalGraph graph = getLoaderFromString("g0[]") .getLogicalGraphByVariable("g0"); HasLabel hasLabel = new HasLabel("anyLabel"); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_anyLabel not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertNull("Property hasLabel_anyLabel is not NULL", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getObject()); }
sumProperty.getAggregatePropertyKey())); assertEquals(PropertyValue.NULL_VALUE, graphHead.getPropertyValue( sumEdgeProperty.getAggregatePropertyKey())); assertEquals(PropertyValue.NULL_VALUE, graphHead.getPropertyValue( sumVertexProperty.getAggregatePropertyKey())); assertEquals(PropertyValue.NULL_VALUE, graphHead.getPropertyValue( sumProperty.getAggregatePropertyKey()));
assertEquals( 2, graphHead.getPropertyValue( minEdgeProperty.getAggregatePropertyKey()).getInt()); assertEquals( 0.0f, graphHead.getPropertyValue( minVertexProperty.getAggregatePropertyKey()).getFloat(), 0.00001f); assertEquals( 0.0f, graphHead.getPropertyValue( minProperty.getAggregatePropertyKey()).getFloat(), 0.00001f);
assertEquals( 3.1f, graphHead.getPropertyValue( maxVertexProperty.getAggregatePropertyKey()).getFloat(), 0.00001f); assertTrue("edge maximum not set", assertEquals( 2, graphHead.getPropertyValue( maxEdgeProperty.getAggregatePropertyKey()).getInt()); assertTrue("element maximum not set", assertEquals( 3.1f, graphHead.getPropertyValue( maxProperty.getAggregatePropertyKey()).getFloat(), 0.00001f);
graphHead.hasProperty(hasOtherLabel.getAggregatePropertyKey())); assertFalse("Property hasEdgeLabel_otherLabel is true, should be false", graphHead.getPropertyValue(hasOtherLabel.getAggregatePropertyKey()).getBoolean()); graphHead.getPropertyValue(hasSomeLabel.getAggregatePropertyKey()).getBoolean()); graphHead.getPropertyValue(hasThirdLabel.getAggregatePropertyKey()).getBoolean());
graphHead.hasProperty(hasPerson.getAggregatePropertyKey())); assertTrue("Property hasVertexLabel_Person is false, should be true", graphHead.getPropertyValue(hasPerson.getAggregatePropertyKey()).getBoolean()); graphHead.getPropertyValue(hasKnows.getAggregatePropertyKey()).getBoolean()); graphHead.getPropertyValue(hasKnowsElement.getAggregatePropertyKey()).getBoolean());