use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testAddClosureWithExitExpressionEqualToExpr.
@Test
public void testAddClosureWithExitExpressionEqualToExpr() 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");
toOptimize = new FunctionCallExpression(TraversalStepType.END, toOptimize, "toList");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestAddClosureWithExitExpressionEqualToExpr());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testMassiveOrExpansion.
@Test
public void testMassiveOrExpansion() throws AtlasException {
GroovyExpression toOptimize = getVerticesExpression();
toOptimize = makeHasExpression(toOptimize, "h1", "h2");
toOptimize = makeHasExpression(toOptimize, "h3", "h4");
for (int i = 0; i < 5; i++) {
GroovyExpression expr1 = makeHasExpression("p1" + i, "e1" + i);
GroovyExpression expr2 = makeHasExpression("p2" + i, "e2" + i);
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(expr1, expr2));
toOptimize = makeHasExpression(toOptimize, "ha" + i, "hb" + i);
toOptimize = makeHasExpression(toOptimize, "hc" + i, "hd" + i);
}
toOptimize = makeHasExpression(toOptimize, "h5", "h6");
toOptimize = makeHasExpression(toOptimize, "h7", "h8");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestMassiveOrExpansion());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testFlatMapExprInOr.
@Test
public void testFlatMapExprInOr() 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));
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestFlatMapExprInOr());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testLongStringNotEndingWithOr.
@Test
public void testLongStringNotEndingWithOr() throws AtlasException {
GroovyExpression toOptimize = getVerticesExpression();
toOptimize = makeHasExpression(toOptimize, "name", "Fred");
toOptimize = makeHasExpression(toOptimize, "age", "13");
toOptimize = makeOutExpression(toOptimize, "livesIn");
toOptimize = makeHasExpression(toOptimize, "state", "Massachusetts");
GroovyExpression or1cond1 = makeHasExpression("p1", "e1");
GroovyExpression or1cond2 = makeHasExpression("p2", "e2");
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(or1cond1, or1cond2));
GroovyExpression or2cond1 = makeHasExpression("p3", "e3");
GroovyExpression or2cond2 = makeHasExpression("p4", "e4");
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(or2cond1, or2cond2));
toOptimize = makeHasExpression(toOptimize, "p5", "e5");
toOptimize = makeHasExpression(toOptimize, "p6", "e6");
GroovyExpression or3cond1 = makeHasExpression("p7", "e7");
GroovyExpression or3cond2 = makeHasExpression("p8", "e8");
toOptimize = getFactory().generateLogicalExpression(toOptimize, "or", Arrays.asList(or3cond1, or3cond2));
toOptimize = makeHasExpression(toOptimize, "p9", "e9");
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestLongStringNotEndingWithOr());
}
use of org.apache.atlas.groovy.GroovyExpression in project incubator-atlas by apache.
the class AbstractGremlinQueryOptimizerTest method testFlatMapExprInAnd.
@Test
public void testFlatMapExprInAnd() throws AtlasException {
GroovyExpression expr1 = makeHasExpression("name", "Fred");
GroovyExpression expr2 = makeHasExpression(makeOutExpression(null, "knows"), "name", "George");
GroovyExpression toOptimize = getVerticesExpression();
toOptimize = getFactory().generateLogicalExpression(toOptimize, "and", Arrays.asList(expr1, expr2));
GroovyExpression optimized = GremlinQueryOptimizer.getInstance().optimize(toOptimize);
assertEquals(optimized.toString(), getExpectedGremlinForTestFlatMapExprInAnd());
}
Aggregations