Search in sources :

Example 1 with RangeFinder

use of org.apache.atlas.gremlin.optimizer.RangeFinder in project incubator-atlas by apache.

the class AbstractGremlinQueryOptimizerTest method testRangeWithNonZeroOffset.

@Test
public void testRangeWithNonZeroOffset() throws Exception {
    // g.V().or(has('__typeName','OMAS_OMRSAsset'),has('__superTypeNames','OMAS_OMRSAsset')).range(5,10).as('inst').select('inst')
    GroovyExpression toOptimize = getVerticesExpression();
    GroovyExpression expr0 = makeHasExpression("__typeName", "OMAS_OMRSAsset");
    GroovyExpression expr1 = makeHasExpression("__superTypeNames", "OMAS_OMRSAsset");
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr0, expr1));
    toOptimize = getFactory().generateRangeExpression(toOptimize, 5, 10);
    toOptimize = getFactory().generateAliasExpression(toOptimize, "inst");
    toOptimize = getFactory().generateSelectExpression(toOptimize, Collections.singletonList(new LiteralExpression("inst")), Collections.<GroovyExpression>emptyList());
    RangeFinder visitor = new RangeFinder(getFactory());
    GremlinQueryOptimizer.visitCallHierarchy(toOptimize, visitor);
    List<AbstractFunctionExpression> rangeExpressions = visitor.getRangeExpressions();
    assertEquals(rangeExpressions.size(), 1);
    int[] rangeParameters = getFactory().getRangeParameters(rangeExpressions.get(0));
    assertNotNull(rangeParameters);
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    // The range optimization is not supported with a non-zero start index, so the optimizer should not add range expressions
    // to the expanded or's.
    assertEquals(optimized.toString(), getExpectedGremlinForTestRangeWithNonZeroOffset());
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) RangeFinder(org.apache.atlas.gremlin.optimizer.RangeFinder) AbstractFunctionExpression(org.apache.atlas.groovy.AbstractFunctionExpression) Test(org.testng.annotations.Test)

Example 2 with RangeFinder

use of org.apache.atlas.gremlin.optimizer.RangeFinder in project incubator-atlas by apache.

the class AbstractGremlinQueryOptimizerTest method testRangeWithOrderBy.

@Test
public void testRangeWithOrderBy() throws Exception {
    // The range optimization is not supported with order, so the optimizer should not add range expressions
    // to the expanded or's.
    GroovyExpression toOptimize = getVerticesExpression();
    GroovyExpression expr0 = makeHasExpression("__typeName", "OMAS_OMRSAsset");
    GroovyExpression expr1 = makeHasExpression("__superTypeNames", "OMAS_OMRSAsset");
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr0, expr1));
    toOptimize = getFactory().generateRangeExpression(toOptimize, 5, 10);
    toOptimize = getFactory().generateAliasExpression(toOptimize, "inst");
    //toOptimize = getFactory().generateSelectExpression(toOptimize, Collections.singletonList(new LiteralExpression("inst")), Collections.<GroovyExpression>emptyList());
    GroovyExpression orderFielda = makeFieldExpression(getFactory().getCurrentTraverserObject(getFactory().getClosureArgumentValue()), "name");
    GroovyExpression orderFieldb = makeFieldExpression(getFactory().getCurrentTraverserObject(getFactory().getClosureArgumentValue()), "name");
    toOptimize = getFactory().generateOrderByExpression(toOptimize, Arrays.asList(orderFielda, orderFieldb), true);
    RangeFinder visitor = new RangeFinder(getFactory());
    GremlinQueryOptimizer.visitCallHierarchy(toOptimize, visitor);
    List<AbstractFunctionExpression> rangeExpressions = visitor.getRangeExpressions();
    assertEquals(rangeExpressions.size(), 1);
    int[] rangeParameters = getFactory().getRangeParameters(rangeExpressions.get(0));
    assertNotNull(rangeParameters);
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestRangeWithOrderBy());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) RangeFinder(org.apache.atlas.gremlin.optimizer.RangeFinder) AbstractFunctionExpression(org.apache.atlas.groovy.AbstractFunctionExpression) Test(org.testng.annotations.Test)

Aggregations

RangeFinder (org.apache.atlas.gremlin.optimizer.RangeFinder)2 AbstractFunctionExpression (org.apache.atlas.groovy.AbstractFunctionExpression)2 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)2 Test (org.testng.annotations.Test)2 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)1