org.umlg.sqlg.test.reducing.TestReducingVertexStep Maven / Gradle / Ivy
package org.umlg.sqlg.test.reducing;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;
import org.umlg.sqlg.test.BaseTest;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* @author Pieter Martin (https://github.com/pietermartin)
* Date: 2018/12/31
*/
@SuppressWarnings("rawtypes")
public class TestReducingVertexStep extends BaseTest {
@Test
public void testGroupOverOnePropertyMax() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "age", 1);
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1", "age", 1);
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1", "age", 2);
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 3);
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 4);
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2", "age", 1);
Vertex b21 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 5);
Vertex b22 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 6);
Vertex b23 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 7);
Vertex b24 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 8);
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
a1.addEdge("ab", b4);
a2.addEdge("ab", b21);
a2.addEdge("ab", b22);
a2.addEdge("ab", b23);
a2.addEdge("ab", b24);
this.sqlgGraph.tx().commit();
Traversal> traversal = this.sqlgGraph.traversal()
.V().has("name", __.or(__.is("a1"), __.is("a2"))).out()
.group().by("name").by(__.values("age").max());
printTraversalForm(traversal);
Assert.assertTrue(traversal.hasNext());
Map result = traversal.next();
Assert.assertFalse(traversal.hasNext());
Assert.assertTrue(result.containsKey("b1"));
Assert.assertTrue(result.containsKey("b2"));
Assert.assertEquals(2, result.get("b1"), 0);
Assert.assertEquals(8, result.get("b2"), 0);
}
@Test
public void testGroupOverOnePropertyLocalMax() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "age", 1);
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1", "age", 1);
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1", "age", 2);
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 3);
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "age", 4);
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2", "age", 1);
Vertex b21 = this.sqlgGraph.addVertex(T.label, "B", "name", "b21", "age", 1);
Vertex b22 = this.sqlgGraph.addVertex(T.label, "B", "name", "b21", "age", 2);
Vertex b23 = this.sqlgGraph.addVertex(T.label, "B", "name", "b22", "age", 3);
Vertex b24 = this.sqlgGraph.addVertex(T.label, "B", "name", "b22", "age", 4);
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
a1.addEdge("ab", b4);
a2.addEdge("ab", b21);
a2.addEdge("ab", b22);
a2.addEdge("ab", b23);
a2.addEdge("ab", b24);
this.sqlgGraph.tx().commit();
Traversal> traversal = this.sqlgGraph.traversal()
.V().hasLabel("A")
.local(
__.out().group().by("name").by(__.values("age").max())
);
printTraversalForm(traversal);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy