use of org.umlg.sqlg.structure.topology.VertexLabel 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());
}
use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.
the class TestGremlinCompileFullTextPredicate method testPerfOneColumn.
@Test
public // @Ignore("check manually index is used")
void testPerfOneColumn() throws SQLException {
assumeTrue(isPostgres());
Vertex v0 = this.sqlgGraph.addVertex(T.label, "Sentence", "name", "a fat cat sat on a mat and ate a fat rat");
int LOOPS = 10000;
for (int a = 0; a < LOOPS; a++) {
this.sqlgGraph.addVertex(T.label, "Sentence", "name", "loop" + a);
}
VertexLabel vl = this.sqlgGraph.getTopology().getVertexLabel("public", "Sentence").get();
vl.ensureIndexExists(IndexType.getFullTextGIN("english"), Collections.singletonList(vl.getProperty("name").get()));
this.sqlgGraph.tx().commit();
long t0 = System.currentTimeMillis();
List<Vertex> vts = this.sqlgGraph.traversal().V().hasLabel("Sentence").has("name", FullText.fullTextMatch("english", "fat & rat")).toList();
assertEquals(1, vts.size());
assertTrue(vts.contains(v0));
long t1 = System.currentTimeMillis();
long delta = t1 - t0;
System.out.println("query time:" + delta + "ms");
}
use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.
the class TestGremlinCompileFullTextPredicate method testConcat.
@Test
public void testConcat() throws SQLException {
assumeTrue(isPostgres());
Vertex v0 = this.sqlgGraph.addVertex(T.label, "Sentence", "name1", "a fat cat sat on a", "name2", "mat and ate a fat rat");
this.sqlgGraph.addVertex(T.label, "Sentence", "name1", "fatal error");
this.sqlgGraph.addVertex(T.label, "Sentence", "name1", "error is not fatal");
VertexLabel vl = this.sqlgGraph.getTopology().getVertexLabel("public", "Sentence").get();
vl.ensureIndexExists(IndexType.getFullTextGIN("english"), Arrays.asList(vl.getProperty("name1").get(), vl.getProperty("name2").get()));
this.sqlgGraph.tx().commit();
List<Vertex> vts = this.sqlgGraph.traversal().V().hasLabel("Sentence").where(FullText.fullTextMatch("english", false, Arrays.asList("name1", "name2"), "fat & rat")).toList();
assertEquals(1, vts.size());
assertTrue(vts.contains(v0));
}
use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.
the class SchemaTableTree method hasNoEdgeLabels.
private boolean hasNoEdgeLabels(SchemaTable schemaTable) {
Optional<Schema> schemaOptional = sqlgGraph.getTopology().getSchema(schemaTable.getSchema());
Preconditions.checkState(schemaOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.getSchema());
Schema schema = schemaOptional.get();
boolean result = true;
if (schemaTable.isVertexTable()) {
// Need to delete any in/out edges.
Optional<VertexLabel> vertexLabelOptional = schema.getVertexLabel(schemaTable.withOutPrefix().getTable());
Preconditions.checkState(vertexLabelOptional.isPresent(), "BUG: %s not found in the topology.", schemaTable.withOutPrefix().getTable());
VertexLabel vertexLabel = vertexLabelOptional.get();
Collection<EdgeLabel> outEdgeLabels = vertexLabel.getOutEdgeLabels().values();
Collection<EdgeLabel> inEdgeLabels = vertexLabel.getInEdgeLabels().values();
result = outEdgeLabels.isEmpty() && inEdgeLabels.isEmpty();
}
return result;
}
use of org.umlg.sqlg.structure.topology.VertexLabel in project sqlg by pietermartin.
the class SqlgDropStepBarrier method processNextStart.
@Override
protected Traverser.Admin<S> processNextStart() {
if (this.first) {
this.first = false;
EventStrategy eventStrategy = null;
if (!this.callbackRegistry.getCallbacks().isEmpty()) {
eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
}
while (this.starts.hasNext()) {
Traverser.Admin<S> start = this.starts.next();
Object object = start.get();
if (object instanceof SqlgElement) {
SqlgElement sqlgElement = (SqlgElement) object;
RecordId recordId = (RecordId) sqlgElement.id();
SchemaTable schemaTable = recordId.getSchemaTable();
Long id = recordId.getId();
if (sqlgElement instanceof SqlgVertex) {
Optional<VertexLabel> vertexLabelOptional = this.sqlgGraph.getTopology().getVertexLabel(schemaTable.getSchema(), schemaTable.getTable());
Preconditions.checkState(vertexLabelOptional.isPresent());
SqlgVertex sqlgVertex = (SqlgVertex) sqlgElement;
boolean added = this.verticesToDelete.put(vertexLabelOptional.get(), id);
if (added && eventStrategy != null) {
final Event removeEvent = new Event.VertexRemovedEvent(eventStrategy.detach(sqlgVertex));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
for (EdgeLabel outEdgeLabel : vertexLabelOptional.get().getOutEdgeLabels().values()) {
// Get all the edges, register to the callBack and delete.
if (eventStrategy != null) {
Iterator<Edge> edges = sqlgVertex.edges(Direction.OUT);
while (edges.hasNext()) {
Edge edge = edges.next();
SchemaTable schemaTableEdge = ((SqlgEdge) edge).getSchemaTablePrefixed().withOutPrefix();
Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable());
Preconditions.checkState(edgeLabelOptional.isPresent());
added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId) edge.id()).getId());
if (added) {
final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
}
} else {
this.foreignKeyOutEdgesToDelete.put(Pair.of(outEdgeLabel, vertexLabelOptional.get()), id);
}
}
for (EdgeLabel inEdgeLabel : vertexLabelOptional.get().getInEdgeLabels().values()) {
// Get all the edges, register to the callBack and delete.
if (!this.callbackRegistry.getCallbacks().isEmpty()) {
Iterator<Edge> edges = sqlgVertex.edges(Direction.IN);
while (edges.hasNext()) {
Edge edge = edges.next();
SchemaTable schemaTableEdge = ((SqlgEdge) edge).getSchemaTablePrefixed().withOutPrefix();
Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTableEdge.getSchema(), schemaTableEdge.getTable());
Preconditions.checkState(edgeLabelOptional.isPresent());
added = this.edgesToDelete.put(edgeLabelOptional.get(), ((RecordId) edge.id()).getId());
if (added) {
final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach(edge));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
}
} else {
this.foreignKeyInEdgesToDelete.put(Pair.of(inEdgeLabel, vertexLabelOptional.get()), id);
}
}
} else if (sqlgElement instanceof SqlgEdge) {
Optional<EdgeLabel> edgeLabelOptional = this.sqlgGraph.getTopology().getEdgeLabel(schemaTable.getSchema(), schemaTable.getTable());
Preconditions.checkState(edgeLabelOptional.isPresent());
boolean added = this.edgesToDelete.put(edgeLabelOptional.get(), id);
if (added && eventStrategy != null) {
final Event removeEvent = new Event.EdgeRemovedEvent(eventStrategy.detach((SqlgEdge) sqlgElement));
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
}
} else if (object instanceof SqlgProperty) {
SqlgProperty sqlgProperty = (SqlgProperty) object;
if (eventStrategy != null) {
final Event removeEvent;
if (sqlgProperty.element() instanceof Edge) {
removeEvent = new Event.EdgePropertyRemovedEvent(eventStrategy.detach((Edge) sqlgProperty.element()), eventStrategy.detach(sqlgProperty));
} else if (sqlgProperty instanceof VertexProperty)
removeEvent = new Event.VertexPropertyRemovedEvent(eventStrategy.detach((VertexProperty) sqlgProperty));
else
throw new IllegalStateException("The incoming object is not removable: " + object);
this.callbackRegistry.getCallbacks().forEach(c -> c.accept(removeEvent));
}
sqlgProperty.remove();
} else {
throw new IllegalStateException("Expected SqlgElement or SqlgProperty. Found " + object.getClass().getSimpleName());
}
}
}
for (Pair<EdgeLabel, VertexLabel> edgeLabelVertexLabelPair : this.foreignKeyOutEdgesToDelete.keySet()) {
EdgeLabel outEdgeLabel = edgeLabelVertexLabelPair.getKey();
VertexLabel vertexLabel = edgeLabelVertexLabelPair.getValue();
Collection<Long> ids = this.foreignKeyOutEdgesToDelete.get(edgeLabelVertexLabelPair);
String sql = this.sqlgGraph.getSqlDialect().dropWithForeignKey(true, outEdgeLabel, vertexLabel, ids, !this.callbackRegistry.getCallbacks().isEmpty());
SqlgSqlExecutor.executeDropEdges(this.sqlgGraph, outEdgeLabel, sql, this.callbackRegistry.getCallbacks());
}
for (Pair<EdgeLabel, VertexLabel> edgeLabelVertexLabelPair : this.foreignKeyInEdgesToDelete.keySet()) {
EdgeLabel inEdgeLabel = edgeLabelVertexLabelPair.getKey();
VertexLabel vertexLabel = edgeLabelVertexLabelPair.getValue();
Collection<Long> ids = this.foreignKeyInEdgesToDelete.get(edgeLabelVertexLabelPair);
String sql = this.sqlgGraph.getSqlDialect().dropWithForeignKey(false, inEdgeLabel, vertexLabel, ids, !this.callbackRegistry.getCallbacks().isEmpty());
SqlgSqlExecutor.executeDropEdges(this.sqlgGraph, inEdgeLabel, sql, this.callbackRegistry.getCallbacks());
}
for (EdgeLabel edgeLabel : this.edgesToDelete.keySet()) {
Collection<Long> ids = this.edgesToDelete.get(edgeLabel);
String sql = this.sqlgGraph.getSqlDialect().drop(edgeLabel, ids);
SqlgSqlExecutor.executeDrop(this.sqlgGraph, sql);
}
for (VertexLabel vertexLabel : this.verticesToDelete.keySet()) {
Collection<Long> ids = this.verticesToDelete.get(vertexLabel);
String sql = this.sqlgGraph.getSqlDialect().drop(vertexLabel, ids);
SqlgSqlExecutor.executeDrop(this.sqlgGraph, sql);
}
// The standard TraversalFilterStep.filter calls TraversalUtil.test which normally resets the traversal for every incoming start.
reset();
throw FastNoSuchElementException.instance();
}
Aggregations