Search in sources :

Example 1 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestGremlinCompileWithHas method testHasLabelOut.

@Test
public void testHasLabelOut() {
    SqlgVertex a1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
    SqlgVertex b1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
    a1.addEdge("outB", b1);
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal) this.sqlgGraph.traversal().V().both().has(T.label, "B");
    Assert.assertEquals(3, traversal.getSteps().size());
    printTraversalForm(traversal);
    Assert.assertEquals(1, traversal.getSteps().size());
    List<Vertex> softwares = traversal.toList();
    Assert.assertEquals(1, softwares.size());
    for (Vertex software : softwares) {
        if (!software.label().equals("B")) {
            Assert.fail("expected label B found " + software.label());
        }
    }
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 2 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testEdgePropertiesRemainsTheSame.

@Test(expected = IllegalStateException.class)
public void testEdgePropertiesRemainsTheSame() {
    SqlgVertex v1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
    SqlgVertex v2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.tx().streamingBatchModeOn();
    LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
    keyValues.put("name", "halo");
    v1.streamEdge("a", v2, keyValues);
    keyValues.clear();
    keyValues.put("namea", "halo");
    v1.streamEdge("a", v2, keyValues);
    Assert.fail();
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Example 3 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method createMilPersonVertex.

private ArrayList<SqlgVertex> createMilPersonVertex() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    ArrayList<SqlgVertex> result = new ArrayList<>();
    this.sqlgGraph.tx().normalBatchModeOn();
    for (int i = 1; i < NUMBER_OF_VERTICES + 1; i++) {
        Map<String, Object> keyValue = new LinkedHashMap<>();
        for (int j = 0; j < 100; j++) {
            keyValue.put("name" + j, "aaaaaaaaaa" + i);
        }
        SqlgVertex person = (SqlgVertex) this.sqlgGraph.addVertex("Person", keyValue);
        result.add(person);
        if (i % (NUMBER_OF_VERTICES / 10) == 0) {
            this.sqlgGraph.tx().commit();
            this.sqlgGraph.tx().normalBatchModeOn();
        }
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println("createMilPersonVertex took " + stopWatch.toString());
    return result;
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) ArrayList(java.util.ArrayList) StopWatch(org.apache.commons.lang3.time.StopWatch) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testStreamLocalDateTime.

@Test
public void testStreamLocalDateTime() throws InterruptedException {
    this.sqlgGraph.tx().streamingBatchModeOn();
    LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
    keyValues.put("name", "halo");
    keyValues.put("surname", "halo");
    for (int i = 0; i < 10; i++) {
        keyValues.put("age", i);
        this.sqlgGraph.streamVertex("Man", keyValues);
    }
    this.sqlgGraph.tx().flush();
    for (int i = 0; i < 10; i++) {
        keyValues.put("age", i);
        this.sqlgGraph.streamVertex("Female", keyValues);
    }
    this.sqlgGraph.tx().flush();
    int count = 0;
    List<Vertex> men = this.sqlgGraph.traversal().V().hasLabel("Man").toList();
    List<Vertex> females = this.sqlgGraph.traversal().V().hasLabel("Female").toList();
    LinkedHashMap<String, Object> edgeKeyValues = new LinkedHashMap<>();
    LocalDateTime now = LocalDateTime.now();
    edgeKeyValues.put("localDateTime", now);
    for (Vertex man : men) {
        SqlgVertex female = (SqlgVertex) females.get(count++);
        ((SqlgVertex) man).streamEdge("married", female, edgeKeyValues);
    }
    this.sqlgGraph.tx().commit();
    testStreamLocalDateTime_assert(this.sqlgGraph, now);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testStreamLocalDateTime_assert(this.sqlgGraph1, now);
    }
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Example 5 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testEdgePropertiesSameOrder.

@Test(expected = IllegalStateException.class)
public void testEdgePropertiesSameOrder() {
    SqlgVertex v1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
    SqlgVertex v2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.tx().streamingBatchModeOn();
    LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
    keyValues.put("name", "halo");
    keyValues.put("surname", "test");
    v1.streamEdge("a", v2, keyValues);
    keyValues.clear();
    keyValues.put("surname", "test");
    keyValues.put("name", "halo");
    v1.streamEdge("a", v2, keyValues);
    Assert.fail();
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Aggregations

SqlgVertex (org.umlg.sqlg.structure.SqlgVertex)27 BaseTest (org.umlg.sqlg.test.BaseTest)22 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)17 LinkedHashMap (java.util.LinkedHashMap)16 StopWatch (org.apache.commons.lang3.time.StopWatch)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)3 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 PropertyType (org.umlg.sqlg.structure.PropertyType)1 SchemaTable (org.umlg.sqlg.structure.SchemaTable)1 VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)1