Search in sources :

Example 1 with PointInterval

use of com.thinkaurelius.titan.util.datastructures.PointInterval in project titan by thinkaurelius.

the class BasicVertexCentricQueryBuilder method compileConstraints.

/**
     * Converts the constraint conditions of this query into a constraintMap which is passed as an argument.
     * If all the constraint conditions could be accounted for in the constraintMap, this method returns true, else -
     * if some constraints cannot be captured in an interval - it returns false to indicate that further in-memory filtering
     * will be necessary.
     * </p>
     * This constraint map is used in constructing the SliceQueries and query optimization since this representation
     * is easier to handle.
     *
     * @param conditions
     * @param constraintMap
     * @return
     */
private boolean compileConstraints(And<TitanRelation> conditions, Map<RelationType, Interval> constraintMap) {
    boolean isFitted = true;
    for (Condition<TitanRelation> condition : conditions.getChildren()) {
        RelationType type = null;
        Interval newInterval = null;
        if (condition instanceof Or) {
            Map.Entry<RelationType, Collection> orEqual = QueryUtil.extractOrCondition((Or) condition);
            if (orEqual != null) {
                type = orEqual.getKey();
                newInterval = new PointInterval(orEqual.getValue());
            }
        } else if (condition instanceof PredicateCondition) {
            PredicateCondition<RelationType, TitanRelation> atom = (PredicateCondition) condition;
            type = atom.getKey();
            Interval interval = constraintMap.get(type);
            newInterval = intersectConstraints(interval, type, atom.getPredicate(), atom.getValue());
        }
        if (newInterval != null) {
            constraintMap.put(type, newInterval);
        } else
            isFitted = false;
    }
    if (adjacentVertex != null) {
        if (adjacentVertex.hasId())
            constraintMap.put(ImplicitKey.ADJACENT_ID, new PointInterval(adjacentVertex.longId()));
        else
            isFitted = false;
    }
    return isFitted;
}
Also used : PointInterval(com.thinkaurelius.titan.util.datastructures.PointInterval) SystemRelationType(com.thinkaurelius.titan.graphdb.types.system.SystemRelationType) Interval(com.thinkaurelius.titan.util.datastructures.Interval) PointInterval(com.thinkaurelius.titan.util.datastructures.PointInterval) RangeInterval(com.thinkaurelius.titan.util.datastructures.RangeInterval)

Example 2 with PointInterval

use of com.thinkaurelius.titan.util.datastructures.PointInterval in project titan by thinkaurelius.

the class BasicVertexCentricQueryBuilder method constructSliceQueries.

private void constructSliceQueries(PropertyKey[] extendedSortKey, EdgeSerializer.TypedInterval[] sortKeyConstraints, int position, InternalRelationType bestCandidate, Direction direction, Map<RelationType, Interval> intervalConstraints, int sliceLimit, boolean isIntervalFittedConditions, boolean bestCandidateSupportsOrder, List<BackendQueryHolder<SliceQuery>> queries) {
    if (position < extendedSortKey.length) {
        PropertyKey keyType = extendedSortKey[position];
        Interval interval = intervalConstraints.get(keyType);
        if (interval != null) {
            sortKeyConstraints[position] = new EdgeSerializer.TypedInterval(keyType, interval);
            position++;
        }
        if (interval != null && interval.isPoints()) {
            //Keep invoking recursively to see if we can satisfy more constraints...
            for (Object point : interval.getPoints()) {
                EdgeSerializer.TypedInterval[] clonedSKC = Arrays.copyOf(sortKeyConstraints, sortKeyConstraints.length);
                clonedSKC[position - 1] = new EdgeSerializer.TypedInterval(keyType, new PointInterval(point));
                constructSliceQueries(extendedSortKey, clonedSKC, position, bestCandidate, direction, intervalConstraints, sliceLimit, isIntervalFittedConditions, bestCandidateSupportsOrder, queries);
            }
            return;
        }
    }
    //...otherwise this is it and we can construct the slicequery
    boolean isFitted = isIntervalFittedConditions && position == intervalConstraints.size();
    if (isFitted && position > 0) {
        //If the last interval is open ended toward the larger values, then its not fitted because we need to
        //filter out NULL values which are serialized with -1 (largest value) byte up front.
        EdgeSerializer.TypedInterval lastInterval = sortKeyConstraints[position - 1];
        if (!lastInterval.interval.isPoints() && lastInterval.interval.getEnd() == null)
            isFitted = false;
    }
    EdgeSerializer serializer = tx.getEdgeSerializer();
    SliceQuery q = serializer.getQuery(bestCandidate, direction, sortKeyConstraints);
    q.setLimit(computeLimit(intervalConstraints.size() - position, sliceLimit));
    queries.add(new BackendQueryHolder<SliceQuery>(q, isFitted, bestCandidateSupportsOrder));
}
Also used : PointInterval(com.thinkaurelius.titan.util.datastructures.PointInterval) EdgeSerializer(com.thinkaurelius.titan.graphdb.database.EdgeSerializer) SliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery) Interval(com.thinkaurelius.titan.util.datastructures.Interval) PointInterval(com.thinkaurelius.titan.util.datastructures.PointInterval) RangeInterval(com.thinkaurelius.titan.util.datastructures.RangeInterval)

Aggregations

Interval (com.thinkaurelius.titan.util.datastructures.Interval)2 PointInterval (com.thinkaurelius.titan.util.datastructures.PointInterval)2 RangeInterval (com.thinkaurelius.titan.util.datastructures.RangeInterval)2 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)1 EdgeSerializer (com.thinkaurelius.titan.graphdb.database.EdgeSerializer)1 SystemRelationType (com.thinkaurelius.titan.graphdb.types.system.SystemRelationType)1