org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep.
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: TopologyStrategy.java From sqlg with MIT License | 6 votes |
@SuppressWarnings("unchecked") @Override public void apply(Traversal.Admin<?, ?> traversal) { Preconditions.checkState(!(this.sqlgSchema && this.globalUniqueIndex), "sqlgSchema and globalUnique are mutually exclusive. Both can not be true."); if (!TraversalHelper.getStepsOfAssignableClass(GraphStep.class, traversal).isEmpty() || !TraversalHelper.getStepsOfAssignableClass(VertexStep.class, traversal).isEmpty()) { if (this.sqlgSchema) { TraversalHelper.insertAfterStep( new HasStep(traversal, new HasContainer(TOPOLOGY_SELECTION_SQLG_SCHEMA, P.eq(this.sqlgSchema))), traversal.getStartStep(), traversal ); } if (this.globalUniqueIndex) { TraversalHelper.insertAfterStep( new HasStep(traversal, new HasContainer(TOPOLOGY_SELECTION_GLOBAL_UNIQUE_INDEX, P.eq(this.globalUniqueIndex))), traversal.getStartStep(), traversal ); } } }
Example #2
Source File: Neo4jGraphStepStrategy.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final Neo4jGraphStep<?, ?> neo4jGraphStep = new Neo4jGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, neo4jGraphStep, traversal); Step<?, ?> currentStep = neo4jGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(neo4jGraphStep, hasContainer)) neo4jGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #3
Source File: TinkerGraphStepStrategy.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (TraversalHelper.onGraphComputer(traversal)) return; for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal); Step<?, ?> currentStep = tinkerGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer)) tinkerGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #4
Source File: BitsyTraversalStrategy.java From bitsy with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final BitsyGraphStep<?, ?> bitsyGraphStep = new BitsyGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, bitsyGraphStep, traversal); Step<?, ?> currentStep = bitsyGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(bitsyGraphStep, hasContainer)) bitsyGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #5
Source File: TinkerGraphStepStrategy.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (TraversalHelper.onGraphComputer(traversal)) return; for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal); Step<?, ?> currentStep = tinkerGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer)) tinkerGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #6
Source File: HBaseVertexStepStrategy.java From hgraphdb with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final VertexStep originalVertexStep : TraversalHelper.getStepsOfClass(VertexStep.class, traversal)) { final HBaseVertexStep<?> hbaseVertexStep = new HBaseVertexStep<>(originalVertexStep); TraversalHelper.replaceStep(originalVertexStep, hbaseVertexStep, traversal); Step<?, ?> currentStep = hbaseVertexStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { hbaseVertexStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #7
Source File: HBaseGraphStepStrategy.java From hgraphdb with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void apply(final Traversal.Admin<?, ?> traversal) { for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) { final HBaseGraphStep<?, ?> hbaseGraphStep = new HBaseGraphStep<>(originalGraphStep); TraversalHelper.replaceStep(originalGraphStep, hbaseGraphStep, traversal); Step<?, ?> currentStep = hbaseGraphStep.getNextStep(); while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) { if (currentStep instanceof HasStep) { for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) { if (!GraphStep.processHasContainerIds(hbaseGraphStep, hasContainer)) hbaseGraphStep.addHasContainer(hasContainer); } TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false); traversal.removeStep(currentStep); } currentStep = currentStep.getNextStep(); } } }
Example #8
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 6 votes |
public static void extractHasContainer(HugeGraphStep<?, ?> newStep, Traversal.Admin<?, ?> traversal) { Step<?, ?> step = newStep; do { step = step.getNextStep(); if (step instanceof HasStep) { HasContainerHolder holder = (HasContainerHolder) step; for (HasContainer has : holder.getHasContainers()) { if (!GraphStep.processHasContainerIds(newStep, has)) { newStep.addHasContainer(has); } } TraversalHelper.copyLabels(step, step.getPreviousStep(), false); traversal.removeStep(step); } } while (step instanceof HasStep || step instanceof NoOpBarrierStep); }
Example #9
Source File: InlineFilterStrategy.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { boolean changed = true; // recursively walk child traversals trying to inline them into the current traversal line. while (changed) { changed = false; final Iterator<FilterStep> filterStepIterator = TraversalHelper.getStepsOfAssignableClass(FilterStep.class, traversal).iterator(); while (!changed && filterStepIterator.hasNext()) { final FilterStep<?> step = filterStepIterator.next(); changed = step instanceof HasStep && InlineFilterStrategy.processHasStep((HasStep) step, traversal) || step instanceof TraversalFilterStep && InlineFilterStrategy.processTraversalFilterStep((TraversalFilterStep) step, traversal) || step instanceof OrStep && InlineFilterStrategy.processOrStep((OrStep) step, traversal) || step instanceof AndStep && InlineFilterStrategy.processAndStep((AndStep) step, traversal); } if (!changed && traversal.isRoot()) { final Iterator<MatchStep> matchStepIterator = TraversalHelper.getStepsOfClass(MatchStep.class, traversal).iterator(); while (!changed && matchStepIterator.hasNext()) { if (InlineFilterStrategy.processMatchStep(matchStepIterator.next(), traversal)) changed = true; } } } }
Example #10
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@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 #11
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 #12
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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)); }
Example #13
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 |
@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 #15
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 #16
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 |
@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 #18
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 #19
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
private static void validateToyTraversal(final Traversal traversal) { assertEquals(traversal.asAdmin().getSteps().size(), 3); assertEquals(IdentityStep.class, traversal.asAdmin().getSteps().get(0).getClass()); assertEquals(HasStep.class, traversal.asAdmin().getSteps().get(1).getClass()); assertEquals(LambdaFilterStep.class, traversal.asAdmin().getSteps().get(2).getClass()); // IDENTITY STEP assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getPreviousStep().getClass()); assertEquals(HasStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getNextStep().getClass()); assertEquals(LambdaFilterStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getNextStep().getNextStep().getClass()); assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(0)).getNextStep().getNextStep().getNextStep().getClass()); // HAS STEP assertEquals(IdentityStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getPreviousStep().getClass()); assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getPreviousStep().getPreviousStep().getClass()); assertEquals(LambdaFilterStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getNextStep().getClass()); assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(1)).getNextStep().getNextStep().getClass()); // FILTER STEP assertEquals(HasStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getPreviousStep().getClass()); assertEquals(IdentityStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getPreviousStep().getPreviousStep().getClass()); assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getPreviousStep().getPreviousStep().getPreviousStep().getClass()); assertEquals(EmptyStep.class, ((Step) traversal.asAdmin().getSteps().get(2)).getNextStep().getClass()); assertEquals(3, traversal.asAdmin().getSteps().size()); }
Example #20
Source File: InlineFilterStrategyTest.java From tinkerpop with Apache License 2.0 | 5 votes |
private static GraphTraversal.Admin<?, ?> addHas(final GraphTraversal<?, ?> traversal, final Object... hasKeyValues) { final HasStep<?> hasStep = new HasStep<>((Traversal.Admin) traversal); for (int i = 0; i < hasKeyValues.length; i = i + 2) { hasStep.addHasContainer(new HasContainer((String) hasKeyValues[i], (P) hasKeyValues[i + 1])); } return traversal.asAdmin().addStep(hasStep); }
Example #21
Source File: SqlgHasStepStrategy.java From sqlg with MIT License | 5 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { //Only optimize SqlgGraph. StarGraph also passes through here. if (!(traversal.getGraph().orElseThrow(IllegalStateException::new) instanceof SqlgGraph)) { return; } if (!SqlgTraversalUtil.mayOptimize(traversal)) { return; } List<HasStep> hasSteps = TraversalHelper.getStepsOfAssignableClass(HasStep.class, traversal); for (HasStep<?> hasStep : hasSteps) { List<HasContainer> hasContainers = new ArrayList<>(hasStep.getHasContainers()); SqlgHasStep sqlgHasStep = new SqlgHasStep( hasStep.getTraversal(), hasContainers.toArray(new HasContainer[]{}) ); for (String label : hasStep.getLabels()) { sqlgHasStep.addLabel(label); } //noinspection unchecked TraversalHelper.replaceStep( hasStep, sqlgHasStep, hasStep.getTraversal() ); } }
Example #22
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 #23
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 #24
Source File: TraversalHelperTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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 #25
Source File: MasterExecutor.java From tinkerpop with Apache License 2.0 | 5 votes |
private static boolean isLocalElement(final Step<?, ?> step) { return step instanceof PropertiesStep || step instanceof PropertyMapStep || step instanceof IdStep || step instanceof LabelStep || step instanceof SackStep || step instanceof PropertyKeyStep || step instanceof PropertyValueStep || step instanceof TailGlobalStep || step instanceof RangeGlobalStep || step instanceof HasStep || step instanceof ConnectiveStep; }
Example #26
Source File: ElementIdStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void apply(final Traversal.Admin<?, ?> traversal) { TraversalHelper.getStepsOfAssignableClass(HasStep.class, traversal).stream() .filter(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).getKey().equals(T.id.getAccessor())) .forEach(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).setKey(this.idPropertyKey)); if (traversal.getStartStep() instanceof GraphStep) { final GraphStep graphStep = (GraphStep) traversal.getStartStep(); // only need to apply the custom id if ids were assigned - otherwise we want the full iterator. // note that it is then only necessary to replace the step if the id is a non-element. other tests // in the suite validate that items in getIds() is uniform so it is ok to just test the first item // in the list. if (graphStep.getIds().length > 0 && !(graphStep.getIds()[0] instanceof Element)) { if (graphStep instanceof HasContainerHolder) ((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, P.within(Arrays.asList(graphStep.getIds())))); else TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, P.within(Arrays.asList(graphStep.getIds())))), graphStep, traversal); graphStep.clearIds(); } } TraversalHelper.getStepsOfAssignableClass(IdStep.class, traversal).stream().forEach(step -> { TraversalHelper.replaceStep(step, new PropertiesStep(traversal, PropertyType.VALUE, idPropertyKey), traversal); }); // in each case below, determine if the T.id is present and if so, replace T.id with the idPropertyKey or if // it is not present then shove it in there and generate an id traversal.getSteps().forEach(step -> { if (step instanceof AddVertexStep || step instanceof AddVertexStartStep || step instanceof AddEdgeStep) { final Parameterizing parameterizing = (Parameterizing) step; if (parameterizing.getParameters().contains(T.id)) parameterizing.getParameters().rename(T.id, this.idPropertyKey); else if (!parameterizing.getParameters().contains(this.idPropertyKey)) parameterizing.getParameters().set(null, this.idPropertyKey, idMaker.get()); } }); }
Example #27
Source File: FilterRankingStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Ranks the given step. Steps with lower ranks can be moved in front of steps with higher ranks. 0 means that * the step has no rank and thus is not exchangeable with its neighbors. * * @param step the step to get a ranking for * @return The rank of the given step. */ private static int getStepRank(final Step step) { final int rank; if (!(step instanceof FilterStep || step instanceof OrderGlobalStep)) return 0; else if (step instanceof IsStep || step instanceof ClassFilterStep) rank = 1; else if (step instanceof HasStep) rank = 2; else if (step instanceof WherePredicateStep && ((WherePredicateStep) step).getLocalChildren().isEmpty()) rank = 3; else if (step instanceof TraversalFilterStep || step instanceof NotStep) rank = 4; else if (step instanceof WhereTraversalStep) rank = 5; else if (step instanceof OrStep) rank = 6; else if (step instanceof AndStep) rank = 7; else if (step instanceof WherePredicateStep) // has by()-modulation rank = 8; else if (step instanceof DedupGlobalStep) rank = 9; else if (step instanceof OrderGlobalStep) rank = 10; else return 0; //////////// if (step instanceof TraversalParent) return getMaxStepRank((TraversalParent) step, rank); else return rank; }
Example #28
Source File: InlineFilterStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
private static final boolean processMatchStep(final MatchStep<?, ?> step, final Traversal.Admin<?, ?> traversal) { if (step.getPreviousStep() instanceof EmptyStep) return false; boolean changed = false; final String startLabel = MatchStep.Helper.computeStartLabel(step.getGlobalChildren()); for (final Traversal.Admin<?, ?> matchTraversal : new ArrayList<>(step.getGlobalChildren())) { if (TraversalHelper.hasAllStepsOfClass(matchTraversal, HasStep.class, MatchStep.MatchStartStep.class, MatchStep.MatchEndStep.class) && matchTraversal.getStartStep() instanceof MatchStep.MatchStartStep && startLabel.equals(((MatchStep.MatchStartStep) matchTraversal.getStartStep()).getSelectKey().orElse(null))) { changed = true; step.removeGlobalChild(matchTraversal); final String endLabel = ((MatchStep.MatchEndStep) matchTraversal.getEndStep()).getMatchKey().orElse(null); // why would this exist? but just in case matchTraversal.removeStep(0); // remove MatchStartStep matchTraversal.removeStep(matchTraversal.getSteps().size() - 1); // remove MatchEndStep TraversalHelper.applySingleLevelStrategies(traversal, matchTraversal, InlineFilterStrategy.class); matchTraversal.getEndStep().addLabel(startLabel); if (null != endLabel) matchTraversal.getEndStep().addLabel(endLabel); TraversalHelper.insertTraversal((Step) step.getPreviousStep(), matchTraversal, traversal); } } if (step.getGlobalChildren().isEmpty()) traversal.removeStep(step); return changed; }
Example #29
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 5 votes |
public static void convAllHasSteps(Traversal.Admin<?, ?> traversal) { // Extract all has steps in traversal @SuppressWarnings("rawtypes") List<HasStep> steps = TraversalHelper.getStepsOfAssignableClassRecursively( HasStep.class, traversal); HugeGraph graph = (HugeGraph) traversal.getGraph().get(); for (HasStep<?> step : steps) { TraversalUtil.convHasStep(graph, step); } }
Example #30
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 5 votes |
public static void extractHasContainer(HugeVertexStep<?> newStep, Traversal.Admin<?, ?> traversal) { Step<?, ?> step = newStep; do { if (step instanceof HasStep) { HasContainerHolder holder = (HasContainerHolder) step; for (HasContainer has : holder.getHasContainers()) { newStep.addHasContainer(has); } TraversalHelper.copyLabels(step, step.getPreviousStep(), false); traversal.removeStep(step); } step = step.getNextStep(); } while (step instanceof HasStep || step instanceof NoOpBarrierStep); }