use of org.apache.tinkerpop.gremlin.process.traversal.lambda.ValueTraversal 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 (final Pair<Traversal.Admin, Object> comp : comparators) {
final String key;
if (comp.getValue0() instanceof ValueTraversal && comp.getValue1() instanceof Order) {
key = ((ValueTraversal) comp.getValue0()).getPropertyKey();
} else if (comp.getValue1() instanceof ElementValueComparator) {
final ElementValueComparator evc = (ElementValueComparator) comp.getValue1();
if (!(evc.getValueComparator() instanceof Order))
return false;
key = evc.getPropertyKey();
} else {
// do not fold comparators that include nested traversals that are not simple ElementValues
return false;
}
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;
}
}
return true;
}
use of org.apache.tinkerpop.gremlin.process.traversal.lambda.ValueTraversal in project janusgraph by JanusGraph.
the class HasStepFolder method foldInOrder.
static Step<?, ?> foldInOrder(final HasStepFolder janusgraphStep, final Step<?, ?> tinkerpopStep, final Traversal.Admin<?, ?> traversal, final Traversal<?, ?> rootTraversal, boolean isVertexOrder, final List<HasContainer> hasContainers) {
Step<?, ?> currentStep = tinkerpopStep;
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 && validJanusGraphOrder(lastOrder, rootTraversal, isVertexOrder)) {
// Add orders to HasStepFolder
for (final Pair<Traversal.Admin<Object, Comparable>, Comparator<Object>> comp : (List<Pair<Traversal.Admin<Object, Comparable>, Comparator<Object>>>) ((OrderGlobalStep) lastOrder).getComparators()) {
final String key;
final Order order;
if (comp.getValue0() instanceof ValueTraversal) {
final ValueTraversal evt = (ValueTraversal) comp.getValue0();
key = evt.getPropertyKey();
order = (Order) comp.getValue1();
} else {
final ElementValueComparator evc = (ElementValueComparator) comp.getValue1();
key = evc.getPropertyKey();
order = (Order) evc.getValueComparator();
}
if (hasContainers == null) {
janusgraphStep.orderBy(key, order);
} else {
janusgraphStep.localOrderBy(traversal.getParent(), hasContainers, key, order);
}
}
lastOrder.getLabels().forEach(janusgraphStep::addLabel);
traversal.removeStep(lastOrder);
}
return currentStep;
}
Aggregations