tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject tinkerpop git commit: Merge branch 'TINKERPOP-1545' into TINKERPOP-1545-tp32
Date Fri, 11 Nov 2016 13:28:43 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1545-tp32 [created] fcf9320ea


Merge branch 'TINKERPOP-1545' into TINKERPOP-1545-tp32


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/fcf9320e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/fcf9320e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/fcf9320e

Branch: refs/heads/TINKERPOP-1545-tp32
Commit: fcf9320ea8355bc83bb32780820e186e18c6bcb2
Parents: d038916 82be439
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Authored: Fri Nov 11 14:26:46 2016 +0100
Committer: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Committed: Fri Nov 11 14:26:46 2016 +0100

----------------------------------------------------------------------
 .../strategy/optimization/IncidentToAdjacentStrategy.java   | 9 +++------
 .../optimization/IncidentToAdjacentStrategyTest.java        | 2 ++
 2 files changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcf9320e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
index a0adbdc,716449b..45e3803
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
@@@ -24,14 -24,11 +24,13 @@@ import org.apache.tinkerpop.gremlin.pro
  import org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder;
  import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep;
  import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep;
- import org.apache.tinkerpop.gremlin.process.traversal.step.map.PathStep;
- import org.apache.tinkerpop.gremlin.process.traversal.step.map.TreeStep;
  import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
 +import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
  import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+ import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
  import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
  import org.apache.tinkerpop.gremlin.structure.Direction;
 +import org.apache.tinkerpop.gremlin.structure.Graph;
  import org.apache.tinkerpop.gremlin.structure.Vertex;
  import org.javatuples.Pair;
  
@@@ -67,22 -61,16 +64,22 @@@ public final class IncidentToAdjacentSt
          implements TraversalStrategy.OptimizationStrategy {
  
      private static final IncidentToAdjacentStrategy INSTANCE = new IncidentToAdjacentStrategy();
-     private static final Set<Class> INVALIDATING_STEP_CLASSES = new HashSet<>(Arrays.asList(PathStep.class,
TreeStep.class, LambdaHolder.class));
 +    private static final String MARKER = Graph.Hidden.hide("gremlin.incidentToAdjacent");
  
      private IncidentToAdjacentStrategy() {
      }
  
      @Override
 -    public void apply(Traversal.Admin<?, ?> traversal) {
 -        final Traversal.Admin root = TraversalHelper.getRootTraversal(traversal);
 -        if (TraversalHelper.anyStepRecursively(s -> s instanceof LambdaHolder
 -                || (!(s instanceof EdgeOtherVertexStep) && s.getRequirements().contains(TraverserRequirement.PATH)),
root))
 +    public void apply(final Traversal.Admin<?, ?> traversal) {
 +        // using a hidden label marker to denote whether the traversal should not be processed
by this strategy
-         if (traversal.getParent() instanceof EmptyStep && TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEP_CLASSES,
traversal))
++        if (traversal.getParent() instanceof EmptyStep && TraversalHelper.anyStepRecursively(s
-> s instanceof LambdaHolder
++                || (!(s instanceof EdgeOtherVertexStep) && s.getRequirements().contains(TraverserRequirement.PATH)),
traversal))
 +            TraversalHelper.applyTraversalRecursively(t -> t.getStartStep().addLabel(MARKER),
traversal);
 +        if (traversal.getStartStep().getLabels().contains(MARKER)) {
 +            traversal.getStartStep().removeLabel(MARKER);
              return;
 +        }
 +        ////////////////////////////////////////////////////////////////////////////
          final Collection<Pair<VertexStep, Step>> stepsToReplace = new ArrayList<>();
          Step prev = null;
          for (final Step curr : traversal.getSteps()) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fcf9320e/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategyTest.java
----------------------------------------------------------------------
diff --cc gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategyTest.java
index 6e56ab8,3207dc3..c8b4ef2
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategyTest.java
@@@ -36,43 -41,99 +36,45 @@@ import static org.junit.Assert.assertEq
  /**
   * @author Daniel Kuppitz (http://gremlin.guru)
   */
 -@RunWith(Enclosed.class)
 +@RunWith(Parameterized.class)
  public class IncidentToAdjacentStrategyTest {
  
 -    @RunWith(Parameterized.class)
 -    public static class StandardTest extends AbstractIncidentToAdjacentStrategyTest {
 +    @Parameterized.Parameter(value = 0)
 +    public Traversal original;
  
 -        @Parameterized.Parameters(name = "{0}")
 -        public static Iterable<Object[]> data() {
 -            return generateTestParameters();
 -        }
 +    @Parameterized.Parameter(value = 1)
 +    public Traversal optimized;
  
 -        @Parameterized.Parameter(value = 0)
 -        public Traversal original;
 -
 -        @Parameterized.Parameter(value = 1)
 -        public Traversal optimized;
 -
 -        @Before
 -        public void setup() {
 -            this.traversalEngine = mock(TraversalEngine.class);
 -            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.STANDARD);
 -        }
 -
 -        @Test
 -        public void shouldApplyStrategy() {
 -            doTest(original, optimized);
 -        }
 -    }
 -
 -    @RunWith(Parameterized.class)
 -    public static class ComputerTest extends AbstractIncidentToAdjacentStrategyTest {
 -
 -        @Parameterized.Parameters(name = "{0}")
 -        public static Iterable<Object[]> data() {
 -            return generateTestParameters();
 -        }
 -
 -        @Parameterized.Parameter(value = 0)
 -        public Traversal original;
 -
 -        @Parameterized.Parameter(value = 1)
 -        public Traversal optimized;
 -
 -        @Before
 -        public void setup() {
 -            this.traversalEngine = mock(TraversalEngine.class);
 -            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
 -        }
 -
 -        @Test
 -        public void shouldApplyStrategy() {
 -            doTest(original, optimized);
 -        }
 +    @Test
 +    public void doTest() {
 +        final TraversalStrategies strategies = new DefaultTraversalStrategies();
 +        strategies.addStrategies(IncidentToAdjacentStrategy.instance());
 +        this.original.asAdmin().setStrategies(strategies);
 +        this.original.asAdmin().applyStrategies();
 +        assertEquals(this.optimized, this.original);
      }
  
 -    private static abstract class AbstractIncidentToAdjacentStrategyTest {
 -
 -        protected TraversalEngine traversalEngine;
 -
 -        void applyIncidentToAdjacentStrategy(final Traversal traversal) {
 -            final TraversalStrategies strategies = new DefaultTraversalStrategies();
 -            strategies.addStrategies(IncidentToAdjacentStrategy.instance());
 -
 -            traversal.asAdmin().setStrategies(strategies);
 -            traversal.asAdmin().setEngine(this.traversalEngine);
 -            traversal.asAdmin().applyStrategies();
 -
 -        }
 -
 -        public void doTest(final Traversal traversal, final Traversal optimized) {
 -            applyIncidentToAdjacentStrategy(traversal);
 -            assertEquals(optimized, traversal);
 -        }
 -
 -        static Iterable<Object[]> generateTestParameters() {
 -
 -            Function<Traverser<Vertex>, Vertex> lambda = Traverser::get; //
to ensure same hashCode
 -            return Arrays.asList(new Traversal[][]{
 -                    {__.outE().inV(), __.out()},
 -                    {__.inE().outV(), __.in()},
 -                    {__.bothE().otherV(), __.both()},
 -                    {__.outE().outV(), __.outE().outV()},
 -                    {__.inE().inV(), __.inE().inV()},
 -                    {__.bothE().bothV(), __.bothE().bothV()},
 -                    {__.bothE().inV(), __.bothE().inV()},
 -                    {__.bothE().outV(), __.bothE().outV()},
 -                    {__.outE().as("a").inV(), __.outE().as("a").inV()}, // todo: this can
be optimized, but requires a lot more checks
 -                    {__.outE().inV().path(), __.outE().inV().path()},
 -                    {__.outE().inV().simplePath(), __.outE().inV().simplePath()},
 -                    {__.outE().inV().tree(), __.outE().inV().tree()},
 -                    {__.outE().inV().map(lambda), __.outE().inV().map(lambda)},
 -                    {__.union(__.outE().inV(), __.inE().outV()).path(), __.union(__.outE().inV(),
__.inE().outV()).path()},
 -                    {__.as("a").outE().inV().as("b"), __.as("a").out().as("b")}});
 -        }
 +    @Parameterized.Parameters(name = "{0}")
 +    public static Iterable<Object[]> generateTestParameters() {
 +
 +        Function<Traverser<Vertex>, Vertex> lambda = Traverser::get; // to ensure
same hashCode
 +        return Arrays.asList(new Traversal[][]{
 +                {__.outE().inV(), __.out()},
 +                {__.inE().outV(), __.in()},
 +                {__.bothE().otherV(), __.both()},
 +                {__.outE().outV(), __.outE().outV()},
 +                {__.inE().inV(), __.inE().inV()},
 +                {__.bothE().bothV(), __.bothE().bothV()},
 +                {__.bothE().inV(), __.bothE().inV()},
 +                {__.bothE().outV(), __.bothE().outV()},
 +                {__.outE().as("a").inV(), __.outE().as("a").inV()}, // todo: this can be
optimized, but requires a lot more checks
 +                {__.outE().inV().path(), __.outE().inV().path()},
++                {__.outE().inV().simplePath(), __.outE().inV().simplePath()},
++                {__.outE().inV().cyclicPath(), __.outE().inV().cyclicPath()},
 +                {__.outE().inV().tree().as("a"), __.outE().inV().tree().as("a")},
 +                {__.outE().inV().map(lambda), __.outE().inV().map(lambda)},
 +                {__.union(__.outE().inV(), __.inE().outV()).path(), __.union(__.outE().inV(),
__.inE().outV()).path()},
 +                {__.as("a").outE().inV().as("b"), __.as("a").out().as("b")}});
      }
  }
 +


Mime
View raw message