Search in sources :

Example 11 with PredicateCondition

use of org.janusgraph.graphdb.query.condition.PredicateCondition in project janusgraph by JanusGraph.

the class AdjacentVertexHasUniquePropertyOptimizerStrategy method isValidStep.

/**
 * Determines whether this HasStep can be answered by a unique index and thus, returns either 0 or 1 match
 */
@Override
protected boolean isValidStep(HasStep<?> step) {
    StandardJanusGraphTx tx = (StandardJanusGraphTx) JanusGraphTraversalUtil.getTx(step.getTraversal());
    List<String> givenKeys = step.getHasContainers().stream().map(HasContainer::getKey).collect(Collectors.toList());
    List<PredicateCondition<String, JanusGraphElement>> constraints = step.getHasContainers().stream().filter(hc -> hc.getBiPredicate() == Compare.eq).map(hc -> new PredicateCondition<>(hc.getKey(), JanusGraphPredicateUtils.convert(hc.getBiPredicate()), hc.getValue())).filter(pc -> tx.validDataType(pc.getValue().getClass())).collect(Collectors.toList());
    final MultiCondition<JanusGraphElement> conditions = QueryUtil.constraints2QNF(tx, constraints);
    // check all matching unique indexes
    return IndexSelectionUtil.existsMatchingIndex(conditions, indexType -> indexType.isCompositeIndex() && ((CompositeIndexType) indexType).getCardinality() == Cardinality.SINGLE && IndexSelectionUtil.isIndexSatisfiedByGivenKeys(indexType, givenKeys));
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) MultiCondition(org.janusgraph.graphdb.query.condition.MultiCondition) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) GraphStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep) FilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep) HashSet(java.util.HashSet) Cardinality(org.janusgraph.core.Cardinality) IndexSelectionUtil(org.janusgraph.graphdb.query.index.IndexSelectionUtil) P(org.apache.tinkerpop.gremlin.process.traversal.P) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Edge(org.apache.tinkerpop.gremlin.structure.Edge) JanusGraphElement(org.janusgraph.core.JanusGraphElement) QueryUtil(org.janusgraph.graphdb.query.QueryUtil) TraversalHelper(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Set(java.util.Set) JanusGraphPredicateUtils(org.janusgraph.graphdb.query.JanusGraphPredicateUtils) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Collectors(java.util.stream.Collectors) JanusGraphTraversalUtil(org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphTraversalUtil) NoneStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.NoneStep) Compare(org.apache.tinkerpop.gremlin.process.traversal.Compare) List(java.util.List) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) IdStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.IdStep) ADJACENT_ID(org.janusgraph.graphdb.types.system.ImplicitKey.ADJACENT_ID) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) JanusGraphElement(org.janusgraph.core.JanusGraphElement) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) CompositeIndexType(org.janusgraph.graphdb.types.CompositeIndexType)

Aggregations

PredicateCondition (org.janusgraph.graphdb.query.condition.PredicateCondition)11 RelationType (org.janusgraph.core.RelationType)6 Cmp (org.janusgraph.core.attribute.Cmp)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 JanusGraphElement (org.janusgraph.core.JanusGraphElement)5 Preconditions (com.google.common.base.Preconditions)4 ImmutableList (com.google.common.collect.ImmutableList)4 Arrays (java.util.Arrays)4 HashSet (java.util.HashSet)4 Collectors (java.util.stream.Collectors)4 Cardinality (org.janusgraph.core.Cardinality)4 PropertyKey (org.janusgraph.core.PropertyKey)4 QueryUtil (org.janusgraph.graphdb.query.QueryUtil)4 Condition (org.janusgraph.graphdb.query.condition.Condition)4 MultiCondition (org.janusgraph.graphdb.query.condition.MultiCondition)4 Or (org.janusgraph.graphdb.query.condition.Or)4