MyPlanTransformListener listener = new MyPlanTransformListener();
optimizer.addPlanTransformListener(listener);
optimizer.optimize();
assertEquals(plan.getPredecessors(filter).get(0), join);
Operator next = plan.getSuccessors(filter).get(0);
assertEquals(next.getClass(), LOFilter.class);
next = plan.getSuccessors(next).get(0);
assertEquals(next.getClass(), LOFilter.class);
next = plan.getSuccessors(next).get(0);
assertEquals(LOStore.class, next.getClass());
OperatorPlan transformed = listener.getTransformed();
assertEquals(transformed.size(), 3);
// run push up filter rule
r = new PushUpFilter("PushUpFilter");
s = new HashSet<Rule>();
s.add(r);
ls = new ArrayList<Set<Rule>>();
ls.add(s);
optimizer = new MyPlanOptimizer(plan, ls, 3);
listener = new MyPlanTransformListener();
optimizer.addPlanTransformListener(listener);
optimizer.optimize();
// 2 filters should be moved up to be after each load, and one filter should remain
next = plan.getSuccessors(load1).get(0);
assertEquals(next.getClass(), LOFilter.class);
assertEquals(plan.getSuccessors(next).get(0), join);
next = plan.getSuccessors(load2).get(0);
assertEquals(next.getClass(), LOFilter.class);
assertEquals(plan.getSuccessors(next).get(0), join);
next = plan.getSuccessors(join).get(0);
assertEquals(next.getClass(), LOFilter.class);
next = plan.getSuccessors(next).get(0);
assertEquals(next.getClass(), LOStore.class);
transformed = listener.getTransformed();
assertEquals(transformed.size(), 4);
assertEquals(transformed.getSinks().get(0).getClass(), LOFilter.class);
assertEquals(transformed.getSources().get(0).getClass(), LOLoad.class);
// run merge filter rule
r = new MergeFilter("MergeFilter");
s = new HashSet<Rule>();
s.add(r);
ls = new ArrayList<Set<Rule>>();
ls.add(s);
optimizer = new MyPlanOptimizer(plan, ls, 3);
listener = new MyPlanTransformListener();
optimizer.addPlanTransformListener(listener);
optimizer.optimize();
// the filters should the same as before, nothing to merge
next = plan.getSuccessors(load1).get(0);
assertEquals(next.getClass(), LOFilter.class);
assertEquals(plan.getSuccessors(next).get(0), join);
next = plan.getSuccessors(load2).get(0);
assertEquals(next.getClass(), LOFilter.class);
assertEquals(plan.getSuccessors(next).get(0), join);
next = plan.getSuccessors(join).get(0);
assertEquals(next.getClass(), LOFilter.class);
next = plan.getSuccessors(next).get(0);
assertEquals(next.getClass(), LOStore.class);
transformed = listener.getTransformed();
assertNull(transformed);
}