Search in sources :

Example 1 with ElementValueTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal in project janusgraph by JanusGraph.

the class HasStepFolder method validJanusGraphOrder.

static boolean validJanusGraphOrder(OrderGlobalStep orderGlobalStep, Traversal rootTraversal, boolean isVertexOrder) {
    final List<Pair<Traversal.Admin, Object>> comparators = orderGlobalStep.getComparators();
    for (Pair<Traversal.Admin, Object> comp : comparators) {
        if (comp.getValue0() instanceof ElementValueTraversal && comp.getValue1() instanceof Order) {
            final String key = ((ElementValueTraversal) comp.getValue0()).getPropertyKey();
            final JanusGraphTransaction tx = JanusGraphTraversalUtil.getTx(rootTraversal.asAdmin());
            final PropertyKey pKey = tx.getPropertyKey(key);
            if (pKey == null || !(Comparable.class.isAssignableFrom(pKey.dataType())) || (isVertexOrder && pKey.cardinality() != Cardinality.SINGLE)) {
                return false;
            }
        } else {
            // do not fold comparators that include nested traversals that are not simple ElementValues
            return false;
        }
    }
    return true;
}
Also used : Order(org.apache.tinkerpop.gremlin.process.traversal.Order) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) PropertyKey(org.janusgraph.core.PropertyKey) Pair(org.javatuples.Pair)

Example 2 with ElementValueTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal in project janusgraph by JanusGraph.

the class HasStepFolder method foldInOrder.

static void foldInOrder(final HasStepFolder janusgraphStep, final Traversal.Admin<?, ?> traversal, final Traversal<?, ?> rootTraversal, boolean isVertexOrder) {
    Step<?, ?> currentStep = janusgraphStep.getNextStep();
    OrderGlobalStep<?, ?> lastOrder = null;
    while (true) {
        if (currentStep instanceof OrderGlobalStep) {
            if (lastOrder != null) {
                // Previous orders are rendered irrelevant by next order (since re-ordered)
                lastOrder.getLabels().forEach(janusgraphStep::addLabel);
                traversal.removeStep(lastOrder);
            }
            lastOrder = (OrderGlobalStep) currentStep;
        } else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof HasStep) && !(currentStep instanceof NoOpBarrierStep)) {
            break;
        }
        currentStep = currentStep.getNextStep();
    }
    if (lastOrder != null) {
        if (validJanusGraphOrder(lastOrder, rootTraversal, isVertexOrder)) {
            // Add orders to HasStepFolder
            for (Pair<Traversal.Admin<Object, Comparable>, Comparator<Object>> comp : (List<Pair<Traversal.Admin<Object, Comparable>, Comparator<Object>>>) ((OrderGlobalStep) lastOrder).getComparators()) {
                ElementValueTraversal evt = (ElementValueTraversal) comp.getValue0();
                janusgraphStep.orderBy(evt.getPropertyKey(), (Order) comp.getValue1());
            }
            lastOrder.getLabels().forEach(janusgraphStep::addLabel);
            traversal.removeStep(lastOrder);
        }
    }
}
Also used : IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep) ArrayList(java.util.ArrayList) List(java.util.List) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) Comparator(java.util.Comparator)

Aggregations

ElementValueTraversal (org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)1 NoOpBarrierStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep)1 OrderGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep)1 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)1 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)1 PropertyKey (org.janusgraph.core.PropertyKey)1 Pair (org.javatuples.Pair)1