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