Search in sources :

Example 21 with SqlPredicate

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

the class PagingPredicateTest method setUp.

@Setup
public void setUp() {
    map = targetInstance.getMap(name);
    innerPredicate = new SqlPredicate(innerPredicateQuery);
}
Also used : SqlPredicate(com.hazelcast.query.SqlPredicate) Setup(com.hazelcast.simulator.test.annotations.Setup)

Example 22 with SqlPredicate

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

the class MapGetVsQueryTest method sqlString.

@TimeStep(prob = 0)
public void sqlString(ThreadState state) {
    int id = state.randomInt(itemCount);
    SqlPredicate predicate = new SqlPredicate("id=" + id);
    map.values(predicate);
}
Also used : SqlPredicate(com.hazelcast.query.SqlPredicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 23 with SqlPredicate

use of com.hazelcast.query.SqlPredicate in project jnosql-diana-driver by eclipse.

the class DefaultHazelcastBucketManager method query.

@Override
public Collection<Value> query(String query, Map<String, Object> params) throws NullPointerException {
    requireNonNull(query, "query is required");
    requireNonNull(params, "params is required");
    final StringBuilder finalQuery = new StringBuilder(query);
    final Consumer<Map.Entry<String, Object>> consumer = e -> {
        String key = ":" + e.getKey();
        int indexOf = query.indexOf(key);
        finalQuery.replace(indexOf, indexOf + key.length(), e.getValue().toString());
    };
    params.entrySet().forEach(consumer);
    return query(new SqlPredicate(finalQuery.toString()));
}
Also used : Collection(java.util.Collection) Function(java.util.function.Function) SqlPredicate(com.hazelcast.query.SqlPredicate) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) IMap(com.hazelcast.core.IMap) Duration(java.time.Duration) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Value(org.jnosql.diana.api.Value) Optional(java.util.Optional) StreamSupport(java.util.stream.StreamSupport) Predicate(com.hazelcast.query.Predicate) KeyValueEntity(org.jnosql.diana.api.key.KeyValueEntity) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 24 with SqlPredicate

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

the class ClientQueryCacheRecoveryUponEventLossTest method testForceConsistency.

@Test
public void testForceConsistency() {
    String mapName = randomMapName("map");
    String queryCacheName = randomMapName("cache");
    Config config = new Config();
    config.setProperty(PARTITION_COUNT.getName(), "1");
    factory.newHazelcastInstance(config);
    QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
    queryCacheConfig.setBatchSize(1111);
    queryCacheConfig.setDelaySeconds(3);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addQueryCacheConfig(mapName, queryCacheConfig);
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap(mapName);
    // set test sequencer to subscriber
    int count = 30;
    setTestSequencer(map, 9);
    final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
    queryCache.addEntryListener(new EventLostListener() {

        @Override
        public void eventLost(EventLostEvent event) {
            queryCache.tryRecover();
        }
    }, false);
    for (int i = 0; i < count; i++) {
        map.put(i, i);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(9, queryCache.size());
        }
    });
}
Also used : QueryCache(com.hazelcast.map.QueryCache) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) QueryCacheConfig(com.hazelcast.config.QueryCacheConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) EventLostListener(com.hazelcast.map.listener.EventLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventLostEvent(com.hazelcast.map.EventLostEvent) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with SqlPredicate

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

the class ClientQueryCacheTest method testQueryCache.

private void testQueryCache(boolean includeValue) {
    String mapName = randomString();
    String queryCacheName = randomString();
    HazelcastInstance client = factory.newHazelcastClient();
    IMap<Integer, Integer> map = client.getMap(mapName);
    for (int i = 0; i < 50; i++) {
        map.put(i, i);
    }
    Predicate<Integer, Integer> predicate = new SqlPredicate("this > 5 AND this < 100");
    QueryCache<Integer, Integer> cache = map.getQueryCache(queryCacheName, predicate, includeValue);
    for (int i = 50; i < 100; i++) {
        map.put(i, i);
    }
    int expected = 94;
    assertQueryCacheSize(expected, cache);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlPredicate(com.hazelcast.query.SqlPredicate)

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