use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testOptimizeLoopExpression.
@Test
public void testOptimizeLoopExpression() throws AtlasException {
GroovyExpression input = getVerticesExpression();
input = getFactory().generateTypeTestExpression(STRATEGY, input, "DataSet", TestIntSequence.INSTANCE).get(0);
input = makeHasExpression(input, "name", "Fred");
input = getFactory().generateAliasExpression(input, "label");
GroovyExpression loopExpr = getFactory().getLoopExpressionParent(input);
loopExpr = getFactory().generateAdjacentVerticesExpression(loopExpr, AtlasEdgeDirection.IN, "inputTables");
loopExpr = getFactory().generateAdjacentVerticesExpression(loopExpr, AtlasEdgeDirection.OUT, "outputTables");
GroovyExpression result = getFactory().generateLoopExpression(input, STRATEGY, DataTypes.STRING_TYPE, loopExpr, "label", null);
result = getFactory().generateToListExpression(result);
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(result);
assertEquals(optimized.toString(), getExpectedGremlinForOptimizeLoopExpression());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testFieldExpressionPushedToResultExpression.
@Test
public void testFieldExpressionPushedToResultExpression() throws AtlasException {
GroovyExpression expr1 = makeHasExpression("name", "Fred");
GroovyExpression expr2 = makeHasExpression(makeOutExpression(null, "knows"), "name", "George");
GroovyExpression toOptimize = getVerticesExpression();
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
toOptimize = makeFieldExpression(toOptimize, "name");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestFieldExpressionPushedToResultExpression());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testAddClosureNoExitExpression.
@Test
public void testAddClosureNoExitExpression() throws AtlasException {
GroovyExpression expr1 = makeHasExpression("prop1", "Fred");
GroovyExpression expr2 = makeHasExpression("prop2", "George");
GroovyExpression toOptimize = getFactory().generateLogicalExpression(getVerticesExpression(), "or", Arrays.asList(expr1, expr2));
toOptimize = makeOutExpression(toOptimize, "knows");
toOptimize = makeOutExpression(toOptimize, "livesIn");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestAddClosureNoExitExpression());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testRangeWithNonZeroOffset.
@Test
public void testRangeWithNonZeroOffset() throws Exception {
// g.V().or(has('__typeName','OMAS_OMRSAsset'),has('__superTypeNames','OMAS_OMRSAsset')).range(5,10).as('inst').select('inst')
GroovyExpression toOptimize = getVerticesExpression();
GroovyExpression expr0 = makeHasExpression("__typeName", "OMAS_OMRSAsset");
GroovyExpression expr1 = makeHasExpression("__superTypeNames", "OMAS_OMRSAsset");
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr0, expr1));
toOptimize = getFactory().generateRangeExpression(toOptimize, 5, 10);
toOptimize = getFactory().generateAliasExpression(toOptimize, "inst");
toOptimize = getFactory().generateSelectExpression(toOptimize, Collections.singletonList(new LiteralExpression("inst")), Collections.<GroovyExpression>emptyList());
RangeFinder visitor = new RangeFinder(getFactory());
GremlinQueryOptimizer.visitCallHierarchy(toOptimize, visitor);
List<AbstractFunctionExpression> rangeExpressions = visitor.getRangeExpressions();
assertEquals(rangeExpressions.size(), 1);
int[] rangeParameters = getFactory().getRangeParameters(rangeExpressions.get(0));
assertNotNull(rangeParameters);
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
// The range optimization is not supported with a non-zero start index, so the optimizer should not add range expressions
// to the expanded or's.
assertEquals(optimized.toString(), getExpectedGremlinForTestRangeWithNonZeroOffset());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testSimpleRangeExpression.
@Test
public void testSimpleRangeExpression() throws AtlasException {
GroovyExpression expr1 = makeHasExpression(null, "name", "Fred");
GroovyExpression expr2 = makeHasExpression(null, "name", "George");
GroovyExpression expr3 = makeHasExpression(null, "age", "34");
GroovyExpression expr4 = makeHasExpression(null, "size", "small");
GroovyExpression toOptimize = getVerticesExpression();
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
toOptimize = getFactory().generateLogicalExpression(toOptimize, "and", Collections.singletonList(expr3));
toOptimize = getFactory().generateAdjacentVerticesExpression(toOptimize, AtlasEdgeDirection.OUT, "eats");
toOptimize = getFactory().generateLogicalExpression(toOptimize, "and", Collections.singletonList(expr4));
toOptimize = makeHasExpression(toOptimize, "color", "blue");
toOptimize = getFactory().generateRangeExpression(toOptimize, 0, 10);
toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
toOptimize = new FunctionCallExpression(toOptimize, "size");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestSimpleRangeExpression());
}
Aggregations