/** * Tests whether vertices are created properly even if not deduplicated. * * @throws Exception If the data could not be loaded or collected properly. */ @Test public void nonDeduplicationTest() throws Exception { LogicalGraph social = getSocialNetworkLoader().getLogicalGraph(); // this operation should create 6 vertices with the property values: // 'Berlin', 3 times 'Dresden', 2 times 'Leipzig' ExtractPropertyFromVertex extract = new ExtractPropertyFromVertex("Person", "city", "City", "name"); extract.setCondensation(false); LogicalGraph extractedGraph = social.callForGraph(extract); List<Vertex> vertices = new ArrayList<>(); extractedGraph .getVerticesByLabel("City") .output(new LocalCollectionOutputFormat<>(vertices)); getConfig().getExecutionEnvironment().execute(); Map<String, Integer> cityCountMap = new HashMap<>(); vertices.forEach(v -> cityCountMap.merge(v.getPropertyValue("name").getString(), 1, Integer::sum)); Assert.assertEquals(1, cityCountMap.get("Berlin").intValue()); Assert.assertEquals(3, cityCountMap.get("Dresden").intValue()); Assert.assertEquals(2, cityCountMap.get("Leipzig").intValue()); }
/** * Creates an initial {@link PlanTableEntry} for each vertex in the query graph and adds it to the * specified {@link PlanTable}. The entry wraps a query plan that filters vertices based on their * predicates and projects properties that are required for further query planning. * * @param planTable plan table */ private void createVertexPlans(PlanTable planTable) { for (Vertex vertex : queryHandler.getVertices()) { String vertexVariable = vertex.getVariable(); CNF allPredicates = queryHandler.getPredicates(); // TODO: this might be moved to the FilterAndProject node in issue #510 CNF vertexPredicates = allPredicates.removeSubCNF(vertexVariable); Set<String> projectionKeys = allPredicates.getPropertyKeys(vertexVariable); DataSet<org.gradoop.common.model.impl.pojo.Vertex> vertices = vertex.getLabel().equals(GradoopConstants.DEFAULT_VERTEX_LABEL) ? graph.getVertices() : graph.getVerticesByLabel(vertex.getLabel()); FilterAndProjectVerticesNode node = new FilterAndProjectVerticesNode(vertices, vertex.getVariable(), vertexPredicates, projectionKeys); planTable.add(new PlanTableEntry(VERTEX, Sets.newHashSet(vertexVariable), allPredicates, new QueryPlanEstimator(new QueryPlan(node), queryHandler, graphStatistics))); } }
/** * Creates an initial {@link PlanTableEntry} for each vertex in the query graph and adds it to the * specified {@link PlanTable}. The entry wraps a query plan that filters vertices based on their * predicates and projects properties that are required for further query planning. * * @param planTable plan table */ private void createVertexPlans(PlanTable planTable) { for (Vertex vertex : queryHandler.getVertices()) { String vertexVariable = vertex.getVariable(); CNF allPredicates = queryHandler.getPredicates(); // TODO: this might be moved to the FilterAndProject node in issue #510 CNF vertexPredicates = allPredicates.removeSubCNF(vertexVariable); Set<String> projectionKeys = allPredicates.getPropertyKeys(vertexVariable); DataSet<org.gradoop.common.model.impl.pojo.Vertex> vertices = vertex.getLabel().equals(GradoopConstants.DEFAULT_VERTEX_LABEL) ? graph.getVertices() : graph.getVerticesByLabel(vertex.getLabel()); FilterAndProjectVerticesNode node = new FilterAndProjectVerticesNode(vertices, vertex.getVariable(), vertexPredicates, projectionKeys); planTable.add(new PlanTableEntry(VERTEX, Sets.newHashSet(vertexVariable), allPredicates, new QueryPlanEstimator(new QueryPlan(node), queryHandler, graphStatistics))); } }
/** * Tests whether vertices are correctly deduplicated/condensed. * * @throws Exception If the data could not be loaded or collected properly. */ @Test public void cityDeduplicationTest() throws Exception { LogicalGraph social = getSocialNetworkLoader().getLogicalGraph(); // this operation should create 3 vertices with the property values: Berlin, Dresden, Leipzig // keep in mind that the default for condensation is 'true' UnaryGraphToGraphOperator extOne = new ExtractPropertyFromVertex("Person", "city", "City", "name"); LogicalGraph extOneGraph = social.callForGraph(extOne); List<Vertex> city = extOneGraph.getVerticesByLabel("City").collect(); Set<String> cityNames = new HashSet<>(); for (Vertex v : city) { String cityName = v.getPropertyValue("name").getString(); Assert.assertTrue(cityName.equals("Dresden") || cityName.equals("Berlin") || cityName.equals("Leipzig")); Assert.assertTrue(cityNames.add(cityName)); } Assert.assertEquals(3, cityNames.size()); // The number of edges should be the same as before. Assert.assertEquals(social.getEdges().count(), extOneGraph.getEdges().count()); }