Search in sources :

Example 1 with ElementValueComparator

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator in project titan by thinkaurelius.

the class HasStepFolder method validTitanOrder.

public static boolean validTitanOrder(OrderGlobalStep ostep, Traversal rootTraversal, boolean isVertexOrder) {
    for (Comparator comp : (List<Comparator>) ostep.getComparators()) {
        if (!(comp instanceof ElementValueComparator))
            return false;
        ElementValueComparator evc = (ElementValueComparator) comp;
        if (!(evc.getValueComparator() instanceof Order))
            return false;
        TitanTransaction tx = TitanTraversalUtil.getTx(rootTraversal.asAdmin());
        String key = evc.getPropertyKey();
        PropertyKey pkey = tx.getPropertyKey(key);
        if (pkey == null || !(Comparable.class.isAssignableFrom(pkey.dataType())))
            return false;
        if (isVertexOrder && pkey.cardinality() != Cardinality.SINGLE)
            return false;
    }
    return true;
}
Also used : Order(org.apache.tinkerpop.gremlin.process.traversal.Order) ArrayList(java.util.ArrayList) List(java.util.List) ElementValueComparator(org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) ElementValueComparator(org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator) Comparator(java.util.Comparator)

Example 2 with ElementValueComparator

use of org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator in project titan by thinkaurelius.

the class HasStepFolder method foldInOrder.

//    public static boolean addLabeledStepAsIdentity(Step<?,?> currentStep, final Traversal.Admin<?, ?> traversal) {
//        if (currentStep.getLabel().isPresent()) {
//            final IdentityStep identityStep = new IdentityStep<>(traversal);
//            identityStep.setLabel(currentStep.getLabel().get());
//            TraversalHelper.insertAfterStep(identityStep, currentStep, traversal);
//            return true;
//        } else return false;
//    }
public static void foldInOrder(final HasStepFolder titanStep, final Traversal.Admin<?, ?> traversal, final Traversal<?, ?> rootTraversal, boolean isVertexOrder) {
    Step<?, ?> currentStep = titanStep.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(titanStep::addLabel);
                traversal.removeStep(lastOrder);
            }
            lastOrder = (OrderGlobalStep) currentStep;
        } else if (currentStep instanceof IdentityStep) {
        // do nothing, can be skipped
        } else if (currentStep instanceof HasStep) {
        // do nothing, can be skipped
        } else {
            break;
        }
        currentStep = currentStep.getNextStep();
    }
    if (lastOrder != null && lastOrder instanceof OrderGlobalStep) {
        if (validTitanOrder(lastOrder, rootTraversal, isVertexOrder)) {
            //Add orders to HasStepFolder
            for (Comparator comp : (List<Comparator>) ((OrderGlobalStep) lastOrder).getComparators()) {
                ElementValueComparator evc = (ElementValueComparator) comp;
                titanStep.orderBy(evc.getPropertyKey(), (Order) evc.getValueComparator());
            }
            lastOrder.getLabels().forEach(titanStep::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) ArrayList(java.util.ArrayList) List(java.util.List) ElementValueComparator(org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator) ElementValueComparator(org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator) Comparator(java.util.Comparator)

Aggregations

ArrayList (java.util.ArrayList)2 Comparator (java.util.Comparator)2 List (java.util.List)2 ElementValueComparator (org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator)2 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)1 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)1 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)1 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)1 OrderGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep)1 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)1