use of com.thinkaurelius.titan.graphdb.internal.OrderList in project titan by thinkaurelius.
the class TitanGraphTest method evaluateQuery.
public static void evaluateQuery(TitanGraphQuery query, ElementCategory resultType, int expectedResults, boolean[] subQuerySpecs, Map<PropertyKey, Order> orderMap, String... intersectingIndexes) {
if (intersectingIndexes == null)
intersectingIndexes = new String[0];
SimpleQueryProfiler profiler = new SimpleQueryProfiler();
((GraphCentricQueryBuilder) query).profiler(profiler);
Iterable<? extends TitanElement> result;
switch(resultType) {
case PROPERTY:
result = query.properties();
break;
case EDGE:
result = query.edges();
break;
case VERTEX:
result = query.vertices();
break;
default:
throw new AssertionError();
}
OrderList orders = profiler.getAnnotation(QueryProfiler.ORDERS_ANNOTATION);
//Check elements and that they are returned in the correct order
int no = 0;
TitanElement previous = null;
for (TitanElement e : result) {
assertNotNull(e);
no++;
if (previous != null && !orders.isEmpty()) {
assertTrue(orders.compare(previous, e) <= 0);
}
previous = e;
}
assertEquals(expectedResults, no);
//Check OrderList of query
assertNotNull(orders);
assertEquals(orderMap.size(), orders.size());
for (int i = 0; i < orders.size(); i++) {
assertEquals(orderMap.get(orders.getKey(i)), orders.getOrder(i));
}
for (PropertyKey key : orderMap.keySet()) assertTrue(orders.containsKey(key));
//Check subqueries
SimpleQueryProfiler subp = Iterables.getOnlyElement(Iterables.filter(profiler, p -> !p.getGroupName().equals(QueryProfiler.OPTIMIZATION)));
if (subQuerySpecs.length == 2) {
//0=>fitted, 1=>ordered
assertEquals(subQuerySpecs[0], (Boolean) subp.getAnnotation(QueryProfiler.FITTED_ANNOTATION));
assertEquals(subQuerySpecs[1], (Boolean) subp.getAnnotation(QueryProfiler.ORDERED_ANNOTATION));
}
Set<String> indexNames = new HashSet<>();
int indexQueries = 0;
boolean fullscan = false;
for (SimpleQueryProfiler indexp : subp) {
if (indexp.getAnnotation(QueryProfiler.FULLSCAN_ANNOTATION) != null) {
fullscan = true;
} else {
indexNames.add(indexp.getAnnotation(QueryProfiler.INDEX_ANNOTATION));
indexQueries++;
}
}
if (indexQueries > 0)
assertFalse(fullscan);
if (fullscan)
assertTrue(intersectingIndexes.length == 0);
assertEquals(intersectingIndexes.length, indexQueries);
assertEquals(Sets.newHashSet(intersectingIndexes), indexNames);
}
use of com.thinkaurelius.titan.graphdb.internal.OrderList in project titan by thinkaurelius.
the class TitanGraphTest method evaluateQuery.
public static void evaluateQuery(TitanVertexQuery query, RelationCategory resultType, int expectedResults, int numSubQueries, boolean[] subQuerySpecs, Map<PropertyKey, Order> orderMap) {
SimpleQueryProfiler profiler = new SimpleQueryProfiler();
((BasicVertexCentricQueryBuilder) query).profiler(profiler);
Iterable<? extends TitanElement> result;
switch(resultType) {
case PROPERTY:
result = query.properties();
break;
case EDGE:
result = query.edges();
break;
case RELATION:
result = query.relations();
break;
default:
throw new AssertionError();
}
OrderList orders = profiler.getAnnotation(QueryProfiler.ORDERS_ANNOTATION);
//Check elements and that they are returned in the correct order
int no = 0;
TitanElement previous = null;
for (TitanElement e : result) {
assertNotNull(e);
no++;
if (previous != null && !orders.isEmpty()) {
assertTrue(orders.compare(previous, e) <= 0);
}
previous = e;
}
assertEquals(expectedResults, no);
//Check OrderList of query
assertNotNull(orders);
assertEquals(orderMap.size(), orders.size());
for (int i = 0; i < orders.size(); i++) {
assertEquals(orderMap.get(orders.getKey(i)), orders.getOrder(i));
}
for (PropertyKey key : orderMap.keySet()) assertTrue(orders.containsKey(key));
//Check subqueries
assertEquals(1, (Number) profiler.getAnnotation(QueryProfiler.NUMVERTICES_ANNOTATION));
int subQueryCounter = 0;
for (SimpleQueryProfiler subProfiler : profiler) {
assertNotNull(subProfiler);
if (subProfiler.getGroupName().equals(QueryProfiler.OPTIMIZATION))
continue;
if (subQuerySpecs.length == 2) {
//0=>fitted, 1=>ordered
assertEquals(subQuerySpecs[0], (Boolean) subProfiler.getAnnotation(QueryProfiler.FITTED_ANNOTATION));
assertEquals(subQuerySpecs[1], (Boolean) subProfiler.getAnnotation(QueryProfiler.ORDERED_ANNOTATION));
}
//assertEquals(1,Iterables.size(subProfiler)); This only applies if a disk call is necessary
subQueryCounter++;
}
assertEquals(numSubQueries, subQueryCounter);
}
use of com.thinkaurelius.titan.graphdb.internal.OrderList in project titan by thinkaurelius.
the class QueryTest method testOrderList.
@Test
public void testOrderList() {
PropertyKey name = tx.makePropertyKey("name").dataType(String.class).make();
PropertyKey weight = tx.makePropertyKey("weight").dataType(Double.class).make();
PropertyKey time = tx.makePropertyKey("time").dataType(Long.class).make();
OrderList ol1 = new OrderList();
ol1.add(name, Order.DESC);
ol1.add(weight, Order.ASC);
ol1.makeImmutable();
try {
ol1.add(time, Order.DESC);
fail();
} catch (IllegalArgumentException e) {
}
assertEquals(2, ol1.size());
assertEquals(name, ol1.getKey(0));
assertEquals(weight, ol1.getKey(1));
assertEquals(Order.DESC, ol1.getOrder(0));
assertEquals(Order.ASC, ol1.getOrder(1));
assertFalse(ol1.hasCommonOrder());
OrderList ol2 = new OrderList();
ol2.add(time, Order.ASC);
ol2.add(weight, Order.ASC);
ol2.add(name, Order.ASC);
ol2.makeImmutable();
assertTrue(ol2.hasCommonOrder());
assertEquals(Order.ASC, ol2.getCommonOrder());
OrderList ol3 = new OrderList();
ol3.add(weight, Order.DESC);
TitanVertex v1 = tx.addVertex("name", "abc", "time", 20, "weight", 2.5), v2 = tx.addVertex("name", "bcd", "time", 10, "weight", 2.5), v3 = tx.addVertex("name", "abc", "time", 10, "weight", 4.5);
assertTrue(ol1.compare(v1, v2) > 0);
assertTrue(ol1.compare(v2, v3) < 0);
assertTrue(ol1.compare(v1, v3) < 0);
assertTrue(ol2.compare(v1, v2) > 0);
assertTrue(ol2.compare(v2, v3) < 0);
assertTrue(ol2.compare(v1, v3) > 0);
assertTrue(ol3.compare(v1, v2) == 0);
assertTrue(ol3.compare(v2, v3) > 0);
assertTrue(ol3.compare(v1, v3) > 0);
}
Aggregations