@@ -3508,9 +3508,16 @@ public void testTinkerPopOptimizationStrategies() {
35083508 assertNumStep (10 , 1 , gts .V (sv [0 ]).local (__ .outE ("knows" ).limit (10 )), JanusGraphVertexStep .class );
35093509 assertNumStep (10 , 1 , gts .V (sv [0 ]).local (__ .outE ("knows" ).range (10 , 20 )), LocalStep .class );
35103510 assertNumStep (numV , 2 , gts .V (sv [0 ]).outE ("knows" ).order ().by ("weight" , decr ), JanusGraphVertexStep .class , OrderGlobalStep .class );
3511- assertNumStep (10 , 1 , gts .V (sv [0 ]).local (__ .outE ("knows" ).order ().by ("weight" , decr ).limit (10 )), LocalStep .class );
3511+ // Ensure the LocalStep is dropped because the Order can be folded in the JanusGraphVertexStep which in turn
3512+ // will allow JanusGraphLocalQueryOptimizationStrategy to drop the LocalStep as the local ordering will be
3513+ // provided by the single JanusGraphVertex step
3514+ assertNumStep (10 , 0 , gts .V (sv [0 ]).local (__ .outE ("knows" ).order ().by ("weight" , decr ).limit (10 )), LocalStep .class );
35123515 assertNumStep (numV / 5 , 2 , gts .V (sv [0 ]).outE ("knows" ).has ("weight" , 1 ).order ().by ("weight" , incr ), JanusGraphVertexStep .class , OrderGlobalStep .class );
3513- assertNumStep (10 , 1 , gts .V (sv [0 ]).local (__ .outE ("knows" ).has ("weight" , 1 ).order ().by ("weight" , incr ).limit (10 )), LocalStep .class );
3516+ assertNumStep (10 , 0 , gts .V (sv [0 ]).local (__ .outE ("knows" ).has ("weight" , 1 ).order ().by ("weight" , incr ).limit (10 )), LocalStep .class );
3517+ // Note that for this test, the upper offset of the range will be folded into the JanusGraphVertexStep
3518+ // by JanusGraphLocalQueryOptimizationStrategy, but not the lower offset. The RangeGlobalStep will in turn be kept
3519+ // to enforce this lower bound and the LocalStep will be left as is as the local behavior will have not been
3520+ // entirely subsumed by the JanusGraphVertexStep
35143521 assertNumStep (5 , 1 , gts .V (sv [0 ]).local (__ .outE ("knows" ).has ("weight" , 1 ).has ("weight" , 1 ).order ().by ("weight" , incr ).range (10 , 15 )), LocalStep .class );
35153522 assertNumStep (1 , 1 , gts .V (sv [0 ]).outE ("knows" ).filter (__ .inV ().is (vs [50 ])), JanusGraphVertexStep .class );
35163523 assertNumStep (1 , 1 , gts .V (sv [0 ]).outE ("knows" ).filter (__ .otherV ().is (vs [50 ])), JanusGraphVertexStep .class );
@@ -3520,7 +3527,7 @@ public void testTinkerPopOptimizationStrategies() {
35203527 //Property
35213528 assertNumStep (numV / 5 , 1 , gts .V (sv [0 ]).properties ("names" ).has ("weight" , 1 ), JanusGraphPropertiesStep .class );
35223529 assertNumStep (numV , 1 , gts .V (sv [0 ]).properties ("names" ), JanusGraphPropertiesStep .class );
3523- assertNumStep (10 , 1 , gts .V (sv [0 ]).local (__ .properties ("names" ).order ().by ("weight" , decr ).limit (10 )), LocalStep .class );
3530+ assertNumStep (10 , 0 , gts .V (sv [0 ]).local (__ .properties ("names" ).order ().by ("weight" , decr ).limit (10 )), LocalStep .class );
35243531 assertNumStep (numV , 2 , gts .V (sv [0 ]).outE ("knows" ).values ("weight" ), JanusGraphVertexStep .class , JanusGraphPropertiesStep .class );
35253532
35263533
@@ -3540,15 +3547,16 @@ public void testTinkerPopOptimizationStrategies() {
35403547 assertNumStep (superV * (numV / 5 * 2 ), 2 , gts .V ().has ("id" , sid ).outE ("knows" ).has ("weight" , P .gte (1 )).has ("weight" , P .lt (3 )), JanusGraphStep .class , JanusGraphVertexStep .class );
35413548 assertNumStep (superV * (numV / 5 * 2 ), 2 , gts .V ().has ("id" , sid ).outE ("knows" ).has ("weight" , P .between (1 , 3 )), JanusGraphStep .class , JanusGraphVertexStep .class );
35423549 assertNumStep (superV * 10 , 2 , gts .V ().has ("id" , sid ).local (__ .outE ("knows" ).has ("weight" , P .gte (1 )).has ("weight" , P .lt (3 )).limit (10 )), JanusGraphStep .class , JanusGraphVertexStep .class );
3543- assertNumStep (superV * 10 , 2 , gts .V ().has ("id" , sid ).local (__ .outE ("knows" ).has ("weight" , P .between (1 , 3 )).order ().by ("weight" , decr ).limit (10 )), JanusGraphStep . class , LocalStep .class );
3544-
3550+ assertNumStep (superV * 10 , 1 , gts .V ().has ("id" , sid ).local (__ .outE ("knows" ).has ("weight" , P .between (1 , 3 )).order ().by ("weight" , decr ).limit (10 )), JanusGraphStep .class );
3551+ assertNumStep ( superV * 10 , 0 , gts . V (). has ( "id" , sid ). local ( __ . outE ( "knows" ). has ( "weight" , P . between ( 1 , 3 )). order (). by ( "weight" , decr ). limit ( 10 )), LocalStep . class );
35453552 clopen (option (USE_MULTIQUERY ), true );
35463553 gts = graph .traversal ();
35473554
35483555 assertNumStep (superV * (numV / 5 ), 2 , gts .V ().has ("id" , sid ).outE ("knows" ).has ("weight" , 1 ), JanusGraphStep .class , JanusGraphVertexStep .class );
35493556 assertNumStep (superV * (numV / 5 * 2 ), 2 , gts .V ().has ("id" , sid ).outE ("knows" ).has ("weight" , P .between (1 , 3 )), JanusGraphStep .class , JanusGraphVertexStep .class );
35503557 assertNumStep (superV * 10 , 2 , gts .V ().has ("id" , sid ).local (__ .outE ("knows" ).has ("weight" , P .gte (1 )).has ("weight" , P .lt (3 )).limit (10 )), JanusGraphStep .class , JanusGraphVertexStep .class );
3551- assertNumStep (superV * 10 , 2 , gts .V ().has ("id" , sid ).local (__ .outE ("knows" ).has ("weight" , P .between (1 , 3 )).order ().by ("weight" , decr ).limit (10 )), JanusGraphStep .class , LocalStep .class );
3558+ assertNumStep (superV * 10 , 1 , gts .V ().has ("id" , sid ).local (__ .outE ("knows" ).has ("weight" , P .between (1 , 3 )).order ().by ("weight" , decr ).limit (10 )), JanusGraphStep .class );
3559+ assertNumStep (superV * 10 , 0 , gts .V ().has ("id" , sid ).local (__ .outE ("knows" ).has ("weight" , P .between (1 , 3 )).order ().by ("weight" , decr ).limit (10 )), LocalStep .class );
35523560 assertNumStep (superV * numV , 2 , gts .V ().has ("id" , sid ).values ("names" ), JanusGraphStep .class , JanusGraphPropertiesStep .class );
35533561
35543562 //Verify traversal metrics when all reads are from cache (i.e. no backend queries)
@@ -3582,19 +3590,19 @@ private static void assertNumStep(int expectedResults, int expectedSteps, GraphT
35823590 traversal .next ();
35833591 num ++;
35843592 }
3585- // System.out.println(traversal);
3593+
35863594 assertEquals (expectedResults , num );
35873595
35883596 //Verify that steps line up with what is expected after JanusGraph's optimizations are applied
35893597 List <Step > steps = traversal .asAdmin ().getSteps ();
35903598 Set <Class <? extends Step >> expSteps = Sets .newHashSet (expectedStepTypes );
35913599 int numSteps = 0 ;
35923600 for (Step s : steps ) {
3593- // System.out.println(s.getClass());
35943601 if (s .getClass ().equals (GraphStep .class ) || s .getClass ().equals (StartStep .class )) continue ;
35953602
3596- assertTrue (s .getClass ().getName (), expSteps .contains (s .getClass ()));
3597- numSteps ++;
3603+ if (expSteps .contains (s .getClass ())) {
3604+ numSteps ++;
3605+ }
35983606 }
35993607 assertEquals (expectedSteps , numSteps );
36003608 }
0 commit comments