org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 6 votes |
public static void extractOrder(Step<?, ?> newStep, Traversal.Admin<?, ?> traversal) { Step<?, ?> step = newStep; do { step = step.getNextStep(); if (step instanceof OrderGlobalStep) { QueryHolder holder = (QueryHolder) newStep; @SuppressWarnings("resource") OrderGlobalStep<?, ?> orderStep = (OrderGlobalStep<?, ?>) step; orderStep.getComparators().forEach(comp -> { ElementValueComparator<?> comparator = (ElementValueComparator<?>) comp.getValue1(); holder.orderBy(comparator.getPropertyKey(), (Order) comparator.getValueComparator()); }); TraversalHelper.copyLabels(step, newStep, false); traversal.removeStep(step); } step = step.getNextStep(); } while (step instanceof OrderGlobalStep || step instanceof IdentityStep); }
Example #2
Source File: HasStepFolder.java From grakn with GNU Affero General Public License v3.0 | 6 votes |
static boolean validJanusGraphOrder(OrderGlobalStep orderGlobalStep, Traversal rootTraversal, boolean isVertexOrder) { List<Pair<Traversal.Admin, Object>> comparators = orderGlobalStep.getComparators(); for (Pair<Traversal.Admin, Object> comp : comparators) { String key; if (comp.getValue0() instanceof ElementValueTraversal && comp.getValue1() instanceof Order) { key = ((ElementValueTraversal) comp.getValue0()).getPropertyKey(); } else if (comp.getValue1() instanceof ElementValueComparator) { 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; } JanusGraphTransaction tx = JanusGraphTraversalUtil.getTx(rootTraversal.asAdmin()); PropertyKey pKey = tx.getPropertyKey(key); if (pKey == null || !(Comparable.class.isAssignableFrom(pKey.dataType())) || (isVertexOrder && pKey.cardinality() != Cardinality.SINGLE)) { return false; } } return true; }
Example #3
Source File: HasStepFolder.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
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; }
Example #4
Source File: SchemaTableTree.java From sqlg with MIT License | 5 votes |
/** * calculate property restrictions from explicit restrictions and required properties */ private void calculatePropertyRestrictions() { if (restrictedProperties == null) { return; } // we use aliases for ordering, so we need the property in the select clause for (org.javatuples.Pair<Traversal.Admin<?, ?>, Comparator<?>> comparator : this.getDbComparators()) { if (comparator.getValue1() instanceof ElementValueComparator) { restrictedProperties.add(((ElementValueComparator<?>) comparator.getValue1()).getPropertyKey()); } else if ((comparator.getValue0() instanceof ElementValueTraversal<?> || comparator.getValue0() instanceof TokenTraversal<?, ?>) && comparator.getValue1() instanceof Order) { Traversal.Admin<?, ?> t = comparator.getValue0(); String key; if (t instanceof ElementValueTraversal) { ElementValueTraversal<?> elementValueTraversal = (ElementValueTraversal<?>) t; key = elementValueTraversal.getPropertyKey(); } else { TokenTraversal<?, ?> tokenTraversal = (TokenTraversal<?, ?>) t; // see calculateLabeledAliasId if (tokenTraversal.getToken().equals(T.id)) { key = Topology.ID; } else { key = tokenTraversal.getToken().getAccessor(); } } if (key != null) { restrictedProperties.add(key); } } } }