Search in sources :

Example 31 with FunctionCallExpression

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

the class AbstractGremlinQueryOptimizerTest method testAddClosureWithExitExpressionDifferentFromExpr.

public void testAddClosureWithExitExpressionDifferentFromExpr() 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");
    toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
    toOptimize = new FunctionCallExpression(toOptimize, "size");
    GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
    assertEquals(optimized.toString(), getExpectedGremlinForTestAddClosureWithExitExpressionDifferentFromExpr());
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 32 with FunctionCallExpression

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

the class AbstractGremlinQueryOptimizerTest method testAddClosureWithExitExpressionEqualToExpr.

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

Example 33 with FunctionCallExpression

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

the class GremlinExpressionFactory method getAliasNameIfRelevant.

/**
     * Checks if the given expression is an alias expression, and if so
     * returns the alias from the expression.  Otherwise, null is
     * returned.
     */
public String getAliasNameIfRelevant(GroovyExpression expr) {
    if (!(expr instanceof FunctionCallExpression)) {
        return null;
    }
    FunctionCallExpression fc = (FunctionCallExpression) expr;
    if (!fc.getFunctionName().equals(AS_METHOD)) {
        return null;
    }
    LiteralExpression aliasName = (LiteralExpression) fc.getArguments().get(0);
    return aliasName.getValue().toString();
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 34 with FunctionCallExpression

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

the class GremlinExpressionFactory method typeTestExpressionUsingFilter.

private List<GroovyExpression> typeTestExpressionUsingFilter(GraphPersistenceStrategies s, GroovyExpression parent, String typeName) {
    GroovyExpression itExpr = getItVariable();
    GroovyExpression typeTestExpr = typeTestExpression(s, typeName, itExpr);
    GroovyExpression closureExpr = new ClosureExpression(typeTestExpr);
    GroovyExpression filterExpr = new FunctionCallExpression(parent, FILTER_METHOD, closureExpr);
    return Collections.singletonList(filterExpr);
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 35 with FunctionCallExpression

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

the class GremlinExpressionFactory method getAggregrationExpression.

private GroovyExpression getAggregrationExpression(GroovyExpression itExpr, GroovyExpression mapFunction, String functionName) {
    GroovyExpression collectionExpr = new CastExpression(itExpr, "Collection");
    ClosureExpression collectFunction = new ClosureExpression(mapFunction);
    GroovyExpression transformedList = new FunctionCallExpression(collectionExpr, "collect", collectFunction);
    return new FunctionCallExpression(transformedList, functionName);
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) CastExpression(org.apache.atlas.groovy.CastExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Aggregations

FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)42 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)34 LiteralExpression (org.apache.atlas.groovy.LiteralExpression)15 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)14 CastExpression (org.apache.atlas.groovy.CastExpression)5 TypeCoersionExpression (org.apache.atlas.groovy.TypeCoersionExpression)5 AbstractFunctionExpression (org.apache.atlas.groovy.AbstractFunctionExpression)4 ComparisonExpression (org.apache.atlas.groovy.ComparisonExpression)4 FieldExpression (org.apache.atlas.groovy.FieldExpression)4 IdentifierExpression (org.apache.atlas.groovy.IdentifierExpression)4 TernaryOperatorExpression (org.apache.atlas.groovy.TernaryOperatorExpression)4 Test (org.testng.annotations.Test)4 ArrayList (java.util.ArrayList)3 ComparisonOperatorExpression (org.apache.atlas.groovy.ComparisonOperatorExpression)2 LogicalExpression (org.apache.atlas.groovy.LogicalExpression)2 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)2 IDataType (org.apache.atlas.typesystem.types.IDataType)2 VariableDeclaration (org.apache.atlas.groovy.ClosureExpression.VariableDeclaration)1 ListExpression (org.apache.atlas.groovy.ListExpression)1 TraversalStepType (org.apache.atlas.groovy.TraversalStepType)1