use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class GremlinExpressionFactory method removeExtraMapFromPathInResult.
public GroovyExpression removeExtraMapFromPathInResult(GroovyExpression parent) {
GroovyExpression listItem = getItVariable();
GroovyExpression tailExpr = new FunctionCallExpression(listItem, "tail");
return new FunctionCallExpression(parent, "collect", new ClosureExpression(tailExpr));
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class GremlinExpressionFactory method typeTestExpressionMultiStep.
private List<GroovyExpression> typeTestExpressionMultiStep(GraphPersistenceStrategies s, String typeName, IntSequence intSeq) {
String varName = "_var_" + intSeq.next();
GroovyExpression varExpr = new IdentifierExpression(varName);
List<GroovyExpression> result = new ArrayList<>();
result.add(newSetVar(varName));
result.add(fillVarWithTypeInstances(s, typeName, varName));
result.add(fillVarWithSubTypeInstances(s, typeName, varName));
result.add(initialExpression(varExpr, s));
return result;
}
use of org.apache.atlas.groovy.GroovyExpression 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);
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class GremlinQueryOptimizer method optimize.
/**
* Optimizes the expression using the given optimization
* @param source
* @param optimization
* @param context
* @return
*/
private GroovyExpression optimize(GroovyExpression source, GremlinOptimization optimization, OptimizationContext context) {
GroovyExpression result = source;
if (optimization.appliesTo(source, context)) {
//Apply the optimization to the expression.
result = optimization.apply(source, context);
}
if (optimization.isApplyRecursively()) {
//Visit the children, update result with the optimized
//children.
List<GroovyExpression> updatedChildren = new ArrayList<>();
boolean changed = false;
for (GroovyExpression child : result.getChildren()) {
//Recursively optimize this child.
GroovyExpression updatedChild = optimize(child, optimization, context);
changed |= updatedChild != child;
updatedChildren.add(updatedChild);
}
if (changed) {
//TBD - Can we update in place rather than making a copy?
result = result.copy(updatedChildren);
}
}
return result;
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testMultipleAliases.
@Test
public void testMultipleAliases() throws AtlasException {
GroovyExpression expr1 = makeHasExpression("name", "Fred");
GroovyExpression expr2 = makeHasExpression("name", "George");
GroovyExpression expr3 = makeHasExpression("age", "13");
GroovyExpression expr4 = makeHasExpression("age", "14");
GroovyExpression toOptimize = getVerticesExpression();
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
toOptimize = getFactory().generateAliasExpression(toOptimize, "x");
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr3, expr4));
toOptimize = getFactory().generateAliasExpression(toOptimize, "y");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGreminForTestMultipleAliases());
}
Aggregations