@Test(expected = IllegalArgumentException.class) public void shouldNotAllowBytecodeEvalWithMissingBinding() throws Exception { final GremlinScriptEngine scriptEngine = manager.getEngineByName(ENGINE_TO_TEST); final Graph graph = EmptyGraph.instance(); final GraphTraversalSource g = graph.traversal(); // purposefully use "x" to match the name of the traversal source binding for "x" below and // thus tests the alias added for "x" final GraphTraversal t = getTraversalWithLambda(g); final Bindings bindings = new SimpleBindings(); bindings.put("z", g); scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x"); }
/** * Merges the results of an arbitrary number of traversals. * * @param unionTraversals the traversals to merge * @return the traversal with the appended {@link UnionStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#union-step" target="_blank">Reference Documentation - Union Step</a> * @since 3.0.0-incubating */ public default <E2> GraphTraversal<S, E2> union(final Traversal<?, E2>... unionTraversals) { this.asAdmin().getBytecode().addStep(Symbols.union, unionTraversals); return this.asAdmin().addStep(new UnionStep<>(this.asAdmin(), Arrays.copyOf(unionTraversals, unionTraversals.length, Traversal.Admin[].class))); }
/** * Map the {@link Edge} to the incident vertex that was not just traversed from in the path history. * * @return the traversal with an appended {@link EdgeOtherVertexStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#vertex-steps" target="_blank">Reference Documentation - Vertex Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, Vertex> otherV() { this.asAdmin().getBytecode().addStep(Symbols.otherV); return this.asAdmin().addStep(new EdgeOtherVertexStep(this.asAdmin())); }
/** * Executes a Connected Component algorithm over the graph. * * @return the traversal with the appended {@link ConnectedComponentVertexProgram} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#connectedcomponent-step" target="_blank">Reference Documentation - ConnectedComponent Step</a> * @since 3.4.0 */ public default GraphTraversal<S, E> connectedComponent() { this.asAdmin().getBytecode().addStep(Symbols.connectedComponent); return this.asAdmin().addStep((Step<E, E>) new ConnectedComponentVertexProgramStep(this.asAdmin())); }
/** * Provides a execute a specified traversal on a single element within a stream. * * @param localTraversal the traversal to execute locally * @return the traversal with the appended {@link LocalStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#local-step" target="_blank">Reference Documentation - Local Step</a> * @since 3.0.0-incubating */ public default <E2> GraphTraversal<S, E2> local(final Traversal<?, E2> localTraversal) { this.asAdmin().getBytecode().addStep(Symbols.local, localTraversal); return this.asAdmin().addStep(new LocalStep<>(this.asAdmin(), localTraversal.asAdmin())); }
/** * Modifies a {@link #repeat(Traversal)} to determine when the loop should exit. * * @param untilTraversal the traversal that determines when the loop exits * @return the traversal with the appended {@link RepeatStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#repeat-step" target="_blank">Reference Documentation - Repeat Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> until(final Traversal<?, ?> untilTraversal) { this.asAdmin().getBytecode().addStep(Symbols.until, untilTraversal); return RepeatStep.addUntilToTraversal(this, (Traversal.Admin<E, ?>) untilTraversal); }
/** * Emit is used in conjunction with {@link #repeat(Traversal)} to emit all objects from the loop. * * @return the traversal with the appended {@link RepeatStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#repeat-step" target="_blank">Reference Documentation - Repeat Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> emit() { this.asAdmin().getBytecode().addStep(Symbols.emit); return RepeatStep.addEmitToTraversal(this, TrueTraversal.instance()); }
/** * Emit is used in conjunction with {@link #repeat(Traversal)} to determine what objects get emit from the loop. * * @param emitPredicate the emit predicate * @return the traversal with the appended {@link RepeatStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#repeat-step" target="_blank">Reference Documentation - Repeat Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> emit(final Predicate<Traverser<E>> emitPredicate) { this.asAdmin().getBytecode().addStep(Symbols.emit, emitPredicate); return RepeatStep.addEmitToTraversal(this, (Traversal.Admin<E, ?>) __.filter(emitPredicate)); }
/** * Filters vertices, edges and vertex properties based on their value. * * @param predicate the filter to apply to the value of the {@link Element} * @return the traversal with an appended {@link HasStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#has-step" target="_blank">Reference Documentation - Has Step</a> * @since 3.2.4 */ public default GraphTraversal<S, E> hasValue(final P<Object> predicate) { this.asAdmin().getBytecode().addStep(Symbols.hasValue, predicate); return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.value.getAccessor(), predicate)); }
/** * Remove all duplicates in the traversal stream up to this point. * * @param dedupLabels if labels are provided, then the scoped object's labels determine de-duplication. No labels implies current object. * @return the traversal with an appended {@link DedupGlobalStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#dedup-step" target="_blank">Reference Documentation - Dedup Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> dedup(final String... dedupLabels) { this.asAdmin().getBytecode().addStep(Symbols.dedup, dedupLabels); return this.asAdmin().addStep(new DedupGlobalStep<>(this.asAdmin(), dedupLabels)); }
/** * Aggregates the emanating paths into a {@link Tree} data structure. * * @return the traversal with an appended {@link TreeStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#tree-step" target="_blank">Reference Documentation - Tree Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, Tree> tree() { this.asAdmin().getBytecode().addStep(Symbols.tree); return this.asAdmin().addStep(new TreeStep<>(this.asAdmin())); }
/** * Determines the smallest value in the stream given the {@link Scope}. * * @return the traversal with an appended {@link MinGlobalStep} or {@link MinLocalStep} depending on the {@link Scope} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#min-step" target="_blank">Reference Documentation - Min Step</a> * @since 3.0.0-incubating */ public default <E2 extends Comparable> GraphTraversal<S, E2> min(final Scope scope) { this.asAdmin().getBytecode().addStep(Symbols.min, scope); return this.asAdmin().addStep(scope.equals(Scope.global) ? new MinGlobalStep<E2>(this.asAdmin()) : new MinLocalStep<>(this.asAdmin())); }
/** * Determines the largest value in the stream given the {@link Scope}. * * @return the traversal with an appended {@link MaxGlobalStep} or {@link MaxLocalStep} depending on the {@link Scope} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#max-step" target="_blank">Reference Documentation - Max Step</a> * @since 3.0.0-incubating */ public default <E2 extends Comparable> GraphTraversal<S, E2> max(final Scope scope) { this.asAdmin().getBytecode().addStep(Symbols.max, scope); return this.asAdmin().addStep(scope.equals(Scope.global) ? new MaxGlobalStep<>(this.asAdmin()) : new MaxLocalStep<>(this.asAdmin())); }
/** * Determines the largest value in the stream. * * @return the traversal with an appended {@link MaxGlobalStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#max-step" target="_blank">Reference Documentation - Max Step</a> * @since 3.0.0-incubating */ public default <E2 extends Comparable> GraphTraversal<S, E2> max() { this.asAdmin().getBytecode().addStep(Symbols.max); return this.asAdmin().addStep(new MaxGlobalStep<>(this.asAdmin())); }
/** * A version of {@code select} that allows for the extraction of a {@link Column} from objects in the traversal. * * @param column the column to extract * @return the traversal with an appended {@link TraversalMapStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#select-step" target="_blank">Reference Documentation - Select Step</a> * @since 3.1.0-incubating */ public default <E2> GraphTraversal<S, Collection<E2>> select(final Column column) { this.asAdmin().getBytecode().addStep(Symbols.select, column); return this.asAdmin().addStep(new TraversalMapStep<>(this.asAdmin(), new ColumnTraversal(column))); }
/** * Map the {@link Vertex} to its outgoing adjacent vertices given the edge labels. * * @param edgeLabels the edge labels to traverse * @return the traversal with an appended {@link VertexStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#vertex-steps" target="_blank">Reference Documentation - Vertex Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, Vertex> out(final String... edgeLabels) { this.asAdmin().getBytecode().addStep(Symbols.out, edgeLabels); return this.asAdmin().addStep(new VertexStep<>(this.asAdmin(), Vertex.class, Direction.OUT, edgeLabels)); }
/** * Map any object to a fixed <code>E</code> value. * * @return the traversal with an appended {@link ConstantStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#constant-step" target="_blank">Reference Documentation - Constant Step</a> * @since 3.0.0-incubating */ public default <E2> GraphTraversal<S, E2> constant(final E2 e) { this.asAdmin().getBytecode().addStep(Symbols.constant, e); return this.asAdmin().addStep(new ConstantStep<E, E2>(this.asAdmin(), e)); }
/** * Map a {@link Traverser} referencing an object of type <code>E</code> to an object of type <code>E2</code>. * * @param mapTraversal the traversal expression that does the functional mapping * @return the traversal with an appended {@link LambdaMapStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#general-steps" target="_blank">Reference Documentation - General Steps</a> * @since 3.0.0-incubating */ public default <E2> GraphTraversal<S, E2> map(final Traversal<?, E2> mapTraversal) { this.asAdmin().getBytecode().addStep(Symbols.map, mapTraversal); return this.asAdmin().addStep(new TraversalMapStep<>(this.asAdmin(), mapTraversal)); }
/** * Map a {@link Traverser} referencing an object of type <code>E</code> to an object of type <code>E2</code>. * * @param function the lambda expression that does the functional mapping * @return the traversal with an appended {@link LambdaMapStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#general-steps" target="_blank">Reference Documentation - General Steps</a> * @since 3.0.0-incubating */ public default <E2> GraphTraversal<S, E2> map(final Function<Traverser<E>, E2> function) { this.asAdmin().getBytecode().addStep(Symbols.map, function); return this.asAdmin().addStep(new LambdaMapStep<>(this.asAdmin(), function)); }
@Benchmark public GraphTraversal.Admin<Vertex,Vertex> testTranslationWithStrategy() { return translator.translate(g.withStrategies(ReadOnlyStrategy.instance()) .withStrategies(SubgraphStrategy.build().vertices(hasLabel("person")).create()) .V().out().in("link").out().in("link").asAdmin().getBytecode()); } }