[
https://issues.apache.org/jira/browse/TINKERPOP-1470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15542431#comment-15542431
]
ASF GitHub Bot commented on TINKERPOP-1470:
-------------------------------------------
Github user dkuppitz commented on a diff in the pull request:
https://github.com/apache/tinkerpop/pull/445#discussion_r81550568
--- Diff:
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
---
@@ -72,97 +75,163 @@ 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;
- // filter(x.y) --> x.y
- for (final TraversalFilterStep<?> step :
TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal)) {
- final Traversal.Admin<?, ?> childTraversal =
step.getLocalChildren().get(0);
- if (TraversalHelper.hasAllStepsOfClass(childTraversal,
FilterStep.class) &&
- !TraversalHelper.hasStepOfClass(childTraversal,
- DropStep.class,
- RangeGlobalStep.class,
- DedupGlobalStep.class,
- LambdaHolder.class)) {
+ for (final FilterStep<?> step :
TraversalHelper.getStepsOfAssignableClass(FilterStep.class, traversal)) {
--- End diff --
Complex traversal could waste a few CPU cycles in this method. Here's an
optimized version:
```
@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.getParent() instanceof EmptyStep) {
final Iterator<MatchStep> matchStepIterator =
TraversalHelper.getStepsOfClass(MatchStep.class, traversal).iterator();
while (!changed && matchStepIterator.hasNext()) {
if
(InlineFilterStrategy.processMatchStep(matchStepIterator.next(), traversal))
changed = true;
}
}
}
}
```
> InlineFilterStrategy should try and P.or() has() children in OrSteps.
> ---------------------------------------------------------------------
>
> Key: TINKERPOP-1470
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1470
> Project: TinkerPop
> Issue Type: Improvement
> Components: process
> Affects Versions: 3.2.2
> Reporter: Marko A. Rodriguez
> Assignee: Marko A. Rodriguez
>
> The following patterns:
> {code}
> g.V().or(has("age",gt(20)), has("age",lt(32)))
> g.V().and(or(has("age",gt(20)), has("age",lt(32))),has("age",neq(23))
> {code}
> should be re-written by {{InlineFilterStrategy}} as:
> {code}
> g.V().has("age",gt(20).or(lt(32)))
> g.V().has("age",gt(20).or(lt(32)).and(neq(23)))
> {code}
> This would then make it easier for provider strategies to fold the predicate
> into graph/vertex-centric push down predicates accordingly.
> Note that {{InlineFilterStep}} already has the code to flatten {{AndSteps}}.
> Thus, during its recursion, it would do the following rewrites to get to the
> final form.
> {code}
> g.V().and(or(has("age",gt(20)), has("age",lt(32))),has("age",neq(23))
> g.V().or(has("age",gt(20)), has("age",lt(32))).has("age",neq(23))
> g.V().has("age",gt(20).or(lt(32))).has("age",neq(23))
> g.V().has("age",gt(20).or(lt(32)).and(neq(23)))
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)