@Test public void simplifyForUnion() { ConstraintImpl and, op1, op2, op3, op4; Set<ConstraintImpl> expected; op1 = mock(ComparisonImpl.class); op2 = mock(ComparisonImpl.class); and = new AndImpl(op1, op2); expected = emptySet(); assertThat(and.convertToUnion(), is(expected)); op1 = mockConstraint("op1", ComparisonImpl.class); op2 = mockConstraint("op2", ComparisonImpl.class); op3 = mockConstraint("op3", ComparisonImpl.class); and = new AndImpl(new OrImpl(op1, op2), op3); expected = of( (ConstraintImpl) new AndImpl(op1, op3) , (ConstraintImpl) new AndImpl(op2, op3) ); assertThat(and.convertToUnion(), is(expected)); op1 = mockConstraint("op1", ComparisonImpl.class); op2 = mockConstraint("op2", ComparisonImpl.class); op3 = mockConstraint("op3", ComparisonImpl.class); op4 = mockConstraint("op4", ComparisonImpl.class); and = new AndImpl(new OrImpl(new OrImpl(op1, op4), op2), op3); expected = of( (ConstraintImpl) new AndImpl(op1, op3) , (ConstraintImpl) new AndImpl(op2, op3) , (ConstraintImpl) new AndImpl(op4, op3) ); assertThat(and.convertToUnion(), is(expected)); }
@Override public Set<ConstraintImpl> convertToUnion() { Set<ConstraintImpl> union = Sets.newLinkedHashSet(); Set<ConstraintImpl> result = Sets.newLinkedHashSet(); Set<ConstraintImpl> nonUnion = Sets.newHashSet(); for (ConstraintImpl c : constraints) { Set<ConstraintImpl> converted = c.convertToUnion(); if (converted.isEmpty()) { nonUnion.add(c); } else { union.addAll(converted); if (union.size() > QueryImpl.MAX_UNION) { throw QueryImpl.TOO_MANY_UNION; } } } if (!union.isEmpty() && nonUnion.size() == 1) { ConstraintImpl right = nonUnion.iterator().next(); for (ConstraintImpl c : union) { result.add(new AndImpl(c, right)); } } else { if (QueryEngineSettings.SQL2_OPTIMIZATION_2) { Set<ConstraintImpl> set = Sets.newLinkedHashSet(); addToUnionList(set); if (set.size() == 1) { return Collections.emptySet(); } return set; } } return result; }
AndImpl extends ConstraintImpl { @Override public Set<ConstraintImpl> convertToUnion() { Set<ConstraintImpl> union = Sets.newLinkedHashSet(); Set<ConstraintImpl> result = Sets.newLinkedHashSet(); Set<ConstraintImpl> nonUnion = Sets.newHashSet(); for (ConstraintImpl c : constraints) { Set<ConstraintImpl> converted = c.convertToUnion(); if (converted.isEmpty()) { nonUnion.add(c); } else { union.addAll(converted); if (union.size() > QueryImpl.MAX_UNION) { throw QueryImpl.TOO_MANY_UNION; } } } if (!union.isEmpty() && nonUnion.size() == 1) { ConstraintImpl right = nonUnion.iterator().next(); for (ConstraintImpl c : union) { result.add(new AndImpl(c, right)); } } else { if (QueryEngineSettings.SQL2_OPTIMIZATION_2) { Set<ConstraintImpl> set = Sets.newLinkedHashSet(); addToUnionList(set); if (set.size() == 1) { return Collections.emptySet(); } return set; } } return result; } }
AndImpl extends ConstraintImpl { @Override public Set<ConstraintImpl> convertToUnion() { Set<ConstraintImpl> union = Sets.newLinkedHashSet(); Set<ConstraintImpl> result = Sets.newLinkedHashSet(); Set<ConstraintImpl> nonUnion = Sets.newHashSet(); for (ConstraintImpl c : constraints) { Set<ConstraintImpl> converted = c.convertToUnion(); if (converted.isEmpty()) { nonUnion.add(c); } else { union.addAll(converted); if (union.size() > QueryImpl.MAX_UNION) { throw QueryImpl.TOO_MANY_UNION; } } } if (!union.isEmpty() && nonUnion.size() == 1) { ConstraintImpl right = nonUnion.iterator().next(); for (ConstraintImpl c : union) { result.add(new AndImpl(c, right)); } } else { if (QueryEngineSettings.SQL2_OPTIMIZATION_2) { Set<ConstraintImpl> set = Sets.newLinkedHashSet(); addToUnionList(set); if (set.size() == 1) { return Collections.emptySet(); } return set; } } return result; } AndImpl(List<ConstraintImpl> constraints);  AndImpl(ConstraintImpl constraint1, ConstraintImpl constraint2); }
AndImpl extends ConstraintImpl { @Override public Set<ConstraintImpl> convertToUnion() { Set<ConstraintImpl> union = Sets.newLinkedHashSet(); Set<ConstraintImpl> result = Sets.newLinkedHashSet(); Set<ConstraintImpl> nonUnion = Sets.newHashSet(); for (ConstraintImpl c : constraints) { Set<ConstraintImpl> converted = c.convertToUnion(); if (converted.isEmpty()) { nonUnion.add(c); } else { union.addAll(converted); if (union.size() > QueryImpl.MAX_UNION) { throw QueryImpl.TOO_MANY_UNION; } } } if (!union.isEmpty() && nonUnion.size() == 1) { ConstraintImpl right = nonUnion.iterator().next(); for (ConstraintImpl c : union) { result.add(new AndImpl(c, right)); } } else { if (QueryEngineSettings.SQL2_OPTIMIZATION_2) { Set<ConstraintImpl> set = Sets.newLinkedHashSet(); addToUnionList(set); if (set.size() == 1) { return Collections.emptySet(); } return set; } } return result; } AndImpl(List<ConstraintImpl> constraints);  AndImpl(ConstraintImpl constraint1, ConstraintImpl constraint2); List<ConstraintImpl> getConstraints(); @Override ConstraintImpl simplify(); @Override Set<PropertyExistenceImpl> getPropertyExistenceConditions(); @Override FullTextExpression getFullTextConstraint(SelectorImpl s); @Override Set<SelectorImpl> getSelectors(); @Override boolean evaluate(); @Override boolean evaluateStop(); @Override void restrict(FilterImpl f); @Override void restrictPushDown(SelectorImpl s); @Override String toString(); @Override boolean equals(Object that); @Override int hashCode(); @Override AstElement copyOf(); void addToUnionList(Set<ConstraintImpl> target); AndImpl pullOrRight(); @Override Set<ConstraintImpl> convertToUnion(); @Override boolean requiresFullTextIndex(); @Override boolean containsUnfilteredFullTextCondition(); }
AndImpl extends ConstraintImpl { @Override public Set<ConstraintImpl> convertToUnion() { Set<ConstraintImpl> union = Sets.newLinkedHashSet(); Set<ConstraintImpl> result = Sets.newLinkedHashSet(); Set<ConstraintImpl> nonUnion = Sets.newHashSet(); for (ConstraintImpl c : constraints) { Set<ConstraintImpl> converted = c.convertToUnion(); if (converted.isEmpty()) { nonUnion.add(c); } else { union.addAll(converted); if (union.size() > QueryImpl.MAX_UNION) { throw QueryImpl.TOO_MANY_UNION; } } } if (!union.isEmpty() && nonUnion.size() == 1) { ConstraintImpl right = nonUnion.iterator().next(); for (ConstraintImpl c : union) { result.add(new AndImpl(c, right)); } } else { if (QueryEngineSettings.SQL2_OPTIMIZATION_2) { Set<ConstraintImpl> set = Sets.newLinkedHashSet(); addToUnionList(set); if (set.size() == 1) { return Collections.emptySet(); } return set; } } return result; } AndImpl(List<ConstraintImpl> constraints);  AndImpl(ConstraintImpl constraint1, ConstraintImpl constraint2); List<ConstraintImpl> getConstraints(); @Override ConstraintImpl simplify(); @Override Set<PropertyExistenceImpl> getPropertyExistenceConditions(); @Override FullTextExpression getFullTextConstraint(SelectorImpl s); @Override Set<SelectorImpl> getSelectors(); @Override boolean evaluate(); @Override boolean evaluateStop(); @Override void restrict(FilterImpl f); @Override void restrictPushDown(SelectorImpl s); @Override String toString(); @Override boolean equals(Object that); @Override int hashCode(); @Override AstElement copyOf(); void addToUnionList(Set<ConstraintImpl> target); AndImpl pullOrRight(); @Override Set<ConstraintImpl> convertToUnion(); @Override boolean requiresFullTextIndex(); @Override boolean containsUnfilteredFullTextCondition();  }