Search in sources :

Example 1 with SchemaTable

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

the class SqlgSqlExecutor method executeDropQuery.

public static void executeDropQuery(SqlgGraph sqlgGraph, SchemaTableTree rootSchemaTableTree, LinkedList<SchemaTableTree> distinctQueryStack) {
    List<Triple<DROP_QUERY, String, SchemaTable>> sqls = rootSchemaTableTree.constructDropSql(distinctQueryStack);
    for (Triple<DROP_QUERY, String, SchemaTable> sqlPair : sqls) {
        DROP_QUERY dropQuery = sqlPair.getLeft();
        String sql = sqlPair.getMiddle();
        SchemaTable deletedSchemaTable = sqlPair.getRight();
        switch(dropQuery) {
            case ALTER:
                executeDropQuery(sqlgGraph, sql, new LinkedList<>(), deletedSchemaTable);
                break;
            case EDGE:
                LinkedList<SchemaTableTree> tmp = new LinkedList<>(distinctQueryStack);
                tmp.removeLast();
                executeDropQuery(sqlgGraph, sql, tmp, deletedSchemaTable);
                break;
            case NORMAL:
                executeDropQuery(sqlgGraph, sql, distinctQueryStack, deletedSchemaTable);
                break;
            case TRUNCATE:
                executeDropQuery(sqlgGraph, sql, new LinkedList<>(), deletedSchemaTable);
                break;
            default:
                throw new IllegalStateException("Unknown DROP_QUERY " + dropQuery.toString());
        }
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) SchemaTableTree(org.umlg.sqlg.sql.parse.SchemaTableTree) SchemaTable(org.umlg.sqlg.structure.SchemaTable) LinkedList(java.util.LinkedList)

Example 2 with SchemaTable

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

the class TestCaptureSchemaTableEdges method testCaptureSchemaTableLabelsRollback.

@Test
public void testCaptureSchemaTableLabelsRollback() {
    Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsTransactionalSchema());
    Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "pieter");
    Vertex car1 = this.sqlgGraph.addVertex(T.label, "Car", "name", "bmw");
    person1.addEdge("drives", car1);
    Vertex car2 = this.sqlgGraph.addVertex(T.label, "Car", "name", "toyota");
    person1.addEdge("drives", car2);
    Vertex bmw = this.sqlgGraph.addVertex(T.label, "Model", "name", "bmw");
    car1.addEdge("model", bmw);
    Vertex toyota = this.sqlgGraph.addVertex(T.label, "Model", "name", "toyota");
    car2.addEdge("model", toyota);
    this.sqlgGraph.tx().rollback();
    Map<SchemaTable, Pair<Set<SchemaTable>, Set<SchemaTable>>> localTables = this.sqlgGraph.getTopology().getTableLabels();
    assertTrue(localTables.containsKey(SchemaTable.of(SQLG_SCHEMA, "V_vertex")));
    assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "V_Person")));
    assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "V_Car")));
    assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "V_Model")));
    assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "E_drives")));
    assertFalse(localTables.containsKey(SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "E_model")));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SchemaTable(org.umlg.sqlg.structure.SchemaTable) Pair(org.apache.commons.lang3.tuple.Pair) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 3 with SchemaTable

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

the class TestBatchServerSideEdgeCreation method testBulkEdges2.

@Test
public void testBulkEdges2() throws InterruptedException {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph.tx().streamingBatchModeOn();
    List<Pair<String, String>> uids = new ArrayList<>();
    LinkedHashMap properties = new LinkedHashMap();
    String uuid1Cache = null;
    String uuid2Cache = null;
    for (int i = 0; i < 1000; i++) {
        String uuid1 = UUID.randomUUID().toString();
        String uuid2 = UUID.randomUUID().toString();
        if (i == 50) {
            uuid1Cache = uuid1;
            uuid2Cache = uuid2;
        }
        uids.add(Pair.of(uuid1, uuid2));
        properties.put("id", uuid1);
        this.sqlgGraph.streamVertex("Person", properties);
        properties.put("id", uuid2);
        this.sqlgGraph.streamVertex("Person", properties);
    }
    this.sqlgGraph.tx().flush();
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    stopWatch.reset();
    stopWatch.start();
    this.sqlgGraph.tx().streamingBatchModeOn();
    SchemaTable person = SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "Person");
    this.sqlgGraph.bulkAddEdges("Person", "Person", "friend", Pair.of("id", "id"), uids);
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    testBulkEdges2_assert(this.sqlgGraph, uuid1Cache, uuid2Cache);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testBulkEdges2_assert(this.sqlgGraph1, uuid1Cache, uuid2Cache);
    }
}
Also used : SchemaTable(org.umlg.sqlg.structure.SchemaTable) StopWatch(org.apache.commons.lang3.time.StopWatch) Pair(org.apache.commons.lang3.tuple.Pair) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 4 with SchemaTable

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

the class TestBatchServerSideEdgeCreation method testBulkEdgesTempTableUnique.

@Test
public void testBulkEdgesTempTableUnique() {
    this.sqlgGraph.tx().streamingBatchModeOn();
    List<Pair<String, String>> uids = new ArrayList<>();
    LinkedHashMap properties = new LinkedHashMap();
    for (int i = 0; i < 1000; i++) {
        String uuid1 = UUID.randomUUID().toString();
        String uuid2 = UUID.randomUUID().toString();
        uids.add(Pair.of(uuid1, uuid2));
        properties.put("id", uuid1);
        this.sqlgGraph.streamVertex("Person", properties);
        properties.put("id", uuid2);
        this.sqlgGraph.streamVertex("Person", properties);
    }
    this.sqlgGraph.tx().flush();
    this.sqlgGraph.tx().streamingBatchModeOn();
    SchemaTable person = SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "Person");
    this.sqlgGraph.bulkAddEdges("Person", "Person", "friend", Pair.of("id", "id"), uids);
    this.sqlgGraph.tx().commit();
    // and again
    this.sqlgGraph.tx().streamingBatchModeOn();
    uids.clear();
    for (int i = 0; i < 1000; i++) {
        String uuid1 = UUID.randomUUID().toString();
        String uuid2 = UUID.randomUUID().toString();
        uids.add(Pair.of(uuid1, uuid2));
        properties.put("id", uuid1);
        this.sqlgGraph.streamVertex("Person", properties);
        properties.put("id", uuid2);
        this.sqlgGraph.streamVertex("Person", properties);
    }
    this.sqlgGraph.tx().flush();
    this.sqlgGraph.tx().streamingBatchModeOn();
    this.sqlgGraph.bulkAddEdges("Person", "Person", "friend", Pair.of("id", "id"), uids);
    this.sqlgGraph.tx().commit();
}
Also used : SchemaTable(org.umlg.sqlg.structure.SchemaTable) Pair(org.apache.commons.lang3.tuple.Pair) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 5 with SchemaTable

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

the class ServerSideBulkEdgeCreation method bulkAddEdges.

@Benchmark
public long bulkAddEdges() {
    int numberOfElement = 1_000_000;
    if (this.sqlgGraph.getSqlDialect().supportsBatchMode()) {
        this.sqlgGraph.tx().streamingBatchModeOn();
    }
    List<String> leftUids = new ArrayList<>();
    for (int i = 0; i < numberOfElement; i++) {
        String uid = UUID.randomUUID().toString();
        leftUids.add(uid);
        this.sqlgGraph.streamVertex(T.label, "A", "uid", uid);
    }
    this.sqlgGraph.tx().flush();
    List<String> rightUids = new ArrayList<>();
    for (int i = 0; i < numberOfElement; i++) {
        String uid = UUID.randomUUID().toString();
        rightUids.add(uid);
        this.sqlgGraph.streamVertex(T.label, "B", "uid", uid);
    }
    this.sqlgGraph.tx().commit();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph.tx().streamingBatchModeOn();
    SchemaTable a = SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "A");
    SchemaTable b = SchemaTable.of(this.sqlgGraph.getSqlDialect().getPublicSchema(), "B");
    List<Pair<String, String>> leftRight = new ArrayList<>();
    int count = 0;
    for (String leftUid : leftUids) {
        leftRight.add(Pair.of(leftUid, rightUids.get(count++)));
    }
    this.sqlgGraph.bulkAddEdges("A", "B", "AB", Pair.of("uid", "uid"), leftRight);
    this.sqlgGraph.tx().commit();
    stopWatch.stop();
    System.out.println(stopWatch.toString());
    assertEquals(numberOfElement, this.gt.V().hasLabel("A").has("uid", P.within(leftUids)).toList().size());
    return numberOfElement;
}
Also used : SchemaTable(org.umlg.sqlg.structure.SchemaTable) ArrayList(java.util.ArrayList) StopWatch(org.apache.commons.lang3.time.StopWatch) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

SchemaTable (org.umlg.sqlg.structure.SchemaTable)9 Pair (org.apache.commons.lang3.tuple.Pair)6 Test (org.junit.Test)5 BaseTest (org.umlg.sqlg.test.BaseTest)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 Set (java.util.Set)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Triple (org.apache.commons.lang3.tuple.Triple)1 SchemaTableTree (org.umlg.sqlg.sql.parse.SchemaTableTree)1 SqlgGraph (org.umlg.sqlg.structure.SqlgGraph)1 SqlgVertex (org.umlg.sqlg.structure.SqlgVertex)1