use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class GremlinQueryOptimizer method visitCallHierarchy.
/**
* Visits all expressions in the call hierarchy of an expression. For example,
* in the expression g.V().has('x','y'), the order would be
* <ol>
* <li>pre-visit has('x','y')</li>
* <li>pre-visit V()</li>
* <li>visit g (non-function caller)</li>
* <li>post-visit V()</li>
* <li>post-visit has('x','y')</li>
* </ol>
* @param expr
* @param visitor
*/
public static void visitCallHierarchy(GroovyExpression expr, CallHierarchyVisitor visitor) {
if (expr == null) {
visitor.visitNullCaller();
return;
}
if (expr instanceof AbstractFunctionExpression) {
AbstractFunctionExpression functionCall = (AbstractFunctionExpression) expr;
if (!visitor.preVisitFunctionCaller(functionCall)) {
return;
}
GroovyExpression caller = functionCall.getCaller();
visitCallHierarchy(caller, visitor);
if (!visitor.postVisitFunctionCaller(functionCall)) {
return;
}
} else {
visitor.visitNonFunctionCaller(expr);
}
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class GremlinQueryOptimizer method copyWithNewLeafNode.
/**
* Recursively copies and follows the caller hierarchy of the expression until we come
* to a function call with a null caller. The caller of that expression is set
* to newLeaf.
*
* @param expr
* @param newLeaf
* @return the updated (/copied) expression
*/
public static GroovyExpression copyWithNewLeafNode(AbstractFunctionExpression expr, GroovyExpression newLeaf) {
AbstractFunctionExpression result = (AbstractFunctionExpression) expr.copy();
//remove leading anonymous traversal expression, if there is one
if (FACTORY.isLeafAnonymousTraversalExpression(expr)) {
result = (AbstractFunctionExpression) newLeaf;
} else {
GroovyExpression newCaller = null;
if (expr.getCaller() == null) {
newCaller = newLeaf;
} else {
newCaller = copyWithNewLeafNode((AbstractFunctionExpression) result.getCaller(), newLeaf);
}
result.setCaller(newCaller);
}
return result;
}
use of org.apache.atlas.groovy.GroovyExpression 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");
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class OptimizationContext method getDefineResultVariableStmt.
public GroovyExpression getDefineResultVariableStmt() {
GroovyExpression castExpression = new TypeCoersionExpression(new ListExpression(), "Set");
GroovyExpression resultVarDef = new VariableAssignmentExpression(RESULT_VARIABLE, castExpression);
return resultVarDef;
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class ExpandOrsOptimization method addCallToUpdateResultVariable.
/**
* This method adds steps to the end of the initial traversal to add the vertices
* that were found into an intermediate variable (defined as a Set). If there is one alias,
* this set will contain the vertices associated with that Alias. If there are multiple
* aliases, the values in the set will be alias->vertex maps that have the vertex
* associated with the alias for each result.
* @param expr
* @param aliasNames
* @param context
* @return
*/
private GroovyExpression addCallToUpdateResultVariable(GroovyExpression expr, List<LiteralExpression> aliasNames, OptimizationContext context) {
GroovyExpression result = expr;
// If there is one range expression in the unoptimized gremlin,
// add a range expression here so that the intermediate variable will only contain
// the specified range of vertices.
AbstractFunctionExpression rangeExpression = context.getRangeExpression();
if (rangeExpression != null) {
int[] rangeParameters = factory.getRangeParameters(rangeExpression);
result = factory.generateRangeExpression(result, rangeParameters[0], rangeParameters[1]);
}
if (!aliasNames.isEmpty()) {
result = factory.generateSelectExpression(result, aliasNames, Collections.<GroovyExpression>emptyList());
}
return factory.generateFillExpression(result, context.getResultVariable());
}
Aggregations