Search in sources :

Example 36 with FunctionCallExpression

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

the class AliasFinder method postVisitFunctionCaller.

@Override
public boolean postVisitFunctionCaller(AbstractFunctionExpression functionCall) {
    if (functionCall instanceof FunctionCallExpression) {
        FunctionCallExpression expr = (FunctionCallExpression) functionCall;
        if (expr.getType() == TraversalStepType.SIDE_EFFECT && expr.getFunctionName().equals("as")) {
            //We found an alias.  This is currently the last expression we've seen
            //in our traversal back up the expression tree, so at this point a final
            //alias is not needed.
            LiteralExpression aliasNameExpr = (LiteralExpression) expr.getArguments().get(0);
            foundAliases.add(aliasNameExpr);
            finalAliasNeeded = false;
        }
    }
    if (TRANSFORMATION_STEP_TYPES.contains(functionCall.getType())) {
        //needs to be added.
        if (!foundAliases.isEmpty()) {
            finalAliasNeeded = true;
        }
    }
    return true;
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 37 with FunctionCallExpression

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

the class IsOrParent method apply.

@Override
public Boolean apply(GroovyExpression expr) {
    if (!(expr instanceof AbstractFunctionExpression)) {
        return false;
    }
    AbstractFunctionExpression functionCall = (AbstractFunctionExpression) expr;
    GroovyExpression target = functionCall.getCaller();
    if (!(target instanceof FunctionCallExpression)) {
        return false;
    }
    if (target.getType() != TraversalStepType.FILTER) {
        return false;
    }
    FunctionCallExpression targetFunction = (FunctionCallExpression) target;
    return targetFunction.getFunctionName().equals("or");
}
Also used : AbstractFunctionExpression(org.apache.atlas.groovy.AbstractFunctionExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 38 with FunctionCallExpression

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

the class FunctionGenerator method postVisitFunctionCaller.

@Override
public boolean postVisitFunctionCaller(AbstractFunctionExpression expr) {
    boolean isRootExpr = depth == 1;
    visitParentExpression(expr);
    //to examine the root expression.
    if (isRootExpr) {
        FunctionCallExpression dummyParent = new FunctionCallExpression(expr, "dummy");
        visitParentExpression(dummyParent);
        newRootExpression = dummyParent.getCaller();
    }
    depth--;
    return true;
}
Also used : FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 39 with FunctionCallExpression

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

the class Gremlin3ExpressionFactory method generateLikeExpressionUsingFilter.

@Override
public GroovyExpression generateLikeExpressionUsingFilter(GroovyExpression parent, String propertyName, GroovyExpression propertyValue) throws AtlasException {
    GroovyExpression itExpr = getItVariable();
    GroovyExpression nameExpr = new FieldExpression(itExpr, propertyName);
    GroovyExpression matchesExpr = new FunctionCallExpression(nameExpr, MATCHES, escapePropertyValue(propertyValue));
    GroovyExpression closureExpr = new ClosureExpression(matchesExpr);
    GroovyExpression filterExpr = new FunctionCallExpression(parent, FILTER_METHOD, closureExpr);
    return filterExpr;
}
Also used : GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) FieldExpression(org.apache.atlas.groovy.FieldExpression)

Example 40 with FunctionCallExpression

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

the class Gremlin3ExpressionFactory method generateGroupByExpression.

@Override
public GroovyExpression generateGroupByExpression(GroovyExpression parent, GroovyExpression groupByExpression, GroovyExpression aggregationFunction) {
    GroovyExpression result = new FunctionCallExpression(TraversalStepType.BARRIER, parent, "group");
    GroovyExpression groupByClosureExpr = new TypeCoersionExpression(new ClosureExpression(groupByExpression), "Function");
    result = new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, result, "by", groupByClosureExpr);
    result = new FunctionCallExpression(TraversalStepType.END, result, "toList");
    GroovyExpression mapValuesClosure = new ClosureExpression(new FunctionCallExpression(new CastExpression(getItVariable(), "Map"), "values"));
    result = new FunctionCallExpression(result, "collect", mapValuesClosure);
    //when we call Map.values(), we end up with an extra list around the result.  We remove this by calling toList().get(0).  This
    //leaves us with a list of lists containing the vertices that match each group.  We then apply the aggregation functions
    //specified in the select list to each of these inner lists.
    result = new FunctionCallExpression(result, "toList");
    result = new FunctionCallExpression(result, "get", new LiteralExpression(0));
    GroovyExpression aggregrationFunctionClosure = new ClosureExpression(aggregationFunction);
    result = new FunctionCallExpression(result, "collect", aggregrationFunctionClosure);
    return result;
}
Also used : TypeCoersionExpression(org.apache.atlas.groovy.TypeCoersionExpression) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) CastExpression(org.apache.atlas.groovy.CastExpression) 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