Search in sources :

Example 1 with BasicVertexCentricQueryBuilder

use of com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder in project titan by thinkaurelius.

the class TitanPropertiesStep method makeQuery.

private <Q extends BaseVertexQuery> Q makeQuery(Q query) {
    String[] keys = getPropertyKeys();
    query.keys(keys);
    for (HasContainer condition : hasContainers) {
        query.has(condition.getKey(), TitanPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue());
    }
    for (OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (limit != BaseQuery.NO_LIMIT)
        query.limit(limit);
    ((BasicVertexCentricQueryBuilder) query).profiler(queryProfiler);
    return query;
}
Also used : BasicVertexCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Example 2 with BasicVertexCentricQueryBuilder

use of com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder 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);
}
Also used : BasicVertexCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder) TitanElement(com.thinkaurelius.titan.core.TitanElement) OrderList(com.thinkaurelius.titan.graphdb.internal.OrderList) SimpleQueryProfiler(com.thinkaurelius.titan.graphdb.query.profile.SimpleQueryProfiler) PropertyKey(com.thinkaurelius.titan.core.PropertyKey)

Example 3 with BasicVertexCentricQueryBuilder

use of com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder in project titan by thinkaurelius.

the class TitanVertexStep method makeQuery.

public <Q extends BaseVertexQuery> Q makeQuery(Q query) {
    query.labels(getEdgeLabels());
    query.direction(getDirection());
    for (HasContainer condition : hasContainers) {
        query.has(condition.getKey(), TitanPredicate.Converter.convert(condition.getBiPredicate()), condition.getValue());
    }
    for (OrderEntry order : orders) query.orderBy(order.key, order.order);
    if (limit != BaseQuery.NO_LIMIT)
        query.limit(limit);
    ((BasicVertexCentricQueryBuilder) query).profiler(queryProfiler);
    return query;
}
Also used : BasicVertexCentricQueryBuilder(com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)

Aggregations

BasicVertexCentricQueryBuilder (com.thinkaurelius.titan.graphdb.query.vertex.BasicVertexCentricQueryBuilder)3 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)2 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)1 TitanElement (com.thinkaurelius.titan.core.TitanElement)1 OrderList (com.thinkaurelius.titan.graphdb.internal.OrderList)1 SimpleQueryProfiler (com.thinkaurelius.titan.graphdb.query.profile.SimpleQueryProfiler)1