use of org.apache.atlas.groovy.FunctionCallExpression 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);
}
use of org.apache.atlas.groovy.FunctionCallExpression 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;
}
use of org.apache.atlas.groovy.FunctionCallExpression 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;
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class ExpandOrsOptimization method expandOrFunction.
/**
* This method takes an 'or' expression and expands it into multiple expressions.
*
* For example:
*
* g.V().or(has('x'),has('y')
*
* is expanded to:
*
* g.V().has('x')
* g.V().has('y')
*
* There are certain cases where it is not safe to move an expression out
* of the 'or'. For example, in the expression
*
* g.V().or(has('x').out('y'),has('z'))
*
* has('x').out('y') cannot be moved out of the 'or', since it changes the value of the traverser.
*
* At this time, the ExpandOrsOptimizer is not able to handle this scenario, so we don't remove
* that expression. In cases like this, a final expression is created that ors together
* all of the expressions that could not be extracted. In this case that would be:
*
* g.V().has('z')
* g.V().or(has('y').out('z'))
*
* This processing is done recursively.
*
*
* @param expr
* @param context
* @return the expressions that should be unioned together to get the query result
*/
private List<GroovyExpression> expandOrFunction(GroovyExpression expr, OptimizationContext context) {
FunctionCallExpression functionCall = (FunctionCallExpression) expr;
GroovyExpression caller = functionCall.getCaller();
List<GroovyExpression> updatedCallers = null;
if (caller != null) {
updatedCallers = expandOrs(caller, context);
} else {
updatedCallers = Collections.singletonList(null);
}
UpdatedExpressions newArguments = getUpdatedChildren(functionCall.getArguments(), context);
List<GroovyExpression> allUpdatedArguments = new ArrayList<>();
for (List<GroovyExpression> exprs : newArguments.getUpdatedChildren()) {
allUpdatedArguments.addAll(exprs);
}
List<AbstractFunctionExpression> extractableArguments = new ArrayList<>();
List<GroovyExpression> nonExtractableArguments = new ArrayList<>();
for (GroovyExpression argument : allUpdatedArguments) {
if (GremlinQueryOptimizer.isExtractable(argument)) {
extractableArguments.add((AbstractFunctionExpression) argument);
} else {
logger_.warn("Found non-extractable argument '{}; in the 'or' expression '{}'", argument.toString(), expr.toString());
nonExtractableArguments.add(argument);
}
}
List<GroovyExpression> result = new ArrayList<>();
for (GroovyExpression updatedCaller : updatedCallers) {
for (AbstractFunctionExpression arg : extractableArguments) {
GroovyExpression updated = GremlinQueryOptimizer.copyWithNewLeafNode(arg, updatedCaller);
result.add(updated);
}
if (!nonExtractableArguments.isEmpty()) {
result.add(factory.generateLogicalExpression(updatedCaller, "or", nonExtractableArguments));
}
}
return result;
}
use of org.apache.atlas.groovy.FunctionCallExpression in project incubator-atlas by apache.
the class FunctionGenerator method preVisitFunctionCaller.
@Override
public boolean preVisitFunctionCaller(AbstractFunctionExpression expr) {
depth++;
if (IsOr.INSTANCE.apply(expr)) {
FunctionCallExpression functionCall = (FunctionCallExpression) expr;
scaleFactor *= functionCall.getArguments().size();
}
if (newRootExpression == null) {
newRootExpression = expr;
}
return true;
}
Aggregations