Search in sources :

Example 1 with ReceivesPredicatesHolder

use of org.unipop.process.predicate.ReceivesPredicatesHolder in project unipop by unipop-graph.

the class UniGraphOrderStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    TraversalHelper.getStepsOfAssignableClass(OrderGlobalStep.class, traversal).forEach(orderGlobalStep -> {
        List<Pair<Traversal.Admin, Comparator>> comparators = orderGlobalStep.getComparators();
        List<Pair<String, Order>> collect = comparators.stream().filter(pair -> pair.getValue0() instanceof ElementValueTraversal).filter(pair -> pair.getValue1() instanceof Order).map(pair -> Pair.with(((ElementValueTraversal) pair.getValue0()).getPropertyKey(), ((Order) pair.getValue1()))).collect(Collectors.toList());
        Collection<Orderable> orderableStepOf = getOrderableStepOf(orderGlobalStep, traversal);
        if (orderableStepOf != null && orderableStepOf.size() == 1) {
            Orderable step = orderableStepOf.iterator().next();
            step.setOrders(collect);
            Step nextStep = orderGlobalStep.getNextStep();
            if (nextStep instanceof RangeGlobalStep) {
                if (step instanceof ReceivesPredicatesHolder) {
                    RangeGlobalStep rangeGlobalStep = (RangeGlobalStep) nextStep;
                    int limit = rangeGlobalStep.getHighRange() > Integer.MAX_VALUE ? -1 : (int) rangeGlobalStep.getHighRange();
                    ((ReceivesPredicatesHolder) step).setLimit(limit);
                }
            }
        }
    });
}
Also used : EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) WhereTraversalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep) TraversalHelper(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper) java.util(java.util) EdgeStepsStrategy(org.unipop.process.edge.EdgeStepsStrategy) UniGraphVertexStepStrategy(org.unipop.process.vertex.UniGraphVertexStepStrategy) UniGraphStepStrategy(org.unipop.process.graph.UniGraphStepStrategy) TraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy) DedupGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.DedupGlobalStep) UniGraphRepeatStepStrategy(org.unipop.process.repeat.UniGraphRepeatStepStrategy) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Pair(org.javatuples.Pair) ReceivesPredicatesHolder(org.unipop.process.predicate.ReceivesPredicatesHolder) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) Stream(java.util.stream.Stream) AbstractTraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) WhereTraversalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep) DedupGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.DedupGlobalStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) ReceivesPredicatesHolder(org.unipop.process.predicate.ReceivesPredicatesHolder) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) Pair(org.javatuples.Pair)

Aggregations

Sets (com.google.common.collect.Sets)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)1 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 TraversalStrategy (org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy)1 ElementValueTraversal (org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal)1 TraversalParent (org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent)1 DedupGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.DedupGlobalStep)1 RangeGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep)1 WhereTraversalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep)1 OrderGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep)1 EmptyStep (org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep)1 AbstractTraversalStrategy (org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy)1 TraversalHelper (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper)1 Pair (org.javatuples.Pair)1 EdgeStepsStrategy (org.unipop.process.edge.EdgeStepsStrategy)1 UniGraphStepStrategy (org.unipop.process.graph.UniGraphStepStrategy)1