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;
}
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));
}
Aggregations