Search in sources :

Example 26 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testOptimizeLoopExpression.

@Test
public void testOptimizeLoopExpression() throws AtlasException {
    GroovyExpression input = getVerticesExpression();
    input = getFactory().generateTypeTestExpression(STRATEGY, input, "DataSet", TestIntSequence.INSTANCE).get(0);
    input = makeHasExpression(input, "name", "Fred");
    input = getFactory().generateAliasExpression(input, "label");
    GroovyExpression loopExpr = getFactory().getLoopExpressionParent(input);
    loopExpr = getFactory().generateAdjacentVerticesExpression(loopExpr, AtlasEdgeDirection.IN, "inputTables");
    loopExpr = getFactory().generateAdjacentVerticesExpression(loopExpr, AtlasEdgeDirection.OUT, "outputTables");
    GroovyExpression result = getFactory().generateLoopExpression(input, STRATEGY, DataTypes.STRING_TYPE, loopExpr, "label", null);
    result = getFactory().generateToListExpression(result);
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(result);
    assertEquals(optimized.toString(), getExpectedGremlinForOptimizeLoopExpression());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) Test(org.testng.annotations.Test)

Example 27 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testFieldExpressionPushedToResultExpression.

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

Example 28 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testAddClosureNoExitExpression.

@Test
public void testAddClosureNoExitExpression() throws AtlasException {
    GroovyExpression expr1 = makeHasExpression("prop1", "Fred");
    GroovyExpression expr2 = makeHasExpression("prop2", "George");
    GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "or", Arrays.asList(expr1, expr2));
    toOptimize = makeOutExpression(toOptimize, "knows");
    toOptimize = makeOutExpression(toOptimize, "livesIn");
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestAddClosureNoExitExpression());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) Test(org.testng.annotations.Test)

Example 29 with GroovyExpression

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

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

the class AbstractGremlinQueryOptimizerTest method testSimpleRangeExpression.

@Test
public void testSimpleRangeExpression() throws AtlasException {
    GroovyExpression expr1 = makeHasExpression(null, "name", "Fred");
    GroovyExpression expr2 = makeHasExpression(null, "name", "George");
    GroovyExpression expr3 = makeHasExpression(null, "age", "34");
    GroovyExpression expr4 = makeHasExpression(null, "size", "small");
    GroovyExpression toOptimize = getVerticesExpression();
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "and", Collections.singletonList(expr3));
    toOptimize = getFactory().generateAdjacentVerticesExpression(toOptimize, AtlasEdgeDirection.OUT, "eats");
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "and", Collections.singletonList(expr4));
    toOptimize = makeHasExpression(toOptimize, "color", "blue");
    toOptimize = getFactory().generateRangeExpression(toOptimize, 0, 10);
    toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
    toOptimize = new FunctionCallExpression(toOptimize, "size");
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestSimpleRangeExpression());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) 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