Search in sources :

Example 71 with Predicate

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);
}
Also used : Predicate(com.hazelcast.query.Predicate) FalsePredicate(com.hazelcast.query.impl.FalsePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 72 with Predicate

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);
}
Also used : Predicate(com.hazelcast.query.Predicate) FalsePredicate(com.hazelcast.query.impl.FalsePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 73 with Predicate

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);
}
Also used : Predicate(com.hazelcast.query.Predicate) FalsePredicate(com.hazelcast.query.impl.FalsePredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 74 with Predicate

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));
}
Also used : PredicateTestUtils.createMockVisitablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 75 with Predicate

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));
}
Also used : PredicateTestUtils.createMockVisitablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Predicate (com.hazelcast.query.Predicate)160 Test (org.junit.Test)125 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)107 TruePredicate (com.hazelcast.query.TruePredicate)41 SqlPredicate (com.hazelcast.query.SqlPredicate)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)23 PredicateBuilder (com.hazelcast.query.PredicateBuilder)19 EntryListener (com.hazelcast.core.EntryListener)16 MapListener (com.hazelcast.map.listener.MapListener)16 EntryObject (com.hazelcast.query.EntryObject)14 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)12 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)10 Value (com.hazelcast.query.SampleObjects.Value)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 ArrayList (java.util.ArrayList)9 EntryEvent (com.hazelcast.core.EntryEvent)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 ValueType (com.hazelcast.query.SampleObjects.ValueType)7