Search in sources :

Example 6 with LiteralExpression

use of org.apache.atlas.groovy.LiteralExpression 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 7 with LiteralExpression

use of org.apache.atlas.groovy.LiteralExpression 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 8 with LiteralExpression

use of org.apache.atlas.groovy.LiteralExpression 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)

Example 9 with LiteralExpression

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

the class Gremlin2ExpressionFactory method typeTestExpression.

@Override
public GroovyExpression typeTestExpression(GraphPersistenceStrategies s, String typeName, GroovyExpression itRef) {
    GroovyExpression superTypeAttrExpr = new FieldExpression(itRef, s.superTypeAttributeName());
    GroovyExpression typeNameExpr = new LiteralExpression(typeName);
    GroovyExpression isSuperTypeExpr = new FunctionCallExpression(superTypeAttrExpr, CONTAINS, typeNameExpr);
    GroovyExpression superTypeMatchesExpr = new TernaryOperatorExpression(superTypeAttrExpr, isSuperTypeExpr, LiteralExpression.FALSE);
    GroovyExpression typeAttrExpr = new FieldExpression(itRef, s.typeAttributeName());
    GroovyExpression typeMatchesExpr = new ComparisonExpression(typeAttrExpr, ComparisonOperator.EQUALS, typeNameExpr);
    return new LogicalExpression(typeMatchesExpr, LogicalOperator.OR, superTypeMatchesExpr);
}
Also used : ComparisonExpression(org.apache.atlas.groovy.ComparisonExpression) LogicalExpression(org.apache.atlas.groovy.LogicalExpression) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) TernaryOperatorExpression(org.apache.atlas.groovy.TernaryOperatorExpression) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression) FieldExpression(org.apache.atlas.groovy.FieldExpression)

Example 10 with LiteralExpression

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

the class GremlinExpressionFactory method typeTestExpressionUsingInFilter.

private List<GroovyExpression> typeTestExpressionUsingInFilter(GraphPersistenceStrategies s, GroovyExpression parent, final String typeName) throws AtlasException {
    List<GroovyExpression> typeNames = new ArrayList<>();
    typeNames.add(new LiteralExpression(typeName));
    Map<TYPE_FILTER, String> filters = new HashMap<TYPE_FILTER, String>() {

        {
            put(TYPE_FILTER.SUPERTYPE, typeName);
        }
    };
    ImmutableList<String> subTypes = TypeSystem.getInstance().getTypeNames(filters);
    if (!subTypes.isEmpty()) {
        for (String subType : subTypes) {
            typeNames.add(new LiteralExpression(subType));
        }
    }
    GroovyExpression inFilterExpr = generateHasExpression(s, parent, s.typeAttributeName(), IN_OPERATOR, new ListExpression(typeNames), null);
    return Collections.singletonList(inFilterExpr);
}
Also used : HashMap(java.util.HashMap) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) ListExpression(org.apache.atlas.groovy.ListExpression) ArrayList(java.util.ArrayList) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) TYPE_FILTER(org.apache.atlas.typesystem.types.cache.TypeCache.TYPE_FILTER)

Aggregations

LiteralExpression (org.apache.atlas.groovy.LiteralExpression)22 GroovyExpression (org.apache.atlas.groovy.GroovyExpression)17 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)15 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)5 ComparisonExpression (org.apache.atlas.groovy.ComparisonExpression)3 IdentifierExpression (org.apache.atlas.groovy.IdentifierExpression)3 ArrayList (java.util.ArrayList)2 AbstractFunctionExpression (org.apache.atlas.groovy.AbstractFunctionExpression)2 CastExpression (org.apache.atlas.groovy.CastExpression)2 FieldExpression (org.apache.atlas.groovy.FieldExpression)2 LogicalExpression (org.apache.atlas.groovy.LogicalExpression)2 TernaryOperatorExpression (org.apache.atlas.groovy.TernaryOperatorExpression)2 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)2 IDataType (org.apache.atlas.typesystem.types.IDataType)2 Test (org.testng.annotations.Test)2 HashMap (java.util.HashMap)1 RangeFinder (org.apache.atlas.gremlin.optimizer.RangeFinder)1 ListExpression (org.apache.atlas.groovy.ListExpression)1 TypeCoersionExpression (org.apache.atlas.groovy.TypeCoersionExpression)1 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)1