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