Search in sources :

Example 41 with SqlPredicate

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

the class ClientMapBasicTest method testKeySet_withPredicate.

@Test
public void testKeySet_withPredicate() {
    int max = 44;
    IMap<Integer, String> map = client.getMap(randomString());
    Set<Integer> expected = new TreeSet<Integer>();
    for (int key = 0; key < max; key++) {
        String value = key + "value";
        map.put(key, value);
    }
    expected.add(4);
    Set<Integer> keySet = map.keySet(new SqlPredicate("this == 4value"));
    assertEquals(expected, keySet);
}
Also used : TreeSet(java.util.TreeSet) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with SqlPredicate

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

the class MapMBean method values.

@ManagedAnnotation(value = "values", operation = true)
public String values(String query) {
    Collection coll;
    if (query != null && !query.isEmpty()) {
        Predicate predicate = new SqlPredicate(query);
        coll = managedObject.values(predicate);
    } else {
        coll = managedObject.values();
    }
    StringBuilder buf = new StringBuilder();
    if (coll.size() == 0) {
        buf.append("Empty");
    } else {
        buf.append("[");
        for (Object obj : coll) {
            buf.append(obj);
            buf.append(", ");
        }
        buf.replace(buf.length() - 1, buf.length(), "]");
    }
    return buf.toString();
}
Also used : Collection(java.util.Collection) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 43 with SqlPredicate

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

the class QueryBasicTest method testPredicateEnumAttribute.

private void testPredicateEnumAttribute(IMap<Integer, NodeType> map) {
    map.put(1, NodeType.MEMBER);
    map.put(2, NodeType.LITE_MEMBER);
    map.put(3, NodeType.JAVA_CLIENT);
    assertEquals(NodeType.MEMBER, map.values(new SqlPredicate("this=MEMBER")).iterator().next());
    assertEquals(2, map.values(new SqlPredicate("this in (MEMBER, LITE_MEMBER)")).size());
    assertEquals(NodeType.JAVA_CLIENT, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.JAVA_CLIENT)).iterator().next());
    assertEquals(0, map.values(new PredicateBuilder().getEntryObject().get("this").equal(NodeType.CSHARP_CLIENT)).size());
    assertEquals(2, map.values(new PredicateBuilder().getEntryObject().get("this").in(NodeType.LITE_MEMBER, NodeType.MEMBER)).size());
}
Also used : PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 44 with SqlPredicate

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

the class IndexesTest method shouldReturnNull_whenQueryingOnKeys.

private void shouldReturnNull_whenQueryingOnKeys(Indexes indexes) {
    for (int i = 0; i < 50; i++) {
        // passing null value to QueryEntry
        indexes.saveEntryIndex(new QueryEntry(serializationService, toData(i), null, Extractors.empty()), null);
    }
    Set<QueryableEntry> query = indexes.query(new SqlPredicate("__key > 10 "));
    assertNull("There should be no result", query);
}
Also used : SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 45 with SqlPredicate

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

the class NestedPredicateTest method nestedAttributeQuery_distributedSql.

@Test
public void nestedAttributeQuery_distributedSql() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    Collection<Body> values = map.values(new SqlPredicate("limb.name == 'leg'"));
    // THEN
    assertEquals(1, values.size());
    assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
}
Also used : SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

SqlPredicate (com.hazelcast.query.SqlPredicate)53 QuickTest (com.hazelcast.test.annotation.QuickTest)40 Test (org.junit.Test)40 ParallelTest (com.hazelcast.test.annotation.ParallelTest)35 Employee (com.hazelcast.mapreduce.helpers.Employee)28 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 IMap (com.hazelcast.core.IMap)5 Map (java.util.Map)5 AssertTask (com.hazelcast.test.AssertTask)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Config (com.hazelcast.config.Config)3 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)3 EventLostEvent (com.hazelcast.map.EventLostEvent)3 QueryCache (com.hazelcast.map.QueryCache)3 EventLostListener (com.hazelcast.map.listener.EventLostListener)3 Predicate (com.hazelcast.query.Predicate)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 TimeStep (com.hazelcast.simulator.test.annotations.TimeStep)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2