Search in sources :

Example 66 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class NestedPredicateWithExtractorTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
    assertEquals(2 + 1, bodyExtractorExecutions);
    assertEquals(0, limbExtractorExecutions);
}
Also used : EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 67 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class BetweenVisitorTest method whenPredicateIsNotGreaterLessPredicate_thenIsNotUsedToBuildBetween.

@Test
public void whenPredicateIsNotGreaterLessPredicate_thenIsNotUsedToBuildBetween() {
    Predicate left = equal("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 68 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class BetweenVisitorTest method whenOnlyOneSideFound_thenReturnOriginalPredicate.

@Test
public void whenOnlyOneSideFound_thenReturnOriginalPredicate() {
    Predicate p1 = greaterEqual("attribute1", 5);
    Predicate p2 = lessEqual("attribute2", 6);
    Predicate and = and(p1, p2);
    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 69 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class BetweenVisitorTest method whenPredicatesOutsideTheRangeFromRightExist_thenEliminateThem.

@Test
public void whenPredicatesOutsideTheRangeFromRightExist_thenEliminateThem() {
    //(age >= 5 and age <= 6 and age < 10)  -->  (age between 5 6)
    Predicate left = greaterEqual("attribute", 5);
    Predicate right = lessEqual("attribute", 6);
    Predicate other = lessEqual("attribute", 10);
    Predicate and = and(left, right, other);
    Predicate result = visitor.visit((AndPredicate) and, mockIndexes);
    assertBetweenPredicate(result, 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 70 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class BetweenVisitorTest method whenNoConverterExist_thenReturnOriginalPredicate.

@Test
public void whenNoConverterExist_thenReturnOriginalPredicate() {
    disableConverter();
    Predicate left = greaterEqual("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)

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