Search in sources :

Example 11 with GroovyExpression

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

the class Gremlin3ExpressionFactory 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)

Example 12 with GroovyExpression

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

the class Gremlin3ExpressionFactory method generateLoopExpression.

@Override
public GroovyExpression generateLoopExpression(GroovyExpression parent, GraphPersistenceStrategies s, IDataType dataType, GroovyExpression loopExpr, String alias, Integer times) {
    GroovyExpression emitExpr = generateLoopEmitExpression(s, dataType);
    GroovyExpression result = new FunctionCallExpression(TraversalStepType.BRANCH, parent, REPEAT_METHOD, loopExpr);
    if (times != null) {
        GroovyExpression timesExpr = new LiteralExpression(times);
        result = new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, result, TIMES_METHOD, timesExpr);
    }
    result = new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, result, EMIT_METHOD, emitExpr);
    return result;
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 13 with GroovyExpression

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

the class Gremlin3ExpressionFactory method generateOrderByExpression.

@Override
public GroovyExpression generateOrderByExpression(GroovyExpression parent, List<GroovyExpression> translatedOrderBy, boolean isAscending) {
    GroovyExpression orderByExpr = translatedOrderBy.get(0);
    GroovyExpression orderByClosure = new ClosureExpression(orderByExpr);
    GroovyExpression orderByClause = new TypeCoersionExpression(orderByClosure, FUNCTION_CLASS);
    GroovyExpression aExpr = new IdentifierExpression("a");
    GroovyExpression bExpr = new IdentifierExpression("b");
    GroovyExpression aCompExpr = new FunctionCallExpression(new FunctionCallExpression(aExpr, TO_STRING_METHOD), TO_LOWER_CASE_METHOD);
    GroovyExpression bCompExpr = new FunctionCallExpression(new FunctionCallExpression(bExpr, TO_STRING_METHOD), TO_LOWER_CASE_METHOD);
    GroovyExpression comparisonExpr = null;
    if (isAscending) {
        comparisonExpr = new ComparisonOperatorExpression(aCompExpr, bCompExpr);
    } else {
        comparisonExpr = new ComparisonOperatorExpression(bCompExpr, aCompExpr);
    }
    ClosureExpression comparisonFunction = new ClosureExpression(comparisonExpr, "a", "b");
    FunctionCallExpression orderCall = new FunctionCallExpression(TraversalStepType.BARRIER, parent, ORDER_METHOD);
    return new FunctionCallExpression(TraversalStepType.SIDE_EFFECT, orderCall, BY_METHOD, orderByClause, comparisonFunction);
}
Also used : TypeCoersionExpression(org.apache.atlas.groovy.TypeCoersionExpression) ComparisonOperatorExpression(org.apache.atlas.groovy.ComparisonOperatorExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) IdentifierExpression(org.apache.atlas.groovy.IdentifierExpression)

Example 14 with GroovyExpression

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

the class GremlinExpressionFactory method fillVarWithTypeInstances.

private GroovyExpression fillVarWithTypeInstances(GraphPersistenceStrategies s, String typeName, String fillVar) {
    GroovyExpression graphExpr = getAllVerticesExpr();
    GroovyExpression typeAttributeNameExpr = new LiteralExpression(s.typeAttributeName());
    GroovyExpression typeNameExpr = new LiteralExpression(typeName);
    GroovyExpression hasExpr = new FunctionCallExpression(graphExpr, HAS_METHOD, typeAttributeNameExpr, typeNameExpr);
    GroovyExpression fillExpr = new FunctionCallExpression(hasExpr, FILL_METHOD, new IdentifierExpression(fillVar));
    return fillExpr;
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) IdentifierExpression(org.apache.atlas.groovy.IdentifierExpression)

Example 15 with GroovyExpression

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

the class GremlinExpressionFactory method fillVarWithSubTypeInstances.

private GroovyExpression fillVarWithSubTypeInstances(GraphPersistenceStrategies s, String typeName, String fillVar) {
    GroovyExpression graphExpr = getAllVerticesExpr();
    GroovyExpression superTypeAttributeNameExpr = new LiteralExpression(s.superTypeAttributeName());
    GroovyExpression typeNameExpr = new LiteralExpression(typeName);
    GroovyExpression hasExpr = new FunctionCallExpression(graphExpr, HAS_METHOD, superTypeAttributeNameExpr, typeNameExpr);
    GroovyExpression fillExpr = new FunctionCallExpression(hasExpr, FILL_METHOD, new IdentifierExpression(fillVar));
    return fillExpr;
}
Also used : LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) IdentifierExpression(org.apache.atlas.groovy.IdentifierExpression)

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