Search in sources :

Example 71 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testOrWithNoChildren.

@Test
public void testOrWithNoChildren() throws AtlasException {
    GroovyExpression toOptimize = getVerticesExpression();
    GroovyExpression expr1 = makeHasExpression(toOptimize, "name", "Fred");
    toOptimize = getFactory().generateLogicalExpression(expr1, "or", Collections.<GroovyExpression>emptyList());
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    //or with no children matches no vertices
    assertEquals(optimized.toString(), getExpectedGremlinFortestOrWithNoChildren());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) Test(org.testng.annotations.Test)

Example 72 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testPullHasExpressionsOutOfAnd.

@Test
public void testPullHasExpressionsOutOfAnd() throws AtlasException {
    GroovyExpression expr1 = makeOutExpression(null, "out1");
    GroovyExpression expr2 = makeOutExpression(null, "out2");
    GroovyExpression expr3 = makeHasExpression("prop1", "Fred");
    GroovyExpression expr4 = makeHasExpression("prop2", "George");
    GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "and", Arrays.asList(expr1, expr2, expr3, expr4));
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestPullHasExpressionsOutOfHas());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) Test(org.testng.annotations.Test)

Example 73 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testToListWithExtraStuff.

@Test
public void testToListWithExtraStuff() 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");
    toOptimize = new FunctionCallExpression(toOptimize, "size");
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestToListWithExtraStuff());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) Test(org.testng.annotations.Test)

Example 74 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testAliasInOrExpr.

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

Example 75 with GroovyExpression

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

the class AbstractGremlinQueryOptimizerTest method testInitialAlias.

@Test
public void testInitialAlias() throws AtlasException {
    GroovyExpression expr1 = makeHasExpression("name", "Fred");
    GroovyExpression expr2 = makeHasExpression("name", "George");
    GroovyExpression toOptimize = getVerticesExpression();
    toOptimize = getFactory().generateAliasExpression(toOptimize, "x");
    toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestInitialAlias());
}
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