Search in sources :

Example 11 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class PredicateBuilderTest method get_attribute.

@Test
public void get_attribute() {
    HazelcastInstance hz = createHazelcastInstance();
    EntryObject entryObject = Predicates.newPredicateBuilder().getEntryObject();
    Predicate predicate = entryObject.get("id").equal("10");
    IMap<Integer, Id> hazelcastLookupMap = hz.getMap("someMap");
    hazelcastLookupMap.put(1, new Id("10"));
    hazelcastLookupMap.put(2, new Id("20"));
    hazelcastLookupMap.put(3, new Id("30"));
    Collection<Id> result = hazelcastLookupMap.values(predicate);
    assertEquals(1, result.size());
    assertContains(result, new Id("10"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class QueryUtil method toPredicate.

@SuppressWarnings({ "unchecked", "rawtypes" })
static Predicate<Object, Object> toPredicate(JetSqlRow left, int[] leftEquiJoinIndices, int[] rightEquiJoinIndices, QueryPath[] rightPaths) {
    PredicateBuilder builder = Predicates.newPredicateBuilder();
    EntryObject entryObject = builder.getEntryObject();
    for (int i = 0; i < leftEquiJoinIndices.length; i++) {
        Comparable leftValue = asComparable(left.get(leftEquiJoinIndices[i]));
        // might need a change when/if IS NOT DISTINCT FROM is supported
        if (leftValue == null) {
            return null;
        }
        QueryPath rightPath = rightPaths[rightEquiJoinIndices[i]];
        EntryObject object;
        if (rightPath.isKey()) {
            object = rightPath.isTop() ? entryObject.key() : entryObject.key().get(rightPath.getPath());
        } else {
            object = rightPath.isTop() ? entryObject.get(rightPath.toString()) : entryObject.get(QueryPath.VALUE).get(rightPath.getPath());
        }
        if (i == 0) {
            object.equal(leftValue);
        } else {
            builder.and(object.equal(leftValue));
        }
    }
    return builder;
}
Also used : QueryPath(com.hazelcast.sql.impl.extract.QueryPath) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder)

Example 13 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class NestedPredicateVersionedPortablesTest method singleAttributeQuery_versionedProtables_predicates.

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

Example 14 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class NestedPredicateWithExtractorTest method nestedAttributeQuery_predicates.

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

Example 15 with EntryObject

use of com.hazelcast.query.PredicateBuilder.EntryObject in project hazelcast by hazelcast.

the class PredicatesTest method testCriteriaAPI.

@Test
public void testCriteriaAPI() {
    Object value = new Employee(12, "abc-123-xvz", 34, true, 10D);
    EntryObject e = Predicates.newPredicateBuilder().getEntryObject();
    EntryObject e2 = e.get("age");
    Predicate predicate = e2.greaterEqual(29).and(e2.lessEqual(36));
    assertTrue(predicate.apply(createEntry("1", value)));
    e = Predicates.newPredicateBuilder().getEntryObject();
    assertTrue(e.get("id").equal(12).apply(createEntry("1", value)));
}
Also used : Employee(com.hazelcast.query.SampleTestObjects.Employee) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)24 Test (org.junit.Test)18 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Predicate (com.hazelcast.query.Predicate)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Employee (com.hazelcast.query.SampleTestObjects.Employee)7 Config (com.hazelcast.config.Config)6 PredicateBuilder (com.hazelcast.query.PredicateBuilder)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 MapConfig (com.hazelcast.config.MapConfig)4 EvictionConfig (com.hazelcast.config.EvictionConfig)2 IndexConfig (com.hazelcast.config.IndexConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 NearCacheConfig (com.hazelcast.config.NearCacheConfig)2 IMap (com.hazelcast.map.IMap)2 Collection (java.util.Collection)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 EntryAdapter (com.hazelcast.core.EntryAdapter)1 EntryView (com.hazelcast.core.EntryView)1