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