use of com.thinkaurelius.titan.core.VertexList in project titan by thinkaurelius.
the class TitanGraphTest method testRelationTypeIndexes.
@Test
public void testRelationTypeIndexes() {
PropertyKey weight = makeKey("weight", Float.class);
PropertyKey time = makeKey("time", Long.class);
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.LIST).make();
EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(time).make();
EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make();
EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().make();
RelationTypeIndex name1 = mgmt.buildPropertyIndex(name, "weightDesc", weight);
RelationTypeIndex connect1 = mgmt.buildEdgeIndex(connect, "weightAsc", Direction.BOTH, incr, weight);
RelationTypeIndex connect2 = mgmt.buildEdgeIndex(connect, "weightDesc", Direction.OUT, decr, weight);
RelationTypeIndex connect3 = mgmt.buildEdgeIndex(connect, "time+weight", Direction.OUT, decr, time, weight);
RelationTypeIndex child1 = mgmt.buildEdgeIndex(child, "time", Direction.OUT, time);
RelationTypeIndex link1 = mgmt.buildEdgeIndex(link, "time", Direction.OUT, time);
final String name1n = name1.name(), connect1n = connect1.name(), connect2n = connect2.name(), connect3n = connect3.name(), child1n = child1.name(), link1n = link1.name();
// ########### INSPECTION & FAILURE ##############
assertTrue(mgmt.containsRelationIndex(name, "weightDesc"));
assertTrue(mgmt.containsRelationIndex(connect, "weightDesc"));
assertFalse(mgmt.containsRelationIndex(child, "weightDesc"));
assertEquals("time+weight", mgmt.getRelationIndex(connect, "time+weight").name());
assertNotNull(mgmt.getRelationIndex(link, "time"));
assertNull(mgmt.getRelationIndex(name, "time"));
assertEquals(1, size(mgmt.getRelationIndexes(child)));
assertEquals(3, size(mgmt.getRelationIndexes(connect)));
assertEquals(0, size(mgmt.getRelationIndexes(weight)));
try {
//Name already exists
mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time);
fail();
} catch (SchemaViolationException e) {
}
// } catch (IllegalArgumentException e) {}
try {
//Not valid in this direction due to multiplicity constraint
mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time);
fail();
} catch (IllegalArgumentException e) {
}
try {
//Not valid in this direction due to unidirectionality
mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
fail();
} catch (IllegalArgumentException e) {
}
// ########## END INSPECTION ###########
finishSchema();
weight = mgmt.getPropertyKey("weight");
time = mgmt.getPropertyKey("time");
name = mgmt.getPropertyKey("name");
connect = mgmt.getEdgeLabel("connect");
child = mgmt.getEdgeLabel("child");
link = mgmt.getEdgeLabel("link");
// ########### INSPECTION & FAILURE (copied from above) ##############
assertTrue(mgmt.containsRelationIndex(name, "weightDesc"));
assertTrue(mgmt.containsRelationIndex(connect, "weightDesc"));
assertFalse(mgmt.containsRelationIndex(child, "weightDesc"));
assertEquals("time+weight", mgmt.getRelationIndex(connect, "time+weight").name());
assertNotNull(mgmt.getRelationIndex(link, "time"));
assertNull(mgmt.getRelationIndex(name, "time"));
assertEquals(1, Iterables.size(mgmt.getRelationIndexes(child)));
assertEquals(3, Iterables.size(mgmt.getRelationIndexes(connect)));
assertEquals(0, Iterables.size(mgmt.getRelationIndexes(weight)));
try {
//Name already exists
mgmt.buildEdgeIndex(connect, "weightAsc", Direction.OUT, time);
fail();
} catch (SchemaViolationException e) {
}
// } catch (IllegalArgumentException e) {}
try {
//Not valid in this direction due to multiplicity constraint
mgmt.buildEdgeIndex(child, "blablub", Direction.IN, time);
fail();
} catch (IllegalArgumentException e) {
}
try {
//Not valid in this direction due to unidirectionality
mgmt.buildEdgeIndex(link, "blablub", Direction.BOTH, time);
fail();
} catch (IllegalArgumentException e) {
}
// ########## END INSPECTION ###########
mgmt.rollback();
/*
########## TEST WITHIN TRANSACTION ##################
*/
weight = tx.getPropertyKey("weight");
time = tx.getPropertyKey("time");
final int numV = 100;
TitanVertex v = tx.addVertex();
TitanVertex[] ns = new TitanVertex[numV];
for (int i = 0; i < numV; i++) {
double w = (i * 0.5) % 5;
long t = (i + 77) % numV;
VertexProperty p = v.property("name", "v" + i, "weight", w, "time", t);
ns[i] = tx.addVertex();
for (String label : new String[] { "connect", "child", "link" }) {
Edge e = v.addEdge(label, ns[i], "weight", w, "time", t);
}
}
TitanVertex u = ns[0];
VertexList vl;
//######### QUERIES ##########
v = getV(tx, v);
u = getV(tx, u);
evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().keys("name").has("weight", Cmp.LESS_THAN, 0.9).orderBy("weight", incr), PROPERTY, 2 * numV / 10, 1, new boolean[] { true, true }, weight, Order.ASC);
evaluateQuery(v.query().keys("name").interval("weight", 1.1, 2.2).orderBy("weight", decr).limit(numV / 10), PROPERTY, numV / 10, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query().keys("name").has("time", Cmp.EQUAL, 5).orderBy("weight", decr), PROPERTY, 1, 1, new boolean[] { false, false }, weight, Order.DESC);
evaluateQuery(v.query().keys("name"), PROPERTY, numV, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(BOTH).has("time", Cmp.EQUAL, 5), EDGE, 1, 2, new boolean[0]);
evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query().labels("child").direction(BOTH).interval("weight", 0.0, 1.0).orderBy("weight", decr), EDGE, 2 * numV / 10, 2, new boolean[] { false, false }, weight, Order.DESC);
evaluateQuery(v.query().labels("child").direction(OUT).interval("weight", 0.0, 1.0), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("child").direction(BOTH), EDGE, numV, 1, new boolean[] { true, true });
vl = v.query().labels("child").direction(BOTH).vertexIds();
assertEquals(numV, vl.size());
assertTrue(vl.isSorted());
assertTrue(isSortedByID(vl));
evaluateQuery(v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
vl = v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT).vertexIds();
assertEquals(2 * numV / 10, vl.size());
assertTrue(vl.isSorted());
assertTrue(isSortedByID(vl));
evaluateQuery(v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr), EDGE, 10, 1, new boolean[] { true, true }, time, Order.ASC);
vl = v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr).vertexIds();
assertEquals(10, vl.size());
assertFalse(vl.isSorted());
assertFalse(isSortedByID(vl));
vl.sort();
assertTrue(vl.isSorted());
assertTrue(isSortedByID(vl));
evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(BOTH), EDGE, 1, 2, new boolean[0]);
evaluateQuery(v.query().labels("connect").interval("time", 10, 20).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", incr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.ASC);
evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", decr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.DESC);
evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 1.4, 2.75).orderBy("weight", decr), EDGE, 3 * numV / 10, 1, new boolean[] { true, true }, weight, Order.DESC);
evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", decr), EDGE, 1, 1, new boolean[] { true, true }, weight, Order.DESC);
evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", incr), EDGE, 1, 1, new boolean[] { true, false }, weight, Order.ASC);
evaluateQuery(v.query().labels("connect").direction(OUT).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").direction(OUT).has("weight", Cmp.EQUAL, 0.0).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 0.0, 1.0).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 50, 100).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
//--------------
clopen();
weight = tx.getPropertyKey("weight");
time = tx.getPropertyKey("time");
//######### QUERIES (copied from above) ##########
v = getV(tx, v);
u = getV(tx, u);
evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().keys("name").has("weight", Cmp.LESS_THAN, 0.9).orderBy("weight", incr), PROPERTY, 2 * numV / 10, 1, new boolean[] { true, true }, weight, Order.ASC);
evaluateQuery(v.query().keys("name").interval("weight", 1.1, 2.2).orderBy("weight", decr).limit(numV / 10), PROPERTY, numV / 10, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query().keys("name").has("time", Cmp.EQUAL, 5).orderBy("weight", decr), PROPERTY, 1, 1, new boolean[] { false, false }, weight, Order.DESC);
evaluateQuery(v.query().keys("name"), PROPERTY, numV, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(BOTH).has("time", Cmp.EQUAL, 5), EDGE, 1, 2, new boolean[0]);
evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query().labels("child").direction(BOTH).interval("weight", 0.0, 1.0).orderBy("weight", decr), EDGE, 2 * numV / 10, 2, new boolean[] { false, false }, weight, Order.DESC);
evaluateQuery(v.query().labels("child").direction(OUT).interval("weight", 0.0, 1.0), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("child").direction(BOTH), EDGE, numV, 1, new boolean[] { true, true });
vl = v.query().labels("child").direction(BOTH).vertexIds();
assertEquals(numV, vl.size());
assertTrue(vl.isSorted());
assertTrue(isSortedByID(vl));
evaluateQuery(v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT), EDGE, 2 * numV / 10, 1, new boolean[] { false, true });
vl = v.query().labels("child").interval("weight", 0.0, 1.0).direction(OUT).vertexIds();
assertEquals(2 * numV / 10, vl.size());
assertTrue(vl.isSorted());
assertTrue(isSortedByID(vl));
evaluateQuery(v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr), EDGE, 10, 1, new boolean[] { true, true }, time, Order.ASC);
vl = v.query().labels("child").interval("time", 70, 80).direction(OUT).orderBy("time", incr).vertexIds();
assertEquals(10, vl.size());
assertFalse(vl.isSorted());
assertFalse(isSortedByID(vl));
vl.sort();
assertTrue(vl.isSorted());
assertTrue(isSortedByID(vl));
evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").has("time", Cmp.EQUAL, 5).interval("weight", 0.0, 5.0).direction(BOTH), EDGE, 1, 2, new boolean[0]);
evaluateQuery(v.query().labels("connect").interval("time", 10, 20).interval("weight", 0.0, 5.0).direction(OUT), EDGE, 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", incr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.ASC);
evaluateQuery(v.query().labels("connect").direction(OUT).orderBy("weight", decr).limit(10), EDGE, 10, 1, new boolean[] { true, true }, weight, Order.DESC);
evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 1.4, 2.75).orderBy("weight", decr), EDGE, 3 * numV / 10, 1, new boolean[] { true, true }, weight, Order.DESC);
evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", decr), EDGE, 1, 1, new boolean[] { true, true }, weight, Order.DESC);
evaluateQuery(v.query().labels("connect").direction(OUT).has("time", Cmp.EQUAL, 22).orderBy("weight", incr), EDGE, 1, 1, new boolean[] { true, false }, weight, Order.ASC);
evaluateQuery(v.query().labels("connect").direction(OUT).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").direction(OUT).has("weight", Cmp.EQUAL, 0.0).adjacent(u), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").direction(OUT).interval("weight", 0.0, 1.0).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 50, 100).adjacent(u), EDGE, 1, 1, new boolean[] { false, true });
evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
//Update in transaction
for (TitanVertexProperty<String> p : v.query().labels("name").properties()) {
if (p.<Long>value("time") < (numV / 2))
p.remove();
}
for (TitanEdge e : v.query().direction(BOTH).edges()) {
if (e.<Long>value("time") < (numV / 2))
e.remove();
}
ns = new TitanVertex[numV * 3 / 2];
for (int i = numV; i < numV * 3 / 2; i++) {
double w = (i * 0.5) % 5;
long t = i;
v.property("name", "v" + i, "weight", w, "time", t);
ns[i] = tx.addVertex();
for (String label : new String[] { "connect", "child", "link" }) {
TitanEdge e = v.addEdge(label, ns[i], "weight", w, "time", t);
}
}
//######### UPDATED QUERIES ##########
evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10), PROPERTY, 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10).orderBy("weight", decr), PROPERTY, 10, 1, new boolean[] { false, false }, weight, Order.DESC);
evaluateQuery(v.query().keys("name").interval("time", numV, numV + 10).limit(5), PROPERTY, 5, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 0, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, numV + 5), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 0, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query().labels("child").direction(OUT).interval("time", numV + 10, numV + 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
//######### END UPDATED QUERIES ##########
newTx();
weight = tx.getPropertyKey("weight");
time = tx.getPropertyKey("time");
v = getV(tx, v);
u = getV(tx, u);
//######### UPDATED QUERIES (copied from above) ##########
evaluateQuery(v.query().keys("name").has("weight", Cmp.GREATER_THAN, 3.6), PROPERTY, 2 * numV / 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10), PROPERTY, 10, 1, new boolean[] { false, true });
evaluateQuery(v.query().keys("name").interval("time", numV / 2 - 10, numV / 2 + 10).orderBy("weight", decr), PROPERTY, 10, 1, new boolean[] { false, false }, weight, Order.DESC);
evaluateQuery(v.query().keys("name").interval("time", numV, numV + 10).limit(5), PROPERTY, 5, 1, new boolean[] { false, true });
evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, 5), EDGE, 0, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(OUT).has("time", Cmp.EQUAL, numV + 5), EDGE, 1, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("child").direction(OUT).interval("time", 10, 20).orderBy("weight", decr).limit(5), EDGE, 0, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query().labels("child").direction(OUT).interval("time", numV + 10, numV + 20).orderBy("weight", decr).limit(5), EDGE, 5, 1, new boolean[] { true, false }, weight, Order.DESC);
evaluateQuery(v.query(), RELATION, numV * 4, 1, new boolean[] { true, true });
evaluateQuery(v.query().direction(OUT), RELATION, numV * 4, 1, new boolean[] { false, true });
//######### END UPDATED QUERIES ##########
}
use of com.thinkaurelius.titan.core.VertexList in project titan by thinkaurelius.
the class SpeedComparisonPerformanceTest method retrieveNgh.
public void retrieveNgh(boolean inMemory) {
long time = time();
Vertex[] vertices = new TitanVertex[numVertices];
for (int i = 0; i < numVertices; i++) vertices[i] = graph.getVertices("uid", i).iterator().next();
time = time() - time;
for (int t = 0; t < 4; t++) {
time = time();
for (int i = 0; i < numVertices; i++) {
TitanVertexQuery q = ((TitanVertexQuery) vertices[i].query()).direction(Direction.OUT).labels("connect");
if (inMemory) {
// TODO: this has been disabled
for (Vertex v : q.vertices()) {
v.getId();
}
} else {
VertexList vl = q.vertexIds();
for (int j = 0; j < vl.size(); j++) {
vl.get(j);
}
}
}
time = time() - time;
System.out.println("Ngh retrieval: " + time);
}
graph.commit();
}
use of com.thinkaurelius.titan.core.VertexList in project titan by thinkaurelius.
the class TitanGraphTest method testVertexCentricQuery.
/* ==================================================================================
VERTEX CENTRIC QUERIES
==================================================================================*/
@Test
@SuppressWarnings("deprecation")
public void testVertexCentricQuery() {
makeVertexIndexedUniqueKey("name", String.class);
PropertyKey time = makeKey("time", Integer.class);
PropertyKey weight = makeKey("weight", Double.class);
PropertyKey number = makeKey("number", Long.class);
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("connect")).sortKey(time).make();
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("connectDesc")).sortKey(time).sortOrder(Order.DESC).make();
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("friend")).sortKey(weight, time).sortOrder(Order.ASC).signature(number).make();
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("friendDesc")).sortKey(weight, time).sortOrder(Order.DESC).signature(number).make();
((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(number, weight).make();
mgmt.makeEdgeLabel("follows").make();
finishSchema();
TitanVertex v = tx.addVertex("name", "v");
TitanVertex u = tx.addVertex("name", "u");
int noVertices = 10000;
assertEquals(0, (noVertices - 1) % 3);
TitanVertex[] vs = new TitanVertex[noVertices];
for (int i = 1; i < noVertices; i++) {
vs[i] = tx.addVertex("name", "v" + i);
}
EdgeLabel[] labelsV = { tx.getEdgeLabel("connect"), tx.getEdgeLabel("friend"), tx.getEdgeLabel("knows") };
EdgeLabel[] labelsU = { tx.getEdgeLabel("connectDesc"), tx.getEdgeLabel("friendDesc"), tx.getEdgeLabel("knows") };
for (int i = 1; i < noVertices; i++) {
for (TitanVertex vertex : new TitanVertex[] { v, u }) {
for (Direction d : new Direction[] { OUT, IN }) {
EdgeLabel label = vertex == v ? labelsV[i % 3] : labelsU[i % 3];
TitanEdge e = d == OUT ? vertex.addEdge(n(label), vs[i]) : vs[i].addEdge(n(label), vertex);
e.property("time", i);
e.property("weight", i % 4 + 0.5);
e.property("name", "e" + i);
e.property("number", i % 5);
}
}
}
int edgesPerLabel = noVertices / 3;
VertexList vl;
Map<TitanVertex, Iterable<TitanEdge>> results;
Map<TitanVertex, Iterable<TitanVertexProperty>> results2;
TitanVertex[] qvs;
int lastTime;
Iterator<? extends Edge> outer;
clopen();
long[] vidsubset = new long[31 - 3];
for (int i = 0; i < vidsubset.length; i++) vidsubset[i] = vs[i + 3].longId();
Arrays.sort(vidsubset);
//##################################################
//Queries from Cache
//##################################################
clopen();
for (int i = 1; i < noVertices; i++) vs[i] = getV(tx, vs[i].longId());
v = getV(tx, v.longId());
u = getV(tx, u.longId());
qvs = new TitanVertex[] { vs[6], vs[9], vs[12], vs[15], vs[60] };
//To trigger queries from cache (don't copy!!!)
assertCount(2 * (noVertices - 1), v.query().direction(Direction.BOTH).edges());
assertEquals(1, v.query().propertyCount());
assertEquals(10, size(v.query().labels("connect").limit(10).vertices()));
assertEquals(10, size(u.query().labels("connectDesc").limit(10).vertices()));
assertEquals(10, size(v.query().labels("connect").has("time", Cmp.GREATER_THAN, 30).limit(10).vertices()));
assertEquals(10, size(u.query().labels("connectDesc").has("time", Cmp.GREATER_THAN, 30).limit(10).vertices()));
lastTime = 0;
for (TitanEdge e : (Iterable<TitanEdge>) v.query().labels("connect").direction(OUT).limit(20).edges()) {
int nowTime = e.value("time");
assertTrue(lastTime + " vs. " + nowTime, lastTime <= nowTime);
lastTime = nowTime;
}
lastTime = Integer.MAX_VALUE;
for (Edge e : (Iterable<TitanEdge>) u.query().labels("connectDesc").direction(OUT).limit(20).edges()) {
int nowTime = e.value("time");
assertTrue(lastTime + " vs. " + nowTime, lastTime >= nowTime);
lastTime = nowTime;
}
assertEquals(10, size(v.query().labels("connect").direction(OUT).has("time", Cmp.GREATER_THAN, 60).limit(10).vertices()));
assertEquals(10, size(u.query().labels("connectDesc").direction(OUT).has("time", Cmp.GREATER_THAN, 60).limit(10).vertices()));
outer = v.query().labels("connect").direction(OUT).limit(20).edges().iterator();
for (Edge e : (Iterable<TitanEdge>) v.query().labels("connect").direction(OUT).limit(10).edges()) {
assertEquals(e, outer.next());
}
evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 3, 31), EDGE, 10, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").direction(OUT).has("time", 15).has("weight", 3.5), EDGE, 1, 1, new boolean[] { false, true });
evaluateQuery(u.query().labels("connectDesc").direction(OUT).interval("time", 3, 31), EDGE, 10, 1, new boolean[] { true, true });
assertEquals(10, v.query().labels("connect").direction(IN).interval("time", 3, 31).edgeCount());
assertEquals(10, u.query().labels("connectDesc").direction(IN).interval("time", 3, 31).edgeCount());
assertEquals(0, v.query().labels("connect").direction(OUT).has("time", null).edgeCount());
assertEquals(10, v.query().labels("connect").direction(OUT).interval("time", 3, 31).vertexIds().size());
assertEquals(edgesPerLabel - 10, v.query().labels("connect").direction(OUT).has("time", Cmp.GREATER_THAN, 31).count());
assertEquals(10, size(v.query().labels("connect").direction(OUT).interval("time", 3, 31).vertices()));
assertEquals(3, v.query().labels("friend").direction(OUT).limit(3).count());
evaluateQuery(v.query().labels("friend").direction(OUT).has("weight", 0.5).limit(3), EDGE, 3, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 3, 33).has("weight", 0.5), EDGE, 3, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 3, 33).has("weight", Contain.IN, ImmutableList.of(0.5)), EDGE, 3, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).has("weight", Contain.IN, ImmutableList.of(0.5, 1.5, 2.5)).interval("time", 3, 33), EDGE, 7, 3, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).has("weight", Contain.IN, ImmutableList.of(0.5, 1.5)), EDGE, 1667, 2, new boolean[] { true, true });
assertEquals(3, u.query().labels("friendDesc").direction(OUT).interval("time", 3, 33).has("weight", 0.5).edgeCount());
assertEquals(1, v.query().labels("friend").direction(OUT).has("weight", 0.5).interval("time", 4, 10).edgeCount());
assertEquals(1, u.query().labels("friendDesc").direction(OUT).has("weight", 0.5).interval("time", 4, 10).edgeCount());
assertEquals(3, v.query().labels("friend").direction(OUT).interval("time", 3, 33).has("weight", 0.5).edgeCount());
assertEquals(4, v.query().labels("friend").direction(OUT).has("time", Cmp.LESS_THAN_EQUAL, 10).edgeCount());
assertEquals(edgesPerLabel - 4, v.query().labels("friend").direction(OUT).has("time", Cmp.GREATER_THAN, 10).edgeCount());
assertEquals(20, v.query().labels("friend", "connect").direction(OUT).interval("time", 3, 33).edgeCount());
assertEquals((int) Math.ceil(edgesPerLabel / 5.0), v.query().labels("knows").direction(OUT).has("number", 0).edgeCount());
assertEquals((int) Math.ceil(edgesPerLabel / 5.0), v.query().labels("knows").direction(OUT).has("number", 0).interval("weight", 0.0, 4.0).edgeCount());
assertEquals((int) Math.ceil(edgesPerLabel / (5.0 * 2)), v.query().labels("knows").direction(OUT).has("number", 0).interval("weight", 0.0, 2.0).edgeCount());
assertEquals((int) Math.floor(edgesPerLabel / (5.0 * 2)), v.query().labels("knows").direction(OUT).has("number", 0).interval("weight", 2.1, 4.0).edgeCount());
assertEquals(20, size(v.query().labels("connect", "friend").direction(OUT).interval("time", 3, 33).vertices()));
assertEquals(20, size(v.query().labels("connect", "friend").direction(OUT).interval("time", 3, 33).vertexIds()));
assertEquals(30, v.query().labels("friend", "connect", "knows").direction(OUT).interval("time", 3, 33).edgeCount());
assertEquals(noVertices - 2, v.query().labels("friend", "connect", "knows").direction(OUT).has("time", Cmp.NOT_EQUAL, 10).edgeCount());
assertEquals(0, v.query().has("age", null).labels("undefined").direction(OUT).edgeCount());
assertEquals(1, v.query().labels("connect").direction(OUT).adjacent(vs[6]).has("time", 6).edgeCount());
assertEquals(1, v.query().labels("knows").direction(OUT).adjacent(vs[11]).edgeCount());
assertEquals(1, v.query().labels("knows").direction(IN).adjacent(vs[11]).edgeCount());
assertEquals(2, v.query().labels("knows").direction(BOTH).adjacent(vs[11]).edgeCount());
assertEquals(1, v.query().labels("knows").direction(OUT).adjacent(vs[11]).has("weight", 3.5).edgeCount());
assertEquals(2, v.query().labels("connect").adjacent(vs[6]).has("time", 6).edgeCount());
assertEquals(0, v.query().labels("connect").adjacent(vs[8]).has("time", 8).edgeCount());
assertEquals(edgesPerLabel, v.query().labels("connect").direction(OUT).edgeCount());
assertEquals(edgesPerLabel, v.query().labels("connect").direction(IN).edgeCount());
assertEquals(2 * edgesPerLabel, v.query().labels("connect").direction(BOTH).edgeCount());
assertEquals(edgesPerLabel, v.query().labels("connect").has("undefined", null).direction(OUT).edgeCount());
assertEquals(2 * (int) Math.ceil((noVertices - 1) / 4.0), size(v.query().labels("connect", "friend", "knows").has("weight", 1.5).vertexIds()));
assertEquals(1, v.query().direction(IN).has("time", 1).edgeCount());
assertEquals(10, v.query().direction(OUT).interval("time", 4, 14).edgeCount());
assertEquals(9, v.query().direction(IN).interval("time", 4, 14).has("time", Cmp.NOT_EQUAL, 10).edgeCount());
assertEquals(9, v.query().direction(OUT).interval("time", 4, 14).has("time", Cmp.NOT_EQUAL, 10).edgeCount());
assertEquals(noVertices - 1, size(v.query().direction(OUT).vertices()));
assertEquals(noVertices - 1, size(v.query().direction(IN).vertices()));
for (Direction dir : new Direction[] { IN, OUT }) {
vl = v.query().labels().direction(dir).interval("time", 3, 31).vertexIds();
vl.sort();
for (int i = 0; i < vl.size(); i++) assertEquals(vidsubset[i], vl.getID(i));
}
assertCount(2 * (noVertices - 1), v.query().direction(Direction.BOTH).edges());
//Property queries
assertEquals(1, size(v.query().properties()));
assertEquals(1, size(v.query().keys("name").properties()));
//MultiQueries
results = tx.multiQuery(qvs).direction(IN).labels("connect").edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(1, size(result));
results = tx.multiQuery(Sets.newHashSet(qvs)).labels("connect").edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(2, size(result));
results = tx.multiQuery(qvs).labels("knows").edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(0, size(result));
results = tx.multiQuery(qvs).edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(4, size(result));
results2 = tx.multiQuery(qvs).properties();
for (Iterable<TitanVertexProperty> result : results2.values()) assertEquals(1, size(result));
results2 = tx.multiQuery(qvs).keys("name").properties();
for (Iterable<TitanVertexProperty> result : results2.values()) assertEquals(1, size(result));
//##################################################
//Same queries as above but without memory loading (i.e. omitting the first query)
//##################################################
clopen();
for (int i = 1; i < noVertices; i++) vs[i] = getV(tx, vs[i].longId());
v = getV(tx, v.longId());
u = getV(tx, u.longId());
qvs = new TitanVertex[] { vs[6], vs[9], vs[12], vs[15], vs[60] };
assertEquals(10, size(v.query().labels("connect").limit(10).vertices()));
assertEquals(10, size(u.query().labels("connectDesc").limit(10).vertices()));
assertEquals(10, size(v.query().labels("connect").has("time", Cmp.GREATER_THAN, 30).limit(10).vertices()));
assertEquals(10, size(u.query().labels("connectDesc").has("time", Cmp.GREATER_THAN, 30).limit(10).vertices()));
lastTime = 0;
for (Edge e : (Iterable<TitanEdge>) v.query().labels("connect").direction(OUT).limit(20).edges()) {
int nowTime = e.value("time");
assertTrue(lastTime + " vs. " + nowTime, lastTime <= nowTime);
lastTime = nowTime;
}
lastTime = Integer.MAX_VALUE;
for (Edge e : (Iterable<TitanEdge>) u.query().labels("connectDesc").direction(OUT).limit(20).edges()) {
int nowTime = e.value("time");
assertTrue(lastTime + " vs. " + nowTime, lastTime >= nowTime);
lastTime = nowTime;
}
assertEquals(10, size(v.query().labels("connect").direction(OUT).has("time", Cmp.GREATER_THAN, 60).limit(10).vertices()));
assertEquals(10, size(u.query().labels("connectDesc").direction(OUT).has("time", Cmp.GREATER_THAN, 60).limit(10).vertices()));
outer = v.query().labels("connect").direction(OUT).limit(20).edges().iterator();
for (Edge e : (Iterable<TitanEdge>) v.query().labels("connect").direction(OUT).limit(10).edges()) {
assertEquals(e, outer.next());
}
evaluateQuery(v.query().labels("connect").direction(OUT).interval("time", 3, 31), EDGE, 10, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("connect").direction(OUT).has("time", 15).has("weight", 3.5), EDGE, 1, 1, new boolean[] { false, true });
evaluateQuery(u.query().labels("connectDesc").direction(OUT).interval("time", 3, 31), EDGE, 10, 1, new boolean[] { true, true });
assertEquals(10, v.query().labels("connect").direction(IN).interval("time", 3, 31).edgeCount());
assertEquals(10, u.query().labels("connectDesc").direction(IN).interval("time", 3, 31).edgeCount());
assertEquals(0, v.query().labels("connect").direction(OUT).has("time", null).edgeCount());
assertEquals(10, v.query().labels("connect").direction(OUT).interval("time", 3, 31).vertexIds().size());
assertEquals(edgesPerLabel - 10, v.query().labels("connect").direction(OUT).has("time", Cmp.GREATER_THAN, 31).count());
assertEquals(10, size(v.query().labels("connect").direction(OUT).interval("time", 3, 31).vertices()));
assertEquals(3, v.query().labels("friend").direction(OUT).limit(3).count());
evaluateQuery(v.query().labels("friend").direction(OUT).has("weight", 0.5).limit(3), EDGE, 3, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 3, 33).has("weight", 0.5), EDGE, 3, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).interval("time", 3, 33).has("weight", Contain.IN, ImmutableList.of(0.5)), EDGE, 3, 1, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).has("weight", Contain.IN, ImmutableList.of(0.5, 1.5, 2.5)).interval("time", 3, 33), EDGE, 7, 3, new boolean[] { true, true });
evaluateQuery(v.query().labels("friend").direction(OUT).has("weight", Contain.IN, ImmutableList.of(0.5, 1.5)), EDGE, 1667, 2, new boolean[] { true, true });
assertEquals(3, u.query().labels("friendDesc").direction(OUT).interval("time", 3, 33).has("weight", 0.5).edgeCount());
assertEquals(1, v.query().labels("friend").direction(OUT).has("weight", 0.5).interval("time", 4, 10).edgeCount());
assertEquals(1, u.query().labels("friendDesc").direction(OUT).has("weight", 0.5).interval("time", 4, 10).edgeCount());
assertEquals(3, v.query().labels("friend").direction(OUT).interval("time", 3, 33).has("weight", 0.5).edgeCount());
assertEquals(4, v.query().labels("friend").direction(OUT).has("time", Cmp.LESS_THAN_EQUAL, 10).edgeCount());
assertEquals(edgesPerLabel - 4, v.query().labels("friend").direction(OUT).has("time", Cmp.GREATER_THAN, 10).edgeCount());
assertEquals(20, v.query().labels("friend", "connect").direction(OUT).interval("time", 3, 33).edgeCount());
assertEquals((int) Math.ceil(edgesPerLabel / 5.0), v.query().labels("knows").direction(OUT).has("number", 0).edgeCount());
assertEquals((int) Math.ceil(edgesPerLabel / 5.0), v.query().labels("knows").direction(OUT).has("number", 0).interval("weight", 0.0, 4.0).edgeCount());
assertEquals((int) Math.ceil(edgesPerLabel / (5.0 * 2)), v.query().labels("knows").direction(OUT).has("number", 0).interval("weight", 0.0, 2.0).edgeCount());
assertEquals((int) Math.floor(edgesPerLabel / (5.0 * 2)), v.query().labels("knows").direction(OUT).has("number", 0).interval("weight", 2.1, 4.0).edgeCount());
assertEquals(20, size(v.query().labels("connect", "friend").direction(OUT).interval("time", 3, 33).vertices()));
assertEquals(20, size(v.query().labels("connect", "friend").direction(OUT).interval("time", 3, 33).vertexIds()));
assertEquals(30, v.query().labels("friend", "connect", "knows").direction(OUT).interval("time", 3, 33).edgeCount());
assertEquals(noVertices - 2, v.query().labels("friend", "connect", "knows").direction(OUT).has("time", Cmp.NOT_EQUAL, 10).edgeCount());
assertEquals(0, v.query().has("age", null).labels("undefined").direction(OUT).edgeCount());
assertEquals(1, v.query().labels("connect").direction(OUT).adjacent(vs[6]).has("time", 6).edgeCount());
assertEquals(1, v.query().labels("knows").direction(OUT).adjacent(vs[11]).edgeCount());
assertEquals(1, v.query().labels("knows").direction(IN).adjacent(vs[11]).edgeCount());
assertEquals(2, v.query().labels("knows").direction(BOTH).adjacent(vs[11]).edgeCount());
assertEquals(1, v.query().labels("knows").direction(OUT).adjacent(vs[11]).has("weight", 3.5).edgeCount());
assertEquals(2, v.query().labels("connect").adjacent(vs[6]).has("time", 6).edgeCount());
assertEquals(0, v.query().labels("connect").adjacent(vs[8]).has("time", 8).edgeCount());
assertEquals(edgesPerLabel, v.query().labels("connect").direction(OUT).edgeCount());
assertEquals(edgesPerLabel, v.query().labels("connect").direction(IN).edgeCount());
assertEquals(2 * edgesPerLabel, v.query().labels("connect").direction(BOTH).edgeCount());
assertEquals(edgesPerLabel, v.query().labels("connect").has("undefined", null).direction(OUT).edgeCount());
assertEquals(2 * (int) Math.ceil((noVertices - 1) / 4.0), size(v.query().labels("connect", "friend", "knows").has("weight", 1.5).vertexIds()));
assertEquals(1, v.query().direction(IN).has("time", 1).edgeCount());
assertEquals(10, v.query().direction(OUT).interval("time", 4, 14).edgeCount());
assertEquals(9, v.query().direction(IN).interval("time", 4, 14).has("time", Cmp.NOT_EQUAL, 10).edgeCount());
assertEquals(9, v.query().direction(OUT).interval("time", 4, 14).has("time", Cmp.NOT_EQUAL, 10).edgeCount());
assertEquals(noVertices - 1, size(v.query().direction(OUT).vertices()));
assertEquals(noVertices - 1, size(v.query().direction(IN).vertices()));
for (Direction dir : new Direction[] { IN, OUT }) {
vl = v.query().labels().direction(dir).interval("time", 3, 31).vertexIds();
vl.sort();
for (int i = 0; i < vl.size(); i++) assertEquals(vidsubset[i], vl.getID(i));
}
assertCount(2 * (noVertices - 1), v.query().direction(Direction.BOTH).edges());
//Property queries
assertEquals(1, size(v.query().properties()));
assertEquals(1, size(v.query().keys("name").properties()));
//MultiQueries
results = tx.multiQuery(qvs).direction(IN).labels("connect").edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(1, size(result));
results = tx.multiQuery(Sets.newHashSet(qvs)).labels("connect").edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(2, size(result));
results = tx.multiQuery(qvs).labels("knows").edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(0, size(result));
results = tx.multiQuery(qvs).edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(4, size(result));
results2 = tx.multiQuery(qvs).properties();
for (Iterable<TitanVertexProperty> result : results2.values()) assertEquals(1, size(result));
results2 = tx.multiQuery(qvs).keys("name").properties();
for (Iterable<TitanVertexProperty> result : results2.values()) assertEquals(1, size(result));
//##################################################
//End copied queries
//##################################################
newTx();
v = getOnlyElement(tx.query().has("name", "v").vertices());
assertNotNull(v);
assertEquals(2, v.query().has("weight", 1.5).interval("time", 10, 30).limit(2).vertexIds().size());
assertEquals(10, v.query().has("weight", 1.5).interval("time", 10, 30).vertexIds().size());
newTx();
v = getOnlyElement(tx.query().has("name", "v").vertices());
assertNotNull(v);
assertEquals(2, v.query().has("weight", 1.5).interval("time", 10, 30).limit(2).edgeCount());
assertEquals(10, v.query().has("weight", 1.5).interval("time", 10, 30).edgeCount());
newTx();
//Test partially new vertex queries
TitanVertex[] qvs2 = new TitanVertex[qvs.length + 2];
qvs2[0] = tx.addVertex();
for (int i = 0; i < qvs.length; i++) qvs2[i + 1] = getV(tx, qvs[i].longId());
qvs2[qvs2.length - 1] = tx.addVertex();
qvs2[0].addEdge("connect", qvs2[qvs2.length - 1]);
qvs2[qvs2.length - 1].addEdge("connect", qvs2[0]);
results = tx.multiQuery(qvs2).direction(IN).labels("connect").edges();
for (Iterable<TitanEdge> result : results.values()) assertEquals(1, size(result));
}
Aggregations