Search in sources :

Example 11 with SqlgVertex

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

the class TestBatchStreamEdge method createMilCarVertex.

private ArrayList<SqlgVertex> createMilCarVertex() {
    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 car = (SqlgVertex) this.sqlgGraph.addVertex("Car", keyValue);
        result.add(car);
        if (i % (NUMBER_OF_VERTICES / 10) == 0) {
            this.sqlgGraph.tx().commit();
            this.sqlgGraph.tx().normalBatchModeOn();
        }
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println("createMilCarVertex 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 12 with SqlgVertex

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

the class TestBatchStreamEdge method testStreamPeriod.

@Test
public void testStreamPeriod() 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<>();
    Period period = Period.of(1, 2, 3);
    edgeKeyValues.put("period", period);
    for (Vertex man : men) {
        SqlgVertex female = (SqlgVertex) females.get(count++);
        ((SqlgVertex) man).streamEdge("married", female, edgeKeyValues);
    }
    this.sqlgGraph.tx().commit();
    testStreamPeriod_assert(this.sqlgGraph, period);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testStreamPeriod_assert(this.sqlgGraph1, period);
    }
}
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 13 with SqlgVertex

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

the class TestBatchStreamVertex method testCanNotAddVertexOnceStreaming.

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

Example 14 with SqlgVertex

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

the class TestAddVertexViaMap method testMap.

@Test
public void testMap() {
    Map<String, Object> map = new HashMap<>();
    map.put("name1", "p1");
    map.put("name2", "p2");
    map.put("name3", "p3");
    Vertex v1 = this.sqlgGraph.addVertex("Person", map);
    this.sqlgGraph.tx().commit();
    Vertex v2 = this.sqlgGraph.traversal().V().<Vertex>has(T.label, "Person").next();
    Assert.assertEquals(v1, v2);
    Assert.assertEquals("p1", v2.property("name1").value());
    Assert.assertEquals("p2", v2.property("name2").value());
    Assert.assertEquals("p3", v2.property("name3").value());
    Map<String, Object> edgeMap = new HashMap<>();
    edgeMap.put("name1", "p1");
    edgeMap.put("name2", "p2");
    edgeMap.put("name3", "p3");
    Edge e1 = ((SqlgVertex) v1).addEdgeWithMap("e1", v2, edgeMap);
    this.sqlgGraph.tx().commit();
    Assert.assertEquals("p1", e1.property("name1").value());
    Assert.assertEquals("p2", e1.property("name2").value());
    Assert.assertEquals("p3", e1.property("name3").value());
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HashMap(java.util.HashMap) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 15 with SqlgVertex

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

the class TestTraversalPerformance method testSpeedWithLargeSchemaFastQuery1.

@Test
public void testSpeedWithLargeSchemaFastQuery1() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Map<String, PropertyType> columns = new HashMap<>();
    for (int i = 0; i < 100; i++) {
        columns.put("property_" + i, PropertyType.STRING);
    }
    // Create a large schema, it slows the maps  down
    int NUMBER_OF_SCHEMA_ELEMENTS = 1_000;
    for (int i = 0; i < NUMBER_OF_SCHEMA_ELEMENTS; i++) {
        VertexLabel person = this.sqlgGraph.getTopology().ensureVertexLabelExist("Person_" + i, columns);
        VertexLabel dog = this.sqlgGraph.getTopology().ensureVertexLabelExist("Dog_" + i, columns);
        person.ensureEdgeLabelExist("pet_" + i, dog, columns);
        if (i % 100 == 0) {
            this.sqlgGraph.tx().commit();
        }
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println("done creating schema time taken " + stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    Map<String, Object> columnValues = new HashMap<>();
    for (int i = 0; i < 100; i++) {
        columnValues.put("property_" + i, "asdasdasd");
    }
    for (int i = 0; i < NUMBER_OF_SCHEMA_ELEMENTS; i++) {
        SqlgVertex person = (SqlgVertex) this.sqlgGraph.addVertex("Person_" + i, columnValues);
        SqlgVertex dog = (SqlgVertex) this.sqlgGraph.addVertex("Dog_" + i, columnValues);
        person.addEdgeWithMap("pet_" + i, dog, columnValues);
    }
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println("done inserting data time taken " + stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    for (int i = 0; i < 10_000; i++) {
        Assert.assertEquals(1, this.sqlgGraph.traversal().V().hasLabel("Person_0").out("pet_0").toList().size());
    }
    stopWatch.stop();
    System.out.println("total query time " + stopWatch.toString());
}
Also used : HashMap(java.util.HashMap) VertexLabel(org.umlg.sqlg.structure.topology.VertexLabel) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) PropertyType(org.umlg.sqlg.structure.PropertyType) StopWatch(org.apache.commons.lang3.time.StopWatch) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

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