Search in sources :

Example 41 with GroovyExpression

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

the class Gremlin2ExpressionFactory method generateSelectExpression.

@Override
public GroovyExpression generateSelectExpression(GroovyExpression parent, List<LiteralExpression> sourceNames, List<GroovyExpression> srcExprs) {
    GroovyExpression srcNamesExpr = new ListExpression(sourceNames);
    List<GroovyExpression> selectArgs = new ArrayList<>();
    selectArgs.add(srcNamesExpr);
    for (GroovyExpression expr : srcExprs) {
        selectArgs.add(new ClosureExpression(expr));
    }
    return new FunctionCallExpression(TraversalStepType.MAP_TO_VALUE, parent, SELECT_METHOD, selectArgs);
}
Also used : ListExpression(org.apache.atlas.groovy.ListExpression) ArrayList(java.util.ArrayList) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 42 with GroovyExpression

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

the class Gremlin3ExpressionFactory method initialExpression.

@Override
protected GroovyExpression initialExpression(GroovyExpression varExpr, GraphPersistenceStrategies s) {
    // this bit of groovy magic converts the set of vertices in varName into
    // a String containing the ids of all the vertices. This becomes the
    // argument
    // to g.V(). This is needed because Gremlin 3 does not support
    // _()
    // s"g.V(${varName}.collect{it.id()} as String[])"
    GroovyExpression gExpr = getGraphExpression();
    GroovyExpression varRefExpr = new TypeCoersionExpression(varExpr, OBJECT_ARRAY_CLASS);
    GroovyExpression matchingVerticesExpr = new FunctionCallExpression(TraversalStepType.START, gExpr, V_METHOD, varRefExpr);
    GroovyExpression isEmpty = new FunctionCallExpression(varExpr, "isEmpty");
    GroovyExpression emptyGraph = getEmptyTraversalExpression();
    GroovyExpression expr = new TernaryOperatorExpression(isEmpty, emptyGraph, matchingVerticesExpr);
    return s.addInitialQueryCondition(expr);
}
Also used : TypeCoersionExpression(org.apache.atlas.groovy.TypeCoersionExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) TernaryOperatorExpression(org.apache.atlas.groovy.TernaryOperatorExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 43 with GroovyExpression

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

the class Gremlin2ExpressionFactory 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 44 with GroovyExpression

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

the class Gremlin2ExpressionFactory method generateHasExpression.

@Override
public GroovyExpression generateHasExpression(GraphPersistenceStrategies s, GroovyExpression parent, String propertyName, String symbol, GroovyExpression requiredValue, FieldInfo fInfo) throws AtlasException {
    GroovyExpression op = gremlin2CompOp(symbol);
    GroovyExpression propertyNameExpr = new LiteralExpression(propertyName);
    return new FunctionCallExpression(TraversalStepType.FILTER, parent, HAS_METHOD, propertyNameExpr, op, requiredValue);
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 45 with GroovyExpression

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

the class Gremlin2ExpressionFactory method escapePropertyValue.

private GroovyExpression escapePropertyValue(GroovyExpression propertyValue) {
    GroovyExpression ret = propertyValue;
    if (propertyValue instanceof LiteralExpression) {
        LiteralExpression exp = (LiteralExpression) propertyValue;
        if (exp != null && exp.getValue() instanceof String) {
            String stringValue = (String) exp.getValue();
            // replace '*' with ".*", replace '?' with '.'
            stringValue = stringValue.replaceAll("\\*", ".*").replaceAll("\\?", ".");
            ret = new LiteralExpression(stringValue);
        }
    }
    return ret;
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression)

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