Finder extends ConditionTreeVisitor<Set<Long>> { public static Finder instance() { return INSTANCE; } private  Finder(); static Finder instance(); @Override Set<Long> visit(ConjunctionTree tree, Object... data); @Override Set<Long> visit(ExpressionTree tree, Object... data);  }
@Test public void testBasicExpression() { Queue store = new Queue(16); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 1)); store.insert(Write.add("company", Convert.javaToThrift("Cinchapi"), 1)); store.insert(Write.add("age", Convert.javaToThrift(100), 1)); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 2)); store.insert(Write.add("company", Convert.javaToThrift("Blavity"), 2)); store.insert(Write.add("age", Convert.javaToThrift(100), 2)); store.insert(Write.add("name", Convert.javaToThrift("ashleah"), 3)); store.insert( Write.add("company", Convert.javaToThrift("ARMN Inc."), 3)); store.insert(Write.add("age", Convert.javaToThrift(50), 3)); String ccl = "name = jeff"; AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl); Finder visitor = Finder.instance(); Set<Long> result = ast.accept(visitor, store); Assert.assertEquals(Sets.newHashSet(1L, 2L), result); }
@Test public void testAndConjunction() { Queue store = new Queue(16); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 1)); store.insert(Write.add("company", Convert.javaToThrift("Cinchapi"), 1)); store.insert(Write.add("age", Convert.javaToThrift(100), 1)); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 2)); store.insert(Write.add("company", Convert.javaToThrift("Blavity"), 2)); store.insert(Write.add("age", Convert.javaToThrift(100), 2)); store.insert(Write.add("name", Convert.javaToThrift("ashleah"), 3)); store.insert( Write.add("company", Convert.javaToThrift("ARMN Inc."), 3)); store.insert(Write.add("age", Convert.javaToThrift(50), 3)); String ccl = "name = jeff and company = Cinchapi"; AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl); Finder visitor = Finder.instance(); Set<Long> result = ast.accept(visitor, store); Assert.assertEquals(Sets.newHashSet(1L), result); }
@Test public void testOrConjunction() { Queue store = new Queue(16); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 1)); store.insert(Write.add("company", Convert.javaToThrift("Cinchapi"), 1)); store.insert(Write.add("age", Convert.javaToThrift(100), 1)); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 2)); store.insert(Write.add("company", Convert.javaToThrift("Blavity"), 2)); store.insert(Write.add("age", Convert.javaToThrift(100), 2)); store.insert(Write.add("name", Convert.javaToThrift("ashleah"), 3)); store.insert( Write.add("company", Convert.javaToThrift("ARMN Inc."), 3)); store.insert(Write.add("age", Convert.javaToThrift(50), 3)); String ccl = "name = jeff or age < 75"; AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl); Finder visitor = Finder.instance(); Set<Long> result = ast.accept(visitor, store); Assert.assertEquals(Sets.newHashSet(1L, 2L, 3L), result); }
@Test public void testAndConjunctionShortCircuit() { Queue store = new Queue(16); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 1)); store.insert(Write.add("company", Convert.javaToThrift("Cinchapi"), 1)); store.insert(Write.add("age", Convert.javaToThrift(100), 1)); store.insert(Write.add("name", Convert.javaToThrift("jeff"), 2)); store.insert(Write.add("company", Convert.javaToThrift("Blavity"), 2)); store.insert(Write.add("age", Convert.javaToThrift(100), 2)); store.insert(Write.add("name", Convert.javaToThrift("ashleah"), 3)); store.insert( Write.add("company", Convert.javaToThrift("ARMN Inc."), 3)); store.insert(Write.add("age", Convert.javaToThrift(50), 3)); String ccl = "(name = jeff or company = Cinchapi) and age = 70"; AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl); Finder visitor = Finder.instance(); Set<Long> result = ast.accept(visitor, store); Assert.assertEquals(Sets.newHashSet(), result); }