本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep类的典型用法代码示例。如果您正苦于以下问题:Java LocalStep类的具体用法?Java LocalStep怎么用?Java LocalStep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalStep类属于org.apache.tinkerpop.gremlin.process.traversal.step.branch包,在下文中一共展示了LocalStep类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldIdentifyLocalChildren
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
@Test
public void shouldIdentifyLocalChildren() {
final Traversal.Admin<?, ?> localChild = __.as("x").select("a", "b").by("name").asAdmin();
new LocalStep<>(new DefaultTraversal(), localChild);
assertFalse(TraversalHelper.isGlobalChild(localChild));
///
new WhereTraversalStep<>(new DefaultTraversal(), localChild);
assertFalse(TraversalHelper.isGlobalChild(localChild));
///
new TraversalFilterStep<>(new DefaultTraversal(), localChild);
assertFalse(TraversalHelper.isGlobalChild(localChild));
///
new TraversalMapStep<>(new DefaultTraversal(), localChild);
assertFalse(TraversalHelper.isGlobalChild(localChild));
///
new TraversalFlatMapStep<>(new DefaultTraversal(), localChild);
assertFalse(TraversalHelper.isGlobalChild(localChild));
///
final Traversal.Admin<?, ?> remoteLocalChild = __.repeat(localChild).asAdmin();
new LocalStep<>(new DefaultTraversal<>(), remoteLocalChild);
assertFalse(TraversalHelper.isGlobalChild(localChild));
}
示例2: unfoldLocalTraversal
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
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);
}
}
}
示例3: endsWithElement
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
public static final boolean endsWithElement(Step<?, ?> currentStep) {
while (!(currentStep instanceof EmptyStep)) {
if (currentStep instanceof VertexStep) // only inE, in, and out send messages
return (((VertexStep) currentStep).returnsVertex() || !((VertexStep) currentStep).getDirection().equals(Direction.OUT));
else if (currentStep instanceof EdgeVertexStep) // TODO: add GraphStep but only if its mid-traversal V()/E()
return true;
else if (currentStep instanceof TraversalFlatMapStep || currentStep instanceof TraversalMapStep || currentStep instanceof LocalStep)
return endsWithElement(((TraversalParent) currentStep).getLocalChildren().get(0).getEndStep());
else if (!(currentStep instanceof FilterStep || currentStep instanceof SideEffectStep || currentStep instanceof IdentityStep || currentStep instanceof Barrier))
return false;
currentStep = currentStep.getPreviousStep();
}
return false;
}
示例4: testLocalStepCompile
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
@Test
public void testLocalStepCompile() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) gt
.V(a1)
.local(
__.out().out()
).path();
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof LocalStep);
LocalStep<?, ?> localStep = (LocalStep) traversal.getSteps().get(1);
Assert.assertEquals(1, localStep.getLocalChildren().size());
Traversal.Admin<?, ?> traversal1 = localStep.getLocalChildren().get(0);
Assert.assertEquals(2, traversal1.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(1, paths.size());
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgLocalStepBarrier);
SqlgLocalStepBarrier<?,?> sqlgLocalStepBarrier = (SqlgLocalStepBarrier) traversal.getSteps().get(1);
Assert.assertEquals(1, sqlgLocalStepBarrier.getLocalChildren().size());
traversal1 = sqlgLocalStepBarrier.getLocalChildren().get(0);
Assert.assertEquals(1, traversal1.getSteps().size());
}
示例5: local
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
public default <E2> GraphTraversal<S, E2> local(final Traversal<?, E2> localTraversal) {
return this.asAdmin().addStep(new LocalStep<>(this.asAdmin(), localTraversal.asAdmin()));
}
示例6: apply
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
// only process the first traversal step in an OLAP chain
TraversalHelper.getFirstStepOfAssignableClass(TraversalVertexProgramStep.class, traversal).ifPresent(step -> {
final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // best guess at what the graph will be as its dynamically determined
final Traversal.Admin<?, ?> compiledComputerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone();
if (!compiledComputerTraversal.isLocked())
compiledComputerTraversal.applyStrategies();
if (!TraversalHelper.hasStepOfAssignableClassRecursively(Arrays.asList(LocalStep.class, LambdaHolder.class), compiledComputerTraversal) && // don't do anything with lambdas or locals as this leads to unknown adjacencies
!compiledComputerTraversal.getTraverserRequirements().contains(TraverserRequirement.PATH) && // when dynamic detachment is provided in 3.3.0, remove this (TODO)
!compiledComputerTraversal.getTraverserRequirements().contains(TraverserRequirement.LABELED_PATH) && // when dynamic detachment is provided in 3.3.0, remove this (TODO)
!(TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, compiledComputerTraversal). // this is a strict precaution that could be loosed with deeper logic on barriers in global children
stream().
filter(parent -> !parent.getGlobalChildren().isEmpty()).findAny().isPresent())) {
final Traversal.Admin<?, ?> computerTraversal = step.computerTraversal.get().clone();
// apply the strategies up to this point
final List<TraversalStrategy<?>> strategies = step.getTraversal().getStrategies().toList();
final int indexOfStrategy = strategies.indexOf(MessagePassingReductionStrategy.instance());
if (indexOfStrategy > 0)
TraversalHelper.applySingleLevelStrategies(step.getTraversal(), computerTraversal, strategies.get(indexOfStrategy - 1).getClass());
if (computerTraversal.getSteps().size() > 1 &&
!(computerTraversal.getStartStep().getNextStep() instanceof Barrier) &&
TraversalHelper.hasStepOfAssignableClassRecursively(Arrays.asList(VertexStep.class, EdgeVertexStep.class), computerTraversal) &&
TraversalHelper.isLocalStarGraph(computerTraversal)) {
final Step barrier = (Step) TraversalHelper.getFirstStepOfAssignableClass(Barrier.class, computerTraversal).orElse(null);
if (MessagePassingReductionStrategy.insertElementId(barrier)) // out().count() -> out().id().count()
TraversalHelper.insertBeforeStep(new IdStep(computerTraversal), barrier, computerTraversal);
if (!(MessagePassingReductionStrategy.endsWithElement(null == barrier ? computerTraversal.getEndStep() : barrier))) {
Traversal.Admin newChildTraversal = new DefaultGraphTraversal<>();
TraversalHelper.removeToTraversal(computerTraversal.getStartStep() instanceof GraphStep ?
computerTraversal.getStartStep().getNextStep() :
(Step) computerTraversal.getStartStep(), null == barrier ?
EmptyStep.instance() :
barrier, newChildTraversal);
newChildTraversal = newChildTraversal.getSteps().size() > 1 ? (Traversal.Admin) __.local(newChildTraversal) : newChildTraversal;
if (null == barrier)
TraversalHelper.insertTraversal(0, newChildTraversal, computerTraversal);
else
TraversalHelper.insertTraversal(barrier.getPreviousStep(), newChildTraversal, computerTraversal);
}
}
step.setComputerTraversal(computerTraversal);
}
});
}
示例7: testOptionalWithOrderAndRange
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
@Test
public void testOptionalWithOrderAndRange() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "aa");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "aaa");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "d");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "c");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b");
Vertex bb1 = this.sqlgGraph.addVertex(T.label, "BB", "name", "g");
Vertex bb2 = this.sqlgGraph.addVertex(T.label, "BB", "name", "f");
Vertex bb3 = this.sqlgGraph.addVertex(T.label, "BB", "name", "e");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "h");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "i");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "j");
Vertex cc1 = this.sqlgGraph.addVertex(T.label, "CC", "name", "k");
Vertex cc2 = this.sqlgGraph.addVertex(T.label, "CC", "name", "l");
Vertex cc3 = this.sqlgGraph.addVertex(T.label, "CC", "name", "m");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
a1.addEdge("abb", bb1);
a1.addEdge("abb", bb2);
a1.addEdge("abb", bb3);
b1.addEdge("bc", c1);
b1.addEdge("bc", c2);
b1.addEdge("bc", c3);
b2.addEdge("bcc", cc1);
b2.addEdge("bcc", cc2);
b2.addEdge("bcc", cc3);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal()
.V().hasLabel("A")
.local(
__.optional(
__.out().order().by("name").optional(
__.out().order().by("name", Order.decr).range(2, 3)
)
)
)
.path();
Assert.assertEquals(4, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof LocalStep);
LocalStep<?, ?> localStep = (LocalStep<?, ?>) traversal.getSteps().get(1);
List<SqlgVertexStep> sqlgVertexSteps = TraversalHelper.getStepsOfAssignableClassRecursively(SqlgVertexStep.class, localStep.getLocalChildren().get(0));
Assert.assertEquals(1, sqlgVertexSteps.size());
SqlgVertexStep sqlgVertexStep = sqlgVertexSteps.get(0);
assertStep(sqlgVertexStep, false, true, true, true);
Assert.assertEquals(7, paths.size());
//all the paths of length 2 and 3 must be sorted
List<Path> pathsOfLength3 = paths.stream().filter(p -> p.size() == 3).collect(Collectors.toList());
Assert.assertEquals(1, pathsOfLength3.size());
Vertex v = (Vertex) pathsOfLength3.get(0).objects().get(2);
Assert.assertEquals("k", v.value("name"));
List<Path> pathsOfLength2 = paths.stream().filter(p -> p.size() == 2).collect(Collectors.toList());
Assert.assertEquals(4, pathsOfLength2.size());
v = (Vertex) pathsOfLength2.get(0).objects().get(1);
Assert.assertEquals("b", v.value("name"));
v = (Vertex) pathsOfLength2.get(1).objects().get(1);
Assert.assertEquals("e", v.value("name"));
v = (Vertex) pathsOfLength2.get(2).objects().get(1);
Assert.assertEquals("f", v.value("name"));
v = (Vertex) pathsOfLength2.get(3).objects().get(1);
Assert.assertEquals("g", v.value("name"));
List<Path> pathsOfLength1 = paths.stream().filter(p -> p.size() == 1).collect(Collectors.toList());
Assert.assertEquals(2, pathsOfLength1.size());
}
示例8: testOptionalWithOrderAndRange2
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
@Test
public void testOptionalWithOrderAndRange2() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "aa");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "aaa");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "d");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "c");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b");
Vertex bb1 = this.sqlgGraph.addVertex(T.label, "BB", "name", "g");
Vertex bb2 = this.sqlgGraph.addVertex(T.label, "BB", "name", "f");
Vertex bb3 = this.sqlgGraph.addVertex(T.label, "BB", "name", "e");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "h");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "i");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "j");
Vertex cc1 = this.sqlgGraph.addVertex(T.label, "CC", "name", "k");
Vertex cc2 = this.sqlgGraph.addVertex(T.label, "CC", "name", "l");
Vertex cc3 = this.sqlgGraph.addVertex(T.label, "CC", "name", "m");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
a1.addEdge("abb", bb1);
a1.addEdge("abb", bb2);
a1.addEdge("abb", bb3);
b1.addEdge("bc", c1);
b1.addEdge("bc", c2);
b1.addEdge("bc", c3);
b2.addEdge("bcc", cc1);
b2.addEdge("bcc", cc2);
b2.addEdge("bcc", cc3);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal()
.V().hasLabel("A")
.local(
__.optional(
__.out().order().by("name").range(1, 2).optional(
__.out().order().by("name", Order.decr).range(2, 3)
)
)
)
.path();
Assert.assertEquals(4, traversal.getSteps().size());
List<Path> paths = traversal.toList();
//This query is no fully optimized.
//The range messes it up, so it has a SqlgVertexStep
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof LocalStep);
LocalStep<?, ?> localStep = (LocalStep<?, ?>) traversal.getSteps().get(1);
List<SqlgVertexStep> sqlgVertexSteps = TraversalHelper.getStepsOfAssignableClassRecursively(SqlgVertexStep.class, localStep.getLocalChildren().get(0));
//first optional step can not be optimized because it has a range step that is not the last step
//the second is optimized.
Assert.assertEquals(2, sqlgVertexSteps.size());
Assert.assertEquals(3, paths.size());
List<Path> pathsOfLength1 = paths.stream().filter(p -> p.size() == 1).collect(Collectors.toList());
Assert.assertEquals(2, pathsOfLength1.size());
List<Path> pathsOfLength3 = paths.stream().filter(p -> p.size() == 3).collect(Collectors.toList());
Assert.assertEquals(1, pathsOfLength3.size());
Vertex v = (Vertex) pathsOfLength3.get(0).objects().get(2);
Assert.assertEquals("k", v.value("name"));
}
示例9: testUmlgRequirementWithRange
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
@Test
public void testUmlgRequirementWithRange() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
Vertex bb1 = this.sqlgGraph.addVertex(T.label, "BB", "name", "bb1");
Vertex bb2 = this.sqlgGraph.addVertex(T.label, "BB", "name", "bb2");
Vertex bb3 = this.sqlgGraph.addVertex(T.label, "BB", "name", "bb3");
a1.addEdge("ab", b1, "order", 3);
a1.addEdge("ab", b2, "order", 2);
a1.addEdge("ab", b3, "order", 1);
a1.addEdge("abb", bb1, "order", 3);
a1.addEdge("abb", bb2, "order", 2);
a1.addEdge("abb", bb3, "order", 1);
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3");
b1.addEdge("bc", c1, "order", 1);
b1.addEdge("bc", c2, "order", 2);
b1.addEdge("bc", c3, "order", 3);
Vertex cc1 = this.sqlgGraph.addVertex(T.label, "CC", "name", "cc1");
Vertex cc2 = this.sqlgGraph.addVertex(T.label, "CC", "name", "cc2");
Vertex cc3 = this.sqlgGraph.addVertex(T.label, "CC", "name", "cc3");
b1.addEdge("bcc", cc1, "order", 3);
b1.addEdge("bcc", cc2, "order", 2);
b1.addEdge("bcc", cc3, "order", 1);
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) sqlgGraph.traversal()
.V().hasLabel("A").as("a").order().by("name", Order.decr)
.local(
__.optional(
__.outE().as("e1").inV().as("b").order().by(__.select("a").by(T.id)).by(T.label).by(__.select("e1").by("order")).limit(1)
.local(
__.optional(
__.outE().as("e2").inV().order().by(__.select("b").by(T.id)).by(T.label).by(__.select("e2").by("order"))
)
)
)
)
.path();
Assert.assertEquals(5, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(4, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(2) instanceof LocalStep);
LocalStep localStep = (LocalStep) traversal.getSteps().get(2);
DefaultGraphTraversal<Vertex, Vertex> t = (DefaultGraphTraversal<Vertex, Vertex>) localStep.getLocalChildren().get(0);
//First optional is a non optimized, optimized SqlgChooseBarrierStep
Assert.assertEquals(1, t.getSteps().size());
Assert.assertTrue(t.getSteps().get(0) instanceof SqlgOptionalStepBarrier);
SqlgOptionalStepBarrier sqlgOptionalStepBarrier = (SqlgOptionalStepBarrier) t.getSteps().get(0);
Traversal.Admin<?, ?> optionalTraversal = (Traversal.Admin<?, ?>) sqlgOptionalStepBarrier.getLocalChildren().get(0);
Assert.assertEquals(2, optionalTraversal.getSteps().size());
Assert.assertTrue(optionalTraversal.getSteps().get(0) instanceof SqlgVertexStep);
Assert.assertTrue(optionalTraversal.getSteps().get(1) instanceof SqlgLocalStepBarrier);
SqlgLocalStepBarrier sqlgLocalStepBarrier1 = (SqlgLocalStepBarrier) optionalTraversal.getSteps().get(1);
t = (DefaultGraphTraversal<Vertex, Vertex>) sqlgLocalStepBarrier1.getLocalChildren().get(0);
//Second optional is a optimized
Assert.assertEquals(1, t.getSteps().size());
Assert.assertEquals(2, paths.size());
Path pathX = paths.get(0);
Assert.assertEquals(1, pathX.size());
Assert.assertTrue(pathX.get(0).equals(a2));
pathX = paths.get(1);
Assert.assertEquals(3, pathX.size());
Assert.assertTrue(pathX.get(0).equals(a1));
Assert.assertTrue(pathX.get(2).equals(b3));
}
示例10: SqlgLocalStepBarrier
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
public SqlgLocalStepBarrier(final Traversal.Admin traversal, LocalStep<S, E> localStep) {
super(traversal);
this.localTraversal = localStep.getLocalChildren().get(0);
}
示例11: local
import org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep; //导入依赖的package包/类
/**
* 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()));
}