@Test public void testNormalizeUnionWithTwoSingletons() { Projection p = new Projection(); Union union = new Union(); union.setRightArg(new SingletonSet()); union.setLeftArg(new SingletonSet()); p.setArg(union); subject.meet(union); assertThat(p.getArg()).isEqualTo(union); }
@Override public void meet(Join join) { super.meet(join); TupleExpr leftArg = join.getLeftArg(); TupleExpr rightArg = join.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { join.replaceWith(new EmptySet()); } else if (leftArg instanceof SingletonSet) { join.replaceWith(rightArg); } else if (rightArg instanceof SingletonSet) { join.replaceWith(leftArg); } else if (leftArg instanceof Union) { Union union = (Union) leftArg; Join leftJoin = new Join(union.getLeftArg(), rightArg.clone()); Join rightJoin = new Join(union.getRightArg(), rightArg.clone()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (rightArg instanceof Union) { Union union = (Union) rightArg; Join leftJoin = new Join(leftArg.clone(), union.getLeftArg()); Join rightJoin = new Join(leftArg.clone(), union.getRightArg()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (leftArg instanceof LeftJoin && isWellDesigned(((LeftJoin) leftArg))) { LeftJoin leftJoin = (LeftJoin) leftArg; join.replaceWith(leftJoin); join.setLeftArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } else if (rightArg instanceof LeftJoin && isWellDesigned(((LeftJoin) rightArg))) { LeftJoin leftJoin = (LeftJoin) rightArg; join.replaceWith(leftJoin); join.setRightArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } }
QueryModelNormalizer extends AbstractQueryModelVisitor<RuntimeException> implements QueryOptimizer { @Override public void meet(Join join) { super.meet(join); TupleExpr leftArg = join.getLeftArg(); TupleExpr rightArg = join.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { join.replaceWith(new EmptySet()); } else if (leftArg instanceof SingletonSet) { join.replaceWith(rightArg); } else if (rightArg instanceof SingletonSet) { join.replaceWith(leftArg); } else if (leftArg instanceof Union) { Union union = (Union) leftArg; Join leftJoin = new Join(union.getLeftArg(), rightArg.clone()); Join rightJoin = new Join(union.getRightArg(), rightArg.clone()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (rightArg instanceof Union) { Union union = (Union) rightArg; Join leftJoin = new Join(leftArg.clone(), union.getLeftArg()); Join rightJoin = new Join(leftArg.clone(), union.getRightArg()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (leftArg instanceof LeftJoin && isWellDesigned(((LeftJoin) leftArg))) { LeftJoin leftJoin = (LeftJoin) leftArg; join.replaceWith(leftJoin); join.setLeftArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } else if (rightArg instanceof LeftJoin && isWellDesigned(((LeftJoin) rightArg))) { LeftJoin leftJoin = (LeftJoin) rightArg; join.replaceWith(leftJoin); join.setRightArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } } }
QueryModelNormalizer extends AbstractQueryModelVisitor<RuntimeException> implements QueryOptimizer { @Override public void meet(Join join) { super.meet(join); TupleExpr leftArg = join.getLeftArg(); TupleExpr rightArg = join.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { join.replaceWith(new EmptySet()); } else if (leftArg instanceof SingletonSet) { join.replaceWith(rightArg); } else if (rightArg instanceof SingletonSet) { join.replaceWith(leftArg); } else if (leftArg instanceof Union) { Union union = (Union) leftArg; Join leftJoin = new Join(union.getLeftArg(), rightArg.clone()); Join rightJoin = new Join(union.getRightArg(), rightArg.clone()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (rightArg instanceof Union) { Union union = (Union) rightArg; Join leftJoin = new Join(leftArg.clone(), union.getLeftArg()); Join rightJoin = new Join(leftArg.clone(), union.getRightArg()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (leftArg instanceof LeftJoin && isWellDesigned(((LeftJoin) leftArg))) { LeftJoin leftJoin = (LeftJoin) leftArg; join.replaceWith(leftJoin); join.setLeftArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } else if (rightArg instanceof LeftJoin && isWellDesigned(((LeftJoin) rightArg))) { LeftJoin leftJoin = (LeftJoin) rightArg; join.replaceWith(leftJoin); join.setRightArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } } QueryModelNormalizer(); }
QueryModelNormalizer extends AbstractQueryModelVisitor<RuntimeException> implements QueryOptimizer { @Override public void meet(Join join) { super.meet(join); TupleExpr leftArg = join.getLeftArg(); TupleExpr rightArg = join.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { join.replaceWith(new EmptySet()); } else if (leftArg instanceof SingletonSet) { join.replaceWith(rightArg); } else if (rightArg instanceof SingletonSet) { join.replaceWith(leftArg); } else if (leftArg instanceof Union) { Union union = (Union) leftArg; Join leftJoin = new Join(union.getLeftArg(), rightArg.clone()); Join rightJoin = new Join(union.getRightArg(), rightArg.clone()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (rightArg instanceof Union) { Union union = (Union) rightArg; Join leftJoin = new Join(leftArg.clone(), union.getLeftArg()); Join rightJoin = new Join(leftArg.clone(), union.getRightArg()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (leftArg instanceof LeftJoin && isWellDesigned(((LeftJoin) leftArg))) { LeftJoin leftJoin = (LeftJoin) leftArg; join.replaceWith(leftJoin); join.setLeftArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } else if (rightArg instanceof LeftJoin && isWellDesigned(((LeftJoin) rightArg))) { LeftJoin leftJoin = (LeftJoin) rightArg; join.replaceWith(leftJoin); join.setRightArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } } QueryModelNormalizer(); @Override void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings); @Override void meet(Join join); @Override void meet(LeftJoin leftJoin); @Override void meet(Union union); @Override void meet(Difference difference); @Override void meet(Intersection intersection); @Override void meet(Filter node); @Override void meet(Or or); @Override void meet(And and); }
QueryModelNormalizer extends AbstractQueryModelVisitor<RuntimeException> implements QueryOptimizer { @Override public void meet(Join join) { super.meet(join); TupleExpr leftArg = join.getLeftArg(); TupleExpr rightArg = join.getRightArg(); if (leftArg instanceof EmptySet || rightArg instanceof EmptySet) { join.replaceWith(new EmptySet()); } else if (leftArg instanceof SingletonSet) { join.replaceWith(rightArg); } else if (rightArg instanceof SingletonSet) { join.replaceWith(leftArg); } else if (leftArg instanceof Union) { Union union = (Union) leftArg; Join leftJoin = new Join(union.getLeftArg(), rightArg.clone()); Join rightJoin = new Join(union.getRightArg(), rightArg.clone()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (rightArg instanceof Union) { Union union = (Union) rightArg; Join leftJoin = new Join(leftArg.clone(), union.getLeftArg()); Join rightJoin = new Join(leftArg.clone(), union.getRightArg()); Union newUnion = new Union(leftJoin, rightJoin); join.replaceWith(newUnion); newUnion.visit(this); } else if (leftArg instanceof LeftJoin && isWellDesigned(((LeftJoin) leftArg))) { LeftJoin leftJoin = (LeftJoin) leftArg; join.replaceWith(leftJoin); join.setLeftArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } else if (rightArg instanceof LeftJoin && isWellDesigned(((LeftJoin) rightArg))) { LeftJoin leftJoin = (LeftJoin) rightArg; join.replaceWith(leftJoin); join.setRightArg(leftJoin.getLeftArg()); leftJoin.setLeftArg(join); leftJoin.visit(this); } } QueryModelNormalizer(); @Override void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings); @Override void meet(Join join); @Override void meet(LeftJoin leftJoin); @Override void meet(Union union); @Override void meet(Difference difference); @Override void meet(Intersection intersection); @Override void meet(Filter node); @Override void meet(Or or); @Override void meet(And and);  }