Search in sources :

Example 1 with PointInterval

use of org.janusgraph.util.datastructures.PointInterval in project janusgraph by JanusGraph.

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<JanusGraphRelation> conditions, Map<RelationType, Interval> constraintMap) {
    boolean isFitted = true;
    for (Condition<JanusGraphRelation> 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, JanusGraphRelation> 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 : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) JanusGraphRelation(org.janusgraph.core.JanusGraphRelation) Or(org.janusgraph.graphdb.query.condition.Or) PointInterval(org.janusgraph.util.datastructures.PointInterval) SystemRelationType(org.janusgraph.graphdb.types.system.SystemRelationType) RelationType(org.janusgraph.core.RelationType) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) PointInterval(org.janusgraph.util.datastructures.PointInterval) Interval(org.janusgraph.util.datastructures.Interval) RangeInterval(org.janusgraph.util.datastructures.RangeInterval)

Example 2 with PointInterval

use of org.janusgraph.util.datastructures.PointInterval in project janusgraph by JanusGraph.

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<>(q, isFitted, bestCandidateSupportsOrder));
}
Also used : PointInterval(org.janusgraph.util.datastructures.PointInterval) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) PropertyKey(org.janusgraph.core.PropertyKey) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) PointInterval(org.janusgraph.util.datastructures.PointInterval) Interval(org.janusgraph.util.datastructures.Interval) RangeInterval(org.janusgraph.util.datastructures.RangeInterval)

Aggregations

Interval (org.janusgraph.util.datastructures.Interval)2 PointInterval (org.janusgraph.util.datastructures.PointInterval)2 RangeInterval (org.janusgraph.util.datastructures.RangeInterval)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JanusGraphRelation (org.janusgraph.core.JanusGraphRelation)1 PropertyKey (org.janusgraph.core.PropertyKey)1 RelationType (org.janusgraph.core.RelationType)1 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)1 EdgeSerializer (org.janusgraph.graphdb.database.EdgeSerializer)1 InternalRelationType (org.janusgraph.graphdb.internal.InternalRelationType)1 Or (org.janusgraph.graphdb.query.condition.Or)1 PredicateCondition (org.janusgraph.graphdb.query.condition.PredicateCondition)1 SystemRelationType (org.janusgraph.graphdb.types.system.SystemRelationType)1