use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class BetweenVisitorTest method whenSideAreOverlapping_thenReturnFalsePredicate.
@Test
public void whenSideAreOverlapping_thenReturnFalsePredicate() {
Predicate p1 = greaterEqual("attribute1", 5);
Predicate p2 = lessEqual("attribute1", 4);
Predicate and = and(p1, p2);
Predicate result = visitor.visit((AndPredicate) and, mockIndexes);
assertEquals(FalsePredicate.INSTANCE, result);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class BetweenVisitorTest method whenPredicateIsExclusive_thenIsNotUsedToBuildBetween.
@Test
public void whenPredicateIsExclusive_thenIsNotUsedToBuildBetween() {
//(age >= 5 and age < 6) --> (age >= 5 and age < 6)
Predicate left = greaterThan("attribute", 5);
Predicate right = lessEqual("attribute", 6);
Predicate and = and(left, right);
Predicate result = visitor.visit((AndPredicate) and, mockIndexes);
assertSame(and, result);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class BetweenVisitorTest method whenPredicatesOtherThenGreatLess_thenDoNotAttemptToEliminateThem.
@Test
public void whenPredicatesOtherThenGreatLess_thenDoNotAttemptToEliminateThem() {
//(age >= 5 and age <= 6 and age <> 4) --> ( (age between 5 6) and (age <> 5) )
Predicate left = greaterEqual("attribute", 5);
Predicate right = lessEqual("attribute", 6);
Predicate other = notEqual("attribute", 4);
Predicate and = and(left, right, other);
AndPredicate result = (AndPredicate) visitor.visit((AndPredicate) and, mockIndexes);
Predicate[] inners = result.predicates;
assertThat(inners, hasItemInArray(other));
BetweenPredicate betweenPredicate = findFirstBetweenPredicate(inners);
assertBetweenPredicate(betweenPredicate, 5, 6);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class VisitorUtilsTest method acceptVisitor_whenNoChange_thenReturnOriginalArray.
@Test
public void acceptVisitor_whenNoChange_thenReturnOriginalArray() {
Visitor mockVisitor = mock(Visitor.class);
Predicate[] predicates = new Predicate[1];
Predicate predicate = createMockVisitablePredicate();
predicates[0] = predicate;
Predicate[] result = VisitorUtils.acceptVisitor(predicates, mockVisitor, mockIndexes);
assertThat(result, sameInstance(predicates));
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class VisitorUtilsTest method acceptVisitor_whenThereIsNonVisitablePredicateAndNewArraysIsCreated_thenJustCopyTheNonVisitablePredicate.
@Test
public void acceptVisitor_whenThereIsNonVisitablePredicateAndNewArraysIsCreated_thenJustCopyTheNonVisitablePredicate() {
Visitor mockVisitor = mock(Visitor.class);
Predicate[] predicates = new Predicate[3];
Predicate p1 = mock(Predicate.class);
predicates[0] = p1;
Predicate transformed = mock(Predicate.class);
Predicate p2 = createMockVisitablePredicate(transformed);
predicates[1] = p2;
Predicate p3 = mock(Predicate.class);
predicates[2] = p3;
Predicate[] result = VisitorUtils.acceptVisitor(predicates, mockVisitor, mockIndexes);
assertThat(result, not(sameInstance(predicates)));
assertThat(result, arrayWithSize(3));
assertThat(result, arrayContainingInAnyOrder(p1, transformed, p3));
}
Aggregations