Search in sources :

Example 31 with GroovyExpression

use of org.apache.atlas.groovy.GroovyExpression 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)

Example 32 with GroovyExpression

use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.

the class AbstractGremlinQueryOptimizerTest method testFinalAlias.

@Test
public void testFinalAlias() throws AtlasException {
    GroovyExpression expr1 = makeHasExpression("name", "Fred");
    GroovyExpression expr2 = makeHasExpression("name", "George");
    GroovyExpression toOptimize = getVerticesExpression();
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
    toOptimize = getFactory().generateAliasExpression(toOptimize, "x");
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestFinalAlias());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) Test(org.testng.annotations.Test)

Example 33 with GroovyExpression

use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.

the class AbstractGremlinQueryOptimizerTest method testToListConversion.

@Test
public void testToListConversion() throws AtlasException {
    GroovyExpression expr1 = makeHasExpression("prop1", "Fred");
    GroovyExpression expr2 = makeHasExpression("prop2", "George");
    GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "or", Arrays.asList(expr1, expr2));
    toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestToListConversion());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) Test(org.testng.annotations.Test)

Example 34 with GroovyExpression

use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.

the class AbstractGremlinQueryOptimizerTest method testHasNotMovedToResult.

@Test
public void testHasNotMovedToResult() throws AtlasException {
    GroovyExpression toOptimize = getVerticesExpression();
    GroovyExpression or1Cond1 = makeHasExpression("p1", "e1");
    GroovyExpression or1Cond2 = makeHasExpression("p2", "e2");
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(or1Cond1, or1Cond2));
    toOptimize = makeHasExpression(toOptimize, "p3", "e3");
    toOptimize = getFactory().generateAliasExpression(toOptimize, "_src");
    toOptimize = getFactory().generateSelectExpression(toOptimize, Collections.singletonList(new LiteralExpression("src1")), Collections.<GroovyExpression>singletonList(new IdentifierExpression("it")));
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestHasNotMovedToResult());
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) IdentifierExpression(org.apache.atlas.groovy.IdentifierExpression) Test(org.testng.annotations.Test)

Example 35 with GroovyExpression

use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.

the class AbstractGremlinQueryOptimizerTest method testAndFollowedByOr.

@Test
public void testAndFollowedByOr() throws AtlasException {
    GroovyExpression expr1 = makeHasExpression("name", "Fred");
    GroovyExpression expr2 = makeHasExpression("name", "George");
    GroovyExpression expr3 = makeHasExpression("age", "13");
    GroovyExpression expr4 = makeHasExpression("age", "14");
    GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "and", Arrays.asList(expr1, expr2));
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr3, expr4));
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestAndFollowedByOr());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) Test(org.testng.annotations.Test)

Aggregations

GroovyExpression (org.apache.atlas.groovy.GroovyExpression)80 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)34 Test (org.testng.annotations.Test)33 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)17 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)16 AbstractFunctionExpression (org.apache.atlas.groovy.AbstractFunctionExpression)11 ArrayList (java.util.ArrayList)9 IdentifierExpression (org.apache.atlas.groovy.IdentifierExpression)6 TypeCoersionExpression (org.apache.atlas.groovy.TypeCoersionExpression)6 CastExpression (org.apache.atlas.groovy.CastExpression)5 FieldExpression (org.apache.atlas.groovy.FieldExpression)5 ComparisonExpression (org.apache.atlas.groovy.ComparisonExpression)4 TernaryOperatorExpression (org.apache.atlas.groovy.TernaryOperatorExpression)4 ListExpression (org.apache.atlas.groovy.ListExpression)3 RangeFinder (org.apache.atlas.gremlin.optimizer.RangeFinder)2 ComparisonOperatorExpression (org.apache.atlas.groovy.ComparisonOperatorExpression)2 LogicalExpression (org.apache.atlas.groovy.LogicalExpression)2 StatementListExpression (org.apache.atlas.groovy.StatementListExpression)2 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)2 IDataType (org.apache.atlas.typesystem.types.IDataType)2