Search in sources :

Example 76 with SqlPredicate

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

the class QueryBasicTest method testPredicateStringAttribute.

private void testPredicateStringAttribute(IMap<Integer, Value> map) {
    map.put(1, new Value("abc"));
    map.put(2, new Value("xyz"));
    map.put(3, new Value("aaa"));
    map.put(4, new Value("zzz"));
    map.put(5, new Value("klm"));
    map.put(6, new Value("prs"));
    map.put(7, new Value("prs"));
    map.put(8, new Value("def"));
    map.put(9, new Value("qwx"));
    assertEquals(8, map.values(new SqlPredicate("name > 'aac'")).size());
    assertEquals(9, map.values(new SqlPredicate("name between 'aaa' and 'zzz'")).size());
    assertEquals(7, map.values(new SqlPredicate("name < 't'")).size());
    assertEquals(6, map.values(new SqlPredicate("name >= 'gh'")).size());
    assertEquals(8, map.values(new PredicateBuilder().getEntryObject().get("name").greaterThan("aac")).size());
    assertEquals(9, map.values(new PredicateBuilder().getEntryObject().get("name").between("aaa", "zzz")).size());
    assertEquals(7, map.values(new PredicateBuilder().getEntryObject().get("name").lessThan("t")).size());
    assertEquals(6, map.values(new PredicateBuilder().getEntryObject().get("name").greaterEqual("gh")).size());
}
Also used : PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 77 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 78 with SqlPredicate

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

the class QueryBasicTest method queryWithThis.

@Test(timeout = 1000 * 60)
public void queryWithThis() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, String> map = instance.getMap("queryWithThis");
    map.addIndex("this", false);
    for (int i = 0; i < 1000; i++) {
        map.put("" + i, "" + i);
    }
    Predicate predicate = new PredicateBuilder().getEntryObject().get("this").equal("10");
    Collection<String> set = map.values(predicate);
    assertEquals(1, set.size());
    assertEquals(1, map.values(new SqlPredicate("this=15")).size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PredicateBuilder(com.hazelcast.query.PredicateBuilder) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 79 with SqlPredicate

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

the class QueryBasicTest method testInPredicate.

@Test(timeout = 1000 * 60)
public void testInPredicate() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, SampleObjects.ValueType> map = instance.getMap("testIteratorContract");
    map.put("1", new ValueType("one"));
    map.put("2", new ValueType("two"));
    map.put("3", new ValueType("three"));
    map.put("4", new ValueType("four"));
    map.put("5", new ValueType("five"));
    map.put("6", new ValueType("six"));
    map.put("7", new ValueType("seven"));
    Predicate predicate = new SqlPredicate("typeName in ('one','two')");
    for (int i = 0; i < 10; i++) {
        Collection<SampleObjects.ValueType> values = map.values(predicate);
        assertEquals(2, values.size());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 80 with SqlPredicate

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

the class MapTransactionTest method testValues_shouldNotDeduplicateEntriesWhenGettingByPredicate.

@Test
public void testValues_shouldNotDeduplicateEntriesWhenGettingByPredicate() throws TransactionException {
    final int nodeCount = 1;
    final String mapName = randomMapName();
    final Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance node = factory.newHazelcastInstance(config);
    final IMap map = node.getMap(mapName);
    final Employee emp = new Employee("name", 77, true, 10D);
    map.put(1, emp);
    node.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Integer, Employee> txMap = context.getMap(mapName);
            txMap.put(2, emp);
            Collection<Employee> coll = txMap.values(new SqlPredicate("age = 77"));
            assertEquals(2, coll.size());
            return true;
        }
    });
    node.shutdown();
}
Also used : TransactionalMap(com.hazelcast.core.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TransactionException(com.hazelcast.transaction.TransactionException) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

SqlPredicate (com.hazelcast.query.SqlPredicate)111 Test (org.junit.Test)93 QuickTest (com.hazelcast.test.annotation.QuickTest)87 ParallelTest (com.hazelcast.test.annotation.ParallelTest)83 HazelcastInstance (com.hazelcast.core.HazelcastInstance)73 Config (com.hazelcast.config.Config)36 Employee (com.hazelcast.mapreduce.helpers.Employee)28 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 MapIndexConfig (com.hazelcast.config.MapIndexConfig)22 IMap (com.hazelcast.core.IMap)21 Employee (com.hazelcast.query.SampleObjects.Employee)21 MapStoreConfig (com.hazelcast.config.MapStoreConfig)18 Collection (java.util.Collection)14 MapConfig (com.hazelcast.config.MapConfig)13 Predicate (com.hazelcast.query.Predicate)12 Map (java.util.Map)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 PortableEmployee (com.hazelcast.query.SampleObjects.PortableEmployee)10 AssertTask (com.hazelcast.test.AssertTask)10 Value (com.hazelcast.query.SampleObjects.Value)9