org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph. 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: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEvalBytecode() 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("x", g);

    final Traversal evald = scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");

    assertTraversals(t, evald);

    assertThat(manager.getBindings().containsKey(GremlinScriptEngine.HIDDEN_G), is(false));
}
 
Example #2
Source File: BytecodeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncludeBindingsInNestedTraversals() {
    final Bindings b = Bindings.instance();
    final GraphTraversalSource g = EmptyGraph.instance().traversal();
    final Bytecode bytecode = g.V().in(b.of("a","created")).where(__.out(b.of("b","knows")).has("age",b.of("c",P.gt(32))).map(__.values(b.of("d","name")))).asAdmin().getBytecode();
    assertEquals(4, bytecode.getBindings().size());
    assertEquals("created", bytecode.getBindings().get("a"));
    assertEquals("knows", bytecode.getBindings().get("b"));
    assertEquals(P.gt(32), bytecode.getBindings().get("c"));
    assertEquals("name", bytecode.getBindings().get("d"));
    //
    Bytecode.Binding binding = (Bytecode.Binding)((List<Bytecode.Instruction>)bytecode.getStepInstructions()).get(1).getArguments()[0];
    assertEquals("a", binding.variable());
    assertEquals("created", binding.value());
    binding = (Bytecode.Binding) ((List<Bytecode.Instruction>)((Bytecode)((List<Bytecode.Instruction>)bytecode.getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(0).getArguments()[0];
    assertEquals("b", binding.variable());
    assertEquals("knows", binding.value());
    binding = (Bytecode.Binding) ((List<Bytecode.Instruction>)((Bytecode)((List<Bytecode.Instruction>)bytecode.getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(1).getArguments()[1];
    assertEquals("c", binding.variable());
    assertEquals(P.gt(32), binding.value());
    binding = (Bytecode.Binding) ((List<Bytecode.Instruction>)((Bytecode)((List<Bytecode.Instruction>)((Bytecode)((List<Bytecode.Instruction>)bytecode.getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(2).getArguments()[0]).getStepInstructions()).get(0).getArguments()[0];
    assertEquals("d", binding.variable());
    assertEquals("name", binding.value());
}
 
Example #3
Source File: BytecodeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncludeBindingsInEquality() {
    final Bindings b = Bindings.instance();
    final GraphTraversalSource g = EmptyGraph.instance().traversal();

    final Bytecode bytecode1 = g.V().out(b.of("a", "created")).asAdmin().getBytecode();
    final Bytecode bytecode2 = g.V().out(b.of("a", "knows")).asAdmin().getBytecode();
    final Bytecode bytecode3 = g.V().out(b.of("b", "knows")).asAdmin().getBytecode();
    final Bytecode bytecode4 = g.V().out(b.of("b", "knows")).asAdmin().getBytecode();

    assertNotEquals(bytecode1, bytecode2);
    assertNotEquals(bytecode1, bytecode3);
    assertNotEquals(bytecode2, bytecode3);
    assertNotEquals(bytecode2, bytecode4);
    assertNotEquals(bytecode1, bytecode4);
    assertEquals(bytecode3, bytecode4);

    assertEquals(1, bytecode1.getBindings().size());
    assertEquals("created", bytecode1.getBindings().get("a"));
}
 
Example #4
Source File: EventStrategyTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {"addE(test).from(x)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").from("x"), 1},
            {"addE(test).from(x).property(this,that)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").from("x").property("this", "that"), 1},
            {"addE(test).to(x)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").to("x"), 1},
            {"addE(test).to(x).property(this,that)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").to("x").property("this", "that"), 1},
            {"addV()", new DefaultGraphTraversal<>(EmptyGraph.instance()).addV(), 1},
            {"addV().property(k,v)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addV().property("test", "that"), 1},
            {"properties().drop()", new DefaultGraphTraversal<>(EmptyGraph.instance()).properties().drop(), 1},
            {"properties(k).drop()", new DefaultGraphTraversal<>(EmptyGraph.instance()).properties("test").drop(), 1},
            {"out().drop()", new DefaultGraphTraversal<>(EmptyGraph.instance()).out().drop(), 1},
            {"out(args).drop()", new DefaultGraphTraversal<>(EmptyGraph.instance()).out("test").drop(), 1},
            {"outE().drop()", new DefaultGraphTraversal<>(EmptyGraph.instance()).outE().drop(), 1},
            {"outE().properties().drop()", new DefaultGraphTraversal<>(EmptyGraph.instance()).outE().properties().drop(), 1},
            {"outE(args).drop()", new DefaultGraphTraversal<>(EmptyGraph.instance()).outE("test").drop(), 1}});
}
 
Example #5
Source File: BytecodeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHaveProperHashAndEquality() {
    final GraphTraversalSource g = EmptyGraph.instance().traversal();
    final Traversal.Admin traversal1 = g.V().out().repeat(__.out().in()).times(2).groupCount().by(__.outE().count()).select(Column.keys).order().by(Order.desc).asAdmin();
    final Traversal.Admin traversal2 = g.V().out().repeat(__.out().in()).times(2).groupCount().by(__.outE().count()).select(Column.keys).order().by(Order.desc).asAdmin();
    final Traversal.Admin traversal3 = g.V().out().repeat(__.out().in()).times(2).groupCount().by(__.outE().count()).select(Column.values).order().by(Order.desc).asAdmin();

    assertEquals(traversal1, traversal2);
    assertNotEquals(traversal1, traversal3);
    assertNotEquals(traversal2, traversal3);
    //
    assertEquals(traversal1.hashCode(), traversal2.hashCode());
    assertNotEquals(traversal1.hashCode(), traversal3.hashCode());
    assertNotEquals(traversal2.hashCode(), traversal3.hashCode());
    //
    assertEquals(traversal1.getBytecode(), traversal2.getBytecode());
    assertNotEquals(traversal1.getBytecode(), traversal3.getBytecode());
    assertNotEquals(traversal2.getBytecode(), traversal3.getBytecode());
    //
    assertEquals(traversal1.getBytecode().hashCode(), traversal2.getBytecode().hashCode());
    assertNotEquals(traversal1.getBytecode().hashCode(), traversal3.getBytecode().hashCode());
    assertNotEquals(traversal2.getBytecode().hashCode(), traversal3.getBytecode().hashCode());

}
 
Example #6
Source File: GraphTraversalSourceTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSupportMapBasedStrategies() throws Exception {
    GraphTraversalSource g = EmptyGraph.instance().traversal();
    assertFalse(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
    g = g.withStrategies(SubgraphStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
        put("vertices", __.hasLabel("person"));
        put("vertexProperties", __.limit(0));
        put("edges", __.hasLabel("knows"));
    }})));
    assertTrue(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
    g = g.withoutStrategies(SubgraphStrategy.class);
    assertFalse(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
    //
    assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
    g = g.withStrategies(ReadOnlyStrategy.instance());
    assertTrue(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
    g = g.withoutStrategies(ReadOnlyStrategy.class);
    assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
}
 
Example #7
Source File: EventStrategyTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEventOnMutatingSteps() {
    final MutationListener listener1 = new ConsoleMutationListener(EmptyGraph.instance());
    final EventStrategy eventStrategy = EventStrategy.build()
            .addListener(listener1).create();

    eventStrategy.apply(traversal.asAdmin());

    final AtomicInteger mutatingStepsFound = new AtomicInteger(0);
    traversal.asAdmin().getSteps().stream()
            .filter(s -> s instanceof Mutating)
            .forEach(s -> {
                final Mutating mutating = (Mutating) s;
                assertEquals(1, mutating.getMutatingCallbackRegistry().getCallbacks().size());
                mutatingStepsFound.incrementAndGet();
            });

    assertEquals(expectedMutatingStepsFound, mutatingStepsFound.get());
}
 
Example #8
Source File: GraphFilterStrategy.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.getStepsOfAssignableClass(VertexProgramStep.class, traversal).size() > 1)  // do not do if there is an OLAP chain
        return;
    final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // given that this strategy only works for single OLAP jobs, the graph is the traversal graph
    for (final TraversalVertexProgramStep step : TraversalHelper.getStepsOfClass(TraversalVertexProgramStep.class, traversal)) {   // will be zero or one step
        final Traversal.Admin<?, ?> computerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone();
        if (!computerTraversal.isLocked())
            computerTraversal.applyStrategies();
        final Computer computer = step.getComputer();
        if (null == computer.getEdges() && !GraphComputer.Persist.EDGES.equals(computer.getPersist())) {  // if edges() already set, use it
            final Traversal.Admin<Vertex, Edge> edgeFilter = getEdgeFilter(computerTraversal);
            if (null != edgeFilter)  // if no edges can be filtered, then don't set edges()
                step.setComputer(computer.edges(edgeFilter));
        }
    }
}
 
Example #9
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRemoveStepsCorrectly() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(new IdentityStep(traversal));
    traversal.asAdmin().addStep(new HasStep(traversal));
    traversal.asAdmin().addStep(new LambdaFilterStep(traversal, traverser -> true));

    traversal.asAdmin().addStep(new PropertiesStep(traversal, PropertyType.VALUE, "marko"));
    traversal.asAdmin().removeStep(3);
    validateToyTraversal(traversal);

    traversal.asAdmin().addStep(0, new PropertiesStep(traversal, PropertyType.PROPERTY, "marko"));
    traversal.asAdmin().removeStep(0);
    validateToyTraversal(traversal);

    traversal.asAdmin().removeStep(1);
    traversal.asAdmin().addStep(1, new HasStep(traversal));
    validateToyTraversal(traversal);
}
 
Example #10
Source File: AddEdgeStep.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
protected Edge map(final Traverser.Admin<S> traverser) {
    Vertex toVertex = this.parameters.get(traverser, TO, () -> (Vertex) traverser.get()).get(0);
    Vertex fromVertex = this.parameters.get(traverser, FROM, () -> (Vertex) traverser.get()).get(0);
    if (toVertex instanceof Attachable)
        toVertex = ((Attachable<Vertex>) toVertex)
                .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
    if (fromVertex instanceof Attachable)
        fromVertex = ((Attachable<Vertex>) fromVertex)
                .attach(Attachable.Method.get(this.getTraversal().getGraph().orElse(EmptyGraph.instance())));
    final String edgeLabel = this.parameters.get(traverser, T.label, () -> Edge.DEFAULT_LABEL).get(0);

    final Edge edge = fromVertex.addEdge(edgeLabel, toVertex, this.parameters.getKeyValues(traverser, TO, FROM, T.label));
    if (callbackRegistry != null) {
        final EventStrategy eventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class).get();
        final Event.EdgeAddedEvent vae = new Event.EdgeAddedEvent(eventStrategy.detach(edge));
        callbackRegistry.getCallbacks().forEach(c -> c.accept(vae));
    }
    return edge;
}
 
Example #11
Source File: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithAliasInBindings() 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("x", g);
    bindings.put(GremlinScriptEngine.HIDDEN_G, g);

    scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
}
 
Example #12
Source File: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithInvalidBinding() 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);
    bindings.put("x", "invalid-binding-for-x-given-x-should-be-traversal-source");

    scriptEngine.eval(t.asAdmin().getBytecode(), bindings, "x");
}
 
Example #13
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotFindTheStepIndex() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    final IdentityStep identityStep = new IdentityStep(traversal);
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    assertEquals(-1, TraversalHelper.stepIndex(identityStep, traversal));
}
 
Example #14
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddStepsCorrectly() {
    Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(0, new LambdaFilterStep(traversal, traverser -> true));
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new IdentityStep(traversal));
    validateToyTraversal(traversal);

    traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(0, new IdentityStep(traversal));
    traversal.asAdmin().addStep(1, new HasStep(traversal));
    traversal.asAdmin().addStep(2, new LambdaFilterStep(traversal, traverser -> true));
    validateToyTraversal(traversal);
}
 
Example #15
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldChainTogetherStepsWithNextPreviousInALinkedListStructure() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(new IdentityStep(traversal));
    traversal.asAdmin().addStep(new HasStep(traversal));
    traversal.asAdmin().addStep(new LambdaFilterStep(traversal, traverser -> true));
    validateToyTraversal(traversal);
}
 
Example #16
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceStep() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    final HasStep hasStep = new HasStep(traversal);
    final IdentityStep identityStep = new IdentityStep(traversal);
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, hasStep);
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    TraversalHelper.replaceStep(hasStep, identityStep, traversal);

    assertEquals(traversal.asAdmin().getSteps().get(1), identityStep);
    assertEquals(3, traversal.asAdmin().getSteps().size());
}
 
Example #17
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldInsertAfterStep() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    final HasStep hasStep = new HasStep(traversal);
    final IdentityStep identityStep = new IdentityStep(traversal);
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, hasStep);
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    TraversalHelper.insertAfterStep(identityStep, hasStep, traversal);

    assertEquals(traversal.asAdmin().getSteps().get(2), identityStep);
    assertEquals(4, traversal.asAdmin().getSteps().size());
}
 
Example #18
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldInsertBeforeStep() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    final HasStep hasStep = new HasStep(traversal);
    final IdentityStep identityStep = new IdentityStep(traversal);
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, hasStep);
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    TraversalHelper.insertBeforeStep(identityStep, hasStep, traversal);

    assertEquals(traversal.asAdmin().getSteps().get(1), identityStep);
    assertEquals(4, traversal.asAdmin().getSteps().size());
}
 
Example #19
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotFindStepOfAssignableClassInTraversal() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    assertThat(TraversalHelper.hasStepOfAssignableClass(IdentityStep.class, traversal), is(false));
}
 
Example #20
Source File: ReadOnlyStrategyTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {"addE(test).from(x)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").from("x")},
            {"addE(test).from(x).property(this,that)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").from("x").property("this", "that")},
            {"addE(test).to(x)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").to("x")},
            {"addE(test).to(x).property(this,that)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addE("test").to("x").property("this", "that")},
            {"outE().property(k,v)", new DefaultGraphTraversal<>(EmptyGraph.instance()).outE().property("test", "test")},
            {"out().properties(k).property(k,v)", new DefaultGraphTraversal<>(EmptyGraph.instance()).out().properties("test").property("test", "that")},
            {"out().property(k,v)", new DefaultGraphTraversal<>(EmptyGraph.instance()).out().property("test", "test")},
            {"out().property(Cardinality,k,v)", new DefaultGraphTraversal<>(EmptyGraph.instance()).out().property(VertexProperty.Cardinality.list, "test", "test")},
            {"addV(person)", new DefaultGraphTraversal<>(EmptyGraph.instance()).addV("person")},
            {"addV()", new DefaultGraphTraversal<>(EmptyGraph.instance()).addV()}});
}
 
Example #21
Source File: TraversalTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldOnlyAllowAnonymousChildren() {
    final GraphTraversalSource g = traversal().withGraph(EmptyGraph.instance());
    g.V(1).addE("self").to(__.V(1));
    try {
        g.V(1).addE("self").to(g.V(1));
        fail("Should not allow child traversals spawned from 'g'");
    } catch (IllegalStateException ignored) {}
}
 
Example #22
Source File: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowBytecodeEvalWithAliasAsTraversalSource() 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("x", g);

    scriptEngine.eval(t.asAdmin().getBytecode(), bindings, GremlinScriptEngine.HIDDEN_G);
}
 
Example #23
Source File: GremlinEnabledScriptEngineTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #24
Source File: SparkSingleIterationStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // best guess at what the graph will be as its dynamically determined
    for (final TraversalVertexProgramStep step : TraversalHelper.getStepsOfClass(TraversalVertexProgramStep.class, traversal)) {
        final Traversal.Admin<?, ?> computerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone();
        if (!computerTraversal.isLocked())
            computerTraversal.applyStrategies();
        ///
        boolean doesMessagePass = TraversalHelper.hasStepOfAssignableClassRecursively(Scope.global, MULTI_ITERATION_CLASSES, computerTraversal);
        if (!doesMessagePass) {
            for (final VertexStep vertexStep : TraversalHelper.getStepsOfAssignableClassRecursively(Scope.global, VertexStep.class, computerTraversal)) {
                if (vertexStep.returnsVertex() || !vertexStep.getDirection().equals(Direction.OUT)) { // in-edges require message pass in OLAP
                    doesMessagePass = true;
                    break;
                }
            }
        }
        if (!doesMessagePass &&
                !MessagePassingReductionStrategy.endsWithElement(computerTraversal.getEndStep()) &&
                !(computerTraversal.getTraverserRequirements().contains(TraverserRequirement.LABELED_PATH) || // TODO: remove this when dynamic detachment is available in 3.3.0
                        computerTraversal.getTraverserRequirements().contains(TraverserRequirement.PATH))) {  // TODO: remove this when dynamic detachment is available in 3.3.0
            step.setComputer(step.getComputer()
                    // if no message passing, don't partition the loaded graph
                    .configure(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, true)
                    // if no message passing, don't cache the loaded graph
                    .configure(Constants.GREMLIN_SPARK_SKIP_GRAPH_CACHE, true));
        }
    }
}
 
Example #25
Source File: SparkInterceptorStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // best guess at what the graph will be as its dynamically determined
    for (final TraversalVertexProgramStep step : TraversalHelper.getStepsOfClass(TraversalVertexProgramStep.class, traversal)) {
        final Traversal.Admin<?, ?> computerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone();
        if (!computerTraversal.isLocked())
            computerTraversal.applyStrategies();
        if (SparkStarBarrierInterceptor.isLegal(computerTraversal)) {
            step.setComputer(step.getComputer()
                    .configure(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, true)
                    .configure(Constants.GREMLIN_SPARK_SKIP_GRAPH_CACHE, true)
                    .configure(Constants.GREMLIN_HADOOP_VERTEX_PROGRAM_INTERCEPTOR, SparkStarBarrierInterceptor.class.getCanonicalName()));
        }
    }
}
 
Example #26
Source File: ReceptionSearchDescription.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected GraphTraversal<Vertex, Vertex> initializeVertices(GraphWrapper graphWrapper) {
  // Get the stored search results
  List<Vertex> otherResults = otherSearch.getSearchResult();

  if (otherResults == null) {
    return EmptyGraph.instance().traversal().V();
  }
  // Filter by type as normal
  GraphTraversal<Vertex, Vertex> vertices = graphWrapper.getCurrentEntitiesFor(getType());

  // Return all the vertices which have a reception relation to the store results (other results):
  // The fact that all reception relations are inbound is a pure historical coincidence.
  return vertices.where(__.inE(getRelationNames()).otherV().is(P.within(otherResults)));
}
 
Example #27
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindStepOfAssignableClassInTraversal() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    assertThat(TraversalHelper.hasStepOfAssignableClass(FilterStep.class, traversal), is(true));
}
 
Example #28
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGetTheStepIndex() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    final HasStep hasStep = new HasStep(traversal);
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, hasStep);
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    assertEquals(1, TraversalHelper.stepIndex(hasStep, traversal));
}
 
Example #29
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindStepOfClassInTraversal() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new IdentityStep<>(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    assertThat(TraversalHelper.hasStepOfClass(IdentityStep.class, traversal), is(true));
}
 
Example #30
Source File: TraversalHelperTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotFindStepOfClassInTraversal() {
    final Traversal.Admin traversal = new DefaultTraversal<>(EmptyGraph.instance());
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));
    traversal.asAdmin().addStep(0, new HasStep(traversal));

    assertThat(TraversalHelper.hasStepOfClass(FilterStep.class, traversal), is(false));
}