org.umlg.sqlg.test.batch.TestBatchServerSideEdgeCreation Maven / Gradle / Ivy
package org.umlg.sqlg.test.batch;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.umlg.sqlg.structure.SchemaTable;
import org.umlg.sqlg.test.BaseTest;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TestBatchServerSideEdgeCreation extends BaseTest {
@Before
public void beforeTest() {
Assume.assumeTrue(this.sqlgGraph.getSqlDialect().supportsBatchMode());
}
@Test
public void testBulkEdges() {
this.sqlgGraph.tx().normalBatchModeOn();
int count = 0;
List> uids = new ArrayList<>();
for (int i = 0; i < 10; i++) {
this.sqlgGraph.addVertex(T.label, "A", "index", Integer.toString(i));
for (int j = 0; j < 10; j++) {
this.sqlgGraph.addVertex(T.label, "B", "index", Integer.toString(count));
uids.add(Pair.of(Integer.toString(i), Integer.toString(count++)));
}
}
this.sqlgGraph.tx().commit();
this.sqlgGraph.tx().streamingBatchModeOn();
this.sqlgGraph.bulkAddEdges("A", "B", "AB", Pair.of("index", "index"), uids);
this.sqlgGraph.tx().commit();
assertEquals(10, this.sqlgGraph.traversal().V().hasLabel("A").count().next(), 0);
assertEquals(100, this.sqlgGraph.traversal().V().hasLabel("B").count().next(), 0);
assertEquals(100, this.sqlgGraph.traversal().V().hasLabel("A").out().count().next(), 0);
}
@Test
public void testBulkEdgesCrossSchemas() {
this.sqlgGraph.tx().normalBatchModeOn();
int count = 0;
List> uids = new ArrayList<>();
for (int i = 0; i < 10; i++) {
this.sqlgGraph.addVertex(T.label, "A.A", "index", Integer.toString(i));
for (int j = 0; j < 10; j++) {
this.sqlgGraph.addVertex(T.label, "B.B", "index", Integer.toString(count));
uids.add(Pair.of(Integer.toString(i), Integer.toString(count++)));
}
}
this.sqlgGraph.tx().commit();
this.sqlgGraph.tx().streamingBatchModeOn();
this.sqlgGraph.bulkAddEdges("A.A", "B.B", "AB", Pair.of("index", "index"), uids);
this.sqlgGraph.tx().commit();
assertEquals(10, this.sqlgGraph.traversal().V().hasLabel("A.A").count().next(), 0);
assertEquals(100, this.sqlgGraph.traversal().V().hasLabel("B.B").count().next(), 0);
assertEquals(100, this.sqlgGraph.traversal().V().hasLabel("A.A").out().count().next(), 0);
}
@Test
public void testBulkEdges2() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
this.sqlgGraph.tx().streamingBatchModeOn();
List> 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());
GraphTraversal has = this.sqlgGraph.traversal().V().hasLabel("Person").has("id", uuid1Cache);
assertTrue(has.hasNext());
Vertex person50 = has.next();
GraphTraversal has1 = this.sqlgGraph.traversal().V().hasLabel("Person").has("id", uuid2Cache);
assertTrue(has1.hasNext());
Vertex person250 = has1.next();
assertTrue(this.sqlgGraph.traversal().V(person50.id()).out().hasNext());
Vertex person250Please = this.sqlgGraph.traversal().V(person50.id()).out().next();
assertEquals(person250, person250Please);
}
@Test
public void testBulkEdgesTempTableUnique() {
this.sqlgGraph.tx().streamingBatchModeOn();
List> 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();
}
@Test
public void testBulkAddEdgesStringAndIntegerIds() {
Vertex realWorkspaceElement1 = this.sqlgGraph.addVertex(T.label, "RealWorkspaceElement", "cmUid", "a");
Vertex realWorkspaceElement2 = this.sqlgGraph.addVertex(T.label, "RealWorkspaceElement", "cmUid", "b");
Vertex virtualGroup = this.sqlgGraph.addVertex(T.label, "VirtualGroup", "name", "asd");
this.sqlgGraph.tx().commit();
Edge e =realWorkspaceElement1.addEdge("realWorkspaceElement_virtualGroup", virtualGroup);
this.sqlgGraph.tx().commit();
e.remove();
this.sqlgGraph.tx().commit();
this.sqlgGraph.tx().streamingBatchModeOn();
List> ids = new ArrayList<>();
ids.add(Pair.of("a", "1"));
ids.add(Pair.of("b", "1"));
this.sqlgGraph.bulkAddEdges("RealWorkspaceElement", "VirtualGroup", "realWorkspaceElement_virtualGroup", Pair.of("cmUid", "ID"), ids);
this.sqlgGraph.tx().commit();
assertTrue(this.sqlgGraph.traversal().V(realWorkspaceElement1.id()).out("realWorkspaceElement_virtualGroup").hasNext());
assertTrue(this.sqlgGraph.traversal().V(realWorkspaceElement2.id()).out("realWorkspaceElement_virtualGroup").hasNext());
assertTrue(this.sqlgGraph.traversal().V(virtualGroup.id()).in("realWorkspaceElement_virtualGroup").hasNext());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy