public static TitanTransaction getTx(Traversal.Admin<?, ?> traversal) { TitanTransaction tx = null; Optional<Graph> optGraph = TraversalHelper.getRootTraversal(traversal.asAdmin()).getGraph(); if (traversal instanceof FulgoraElementTraversal) { tx = (TitanTransaction) optGraph.get(); } else { if (!optGraph.isPresent()) throw new IllegalArgumentException("Traversal is not bound to a graph: " + traversal); Graph graph = optGraph.get(); if (graph instanceof TitanTransaction) tx = (TitanTransaction) graph; else if (graph instanceof TitanBlueprintsGraph) tx = ((TitanBlueprintsGraph) graph).getCurrentThreadTx(); else throw new IllegalArgumentException("Traversal is not bound to a Titan Graph, but: " + graph); } if (tx == null) throw new IllegalArgumentException("Not a valid start step for a Titan traversal: " + traversal); if (tx.isOpen()) return tx; else return ((StandardTitanTx) tx).getNextTx(); }
public static JanusGraphTransaction getTx(Traversal.Admin<?, ?> traversal) { final JanusGraphTransaction tx; Optional<Graph> optGraph = TraversalHelper.getRootTraversal(traversal.asAdmin()).getGraph(); if (traversal instanceof FulgoraElementTraversal) { tx = (JanusGraphTransaction) optGraph.get(); } else { if (!optGraph.isPresent()) throw new IllegalArgumentException("Traversal is not bound to a graph: " + traversal); Graph graph = optGraph.get(); if (graph instanceof JanusGraphTransaction) tx = (JanusGraphTransaction) graph; else if (graph instanceof JanusGraphBlueprintsGraph) tx = ((JanusGraphBlueprintsGraph) graph).getCurrentThreadTx(); else throw new IllegalArgumentException("Traversal is not bound to a JanusGraph Graph, but: " + graph); } if (tx == null) throw new IllegalArgumentException("Not a valid start step for a JanusGraph traversal: " + traversal); if (tx.isOpen()) return tx; else return ((StandardJanusGraphTx) tx).getNextTx(); }
public JanusGraphStep(final GraphStep<S, E> originalStep) { super(originalStep.getTraversal(), originalStep.getReturnClass(), originalStep.isStartStep(), originalStep.getIds()); originalStep.getLabels().forEach(this::addLabel); this.setIteratorSupplier(() -> { if (this.ids == null) { return Collections.emptyIterator(); } else if (this.ids.length > 0) { final Graph graph = (Graph)traversal.asAdmin().getGraph().get(); return iteratorList((Iterator)graph.vertices(this.ids)); } if (hasLocalContainers.isEmpty()) { hasLocalContainers.put(new ArrayList<>(), new QueryInfo(new ArrayList<>(), 0, BaseQuery.NO_LIMIT)); } final JanusGraphTransaction tx = JanusGraphTraversalUtil.getTx(traversal); final GraphCentricQuery globalQuery = buildGlobalGraphCentricQuery(tx); final Multimap<Integer, GraphCentricQuery> queries = ArrayListMultimap.create(); if (globalQuery != null && !globalQuery.getSubQuery(0).getBackendQuery().isEmpty()) { queries.put(0, globalQuery); } else { hasLocalContainers.entrySet().forEach(c -> queries.put(c.getValue().getLowLimit(), buildGraphCentricQuery(tx, c))); } final GraphCentricQueryBuilder builder = (GraphCentricQueryBuilder) tx.query(); final List<Iterator<E>> responses = new ArrayList<>(); queries.entries().forEach(q -> executeGraphCentryQuery(builder, responses, q)); return new MultiDistinctOrderedIterator<E>(lowLimit, highLimit, responses, orders); }); }
public UniGraphCoalesceStep(Traversal.Admin traversal, UniGraph graph, List<Traversal.Admin<S, E>> coalesceTraversals) { super(traversal, graph); this.coalesceTraversals = coalesceTraversals; this.coalesceTraversals.forEach(t -> t.addStep(new UniGraphTraverserStep<>(t.asAdmin()))); this.coalesceTraversals.forEach(this::integrateChild); }
boolean canNotBeOptimized() { @SuppressWarnings("unchecked") final List<Step<?, ?>> steps = new ArrayList(this.traversal.asAdmin().getSteps()); final ListIterator<Step<?, ?>> stepIterator = steps.listIterator(); List<Step<?, ?>> toCome = steps.subList(stepIterator.nextIndex(), steps.size()); return toCome.stream().anyMatch(s -> s.getClass().equals(Order.class) || s.getClass().equals(LambdaCollectingBarrierStep.class) || s.getClass().equals(SackValueStep.class) ); }
public SqlgTraversalFilterStepBarrier(Traversal.Admin traversal, Traversal.Admin<S, ?> filterTraversal) { super(traversal); this.filterTraversal = this.integrateChild(filterTraversal.asAdmin()); }
boolean canNotBeOptimized() { @SuppressWarnings("unchecked") final List<Step<?, ?>> steps = new ArrayList(this.traversal.asAdmin().getSteps()); final ListIterator<Step<?, ?>> stepIterator = steps.listIterator(); List<Step<?, ?>> toCome = steps.subList(stepIterator.nextIndex(), steps.size()); return toCome.stream().anyMatch(s -> s.getClass().equals(Order.class) || s.getClass().equals(LambdaCollectingBarrierStep.class) || s.getClass().equals(SackValueStep.class) ); }
public SubgraphStep(final Traversal.Admin traversal, final String sideEffectKey) { super(traversal); this.sideEffectKey = sideEffectKey; this.getTraversal().asAdmin().getSideEffects().registerIfAbsent(this.sideEffectKey, () -> GraphFactory.open(DEFAULT_CONFIGURATION), Operator.assign); }
@Override public Traverser.Admin<E> processNextStart() { if (this.done) throw FastNoSuchElementException.instance(); this.processAllStarts(); this.done = true; return this.getTraversal().asAdmin().getTraverserGenerator().generate(this.supply(), (Step<E, E>) this, 1l); }
final Step<?, ?> matchEndStep = new MatchEndStep(matchTraversal, label); if (null != label) this.matchEndLabels.add(label); matchTraversal.asAdmin().addStep(matchEndStep);
final Direction direction = TinkerMessenger.getDirection(incidentTraversal); final Edge[] edge = new Edge[1]; // simulates storage side-effects available in Gremlin, but not Java8 streams multiIterator.addIterator(StreamSupport.stream(Spliterators.spliteratorUnknownSize(VertexProgramHelper.reverse(incidentTraversal.asAdmin()), Spliterator.IMMUTABLE | Spliterator.SIZED), false) .map((Edge e) -> { edge[0] = e;
final Step<?, ?> endStep = traversal.asAdmin().getEndStep(); if (TraversalHelper.hasStepOfClass(ProfileSideEffectStep.class, traversal) && !(endStep instanceof ProfileSideEffectStep ||
private static void verifyUniqueStepIds(final Traversal.Admin<?, ?> traversal, final int depth, final Set<String> ids) { for (final Step step : traversal.asAdmin().getSteps()) { /*for (int i = 0; i < depth; i++) System.out.print("\t"); System.out.println(step.getId() + " --> " + step);*/ if (!ids.add(step.getId())) { fail("The following step id already exists: " + step.getId() + "---" + step); } if (step instanceof TraversalParent) { for (final Traversal.Admin<?, ?> globalTraversal : ((TraversalParent) step).getGlobalChildren()) { verifyUniqueStepIds(globalTraversal, depth + 1, ids); } for (final Traversal.Admin<?, ?> localTraversal : ((TraversalParent) step).getLocalChildren()) { verifyUniqueStepIds(localTraversal, depth + 1, ids); } } } } }
private static <T extends Traversal.Admin<Vertex, Edge>> T setVertexStart(final Traversal.Admin<Vertex, Edge> incidentTraversal, final Vertex vertex) { incidentTraversal.asAdmin().addStart(incidentTraversal.getTraverserGenerator().generate(vertex, incidentTraversal.asAdmin().getStartStep(), 1l)); return (T) incidentTraversal; }
public GroupCountSideEffectStep(final Traversal.Admin traversal, final String sideEffectKey) { super(traversal); this.sideEffectKey = sideEffectKey; this.getTraversal().asAdmin().getSideEffects().registerIfAbsent(this.sideEffectKey, HashMapSupplier.instance(), GroupCountStep.GroupCountBiOperator.instance()); }
@Override public Traverser.Admin<E> processNextStart() { if (this.done) throw FastNoSuchElementException.instance(); this.processAllStarts(); this.done = true; return this.getTraversal().asAdmin().getTraverserGenerator().generate(this.supply(), (Step<E, E>) this, 1l); }
public SubgraphStep(final Traversal.Admin traversal, final String sideEffectKey) { super(traversal); this.sideEffectKey = sideEffectKey; this.getTraversal().asAdmin().getSideEffects().registerIfAbsent(this.sideEffectKey, () -> GraphFactory.open(DEFAULT_CONFIGURATION), Operator.assign); }
private static void unfoldLocalTraversal(final Traversal.Admin<?, ?> traversal, LocalStep<?,?> localStep, Traversal.Admin localTraversal, MultiQueriable vertexStep, boolean useMultiQuery) { assert localTraversal.asAdmin().getSteps().size() > 0; if (localTraversal.asAdmin().getSteps().size() == 1) { //Can replace the entire localStep by the vertex step in the outer traversal assert localTraversal.getStartStep() == vertexStep; vertexStep.setTraversal(traversal); TraversalHelper.replaceStep(localStep, vertexStep, traversal); if (useMultiQuery && !(isChildOf(vertexStep, MULTIQUERY_INCOMPATIBLE_STEPS))) { vertexStep.setUseMultiQuery(true); } } }
private static void unfoldLocalTraversal(final Traversal.Admin<?, ?> traversal, LocalStep<?,?> localStep, Traversal.Admin localTraversal, MultiQueriable vstep, boolean useMultiQuery) { assert localTraversal.asAdmin().getSteps().size() > 0; if (localTraversal.asAdmin().getSteps().size() == 1) { //Can replace the entire localStep by the vertex step in the outer traversal assert localTraversal.getStartStep() == vstep; vstep.setTraversal(traversal); TraversalHelper.replaceStep(localStep, vstep, traversal); if (useMultiQuery) { vstep.setUseMultiQuery(true); } } }