Search in sources :

Example 96 with SqlPredicate

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

the class QueryBasicTest method testIteratorContract.

@Test(timeout = 1000 * 60)
public void testIteratorContract() {
    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"));
    Predicate predicate = new SqlPredicate("typeName in ('one','two')");
    assertEquals(2, map.values(predicate).size());
    assertEquals(2, map.keySet(predicate).size());
    testIterator(map.keySet().iterator(), 3);
    testIterator(map.keySet(predicate).iterator(), 2);
    testIterator(map.entrySet().iterator(), 3);
    testIterator(map.entrySet(predicate).iterator(), 2);
    testIterator(map.values().iterator(), 3);
    testIterator(map.values(predicate).iterator(), 2);
}
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 97 with SqlPredicate

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

the class QueryBasicTest method testQueryUsingNestedPortableObject.

private void testQueryUsingNestedPortableObject(Config config, String name) {
    addPortableFactories(config);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    IMap<String, GrandParentPortableObject> map = instance2.getMap(name);
    String key = generateKeyOwnedBy(instance1);
    map.put(key, new GrandParentPortableObject(1, new ParentPortableObject(1L, new ChildPortableObject(1L))));
    waitAllForSafeState(instance1, instance2);
    Collection<GrandParentPortableObject> values = map.values(new SqlPredicate("child.timestamp > 0"));
    assertEquals(1, values.size());
    values = map.values(new SqlPredicate("child.child.timestamp > 0"));
    assertEquals(1, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ChildPortableObject(com.hazelcast.nio.serialization.PortableTest.ChildPortableObject) ParentPortableObject(com.hazelcast.nio.serialization.PortableTest.ParentPortableObject) GrandParentPortableObject(com.hazelcast.nio.serialization.PortableTest.GrandParentPortableObject) SqlPredicate(com.hazelcast.query.SqlPredicate) GrandParentPortableObject(com.hazelcast.nio.serialization.PortableTest.GrandParentPortableObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 98 with SqlPredicate

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

the class QueryBasicTest method doFunctionalSQLQueryTest.

public static void doFunctionalSQLQueryTest(IMap<String, Employee> map) {
    map.put("1", new Employee("joe", 33, false, 14.56));
    map.put("2", new Employee("ali", 23, true, 15.00));
    for (int i = 3; i < 103; i++) {
        map.put(String.valueOf(i), new Employee("name" + i, i % 60, ((i & 1) == 1), i));
    }
    Set<Map.Entry<String, Employee>> entries = map.entrySet();
    assertEquals(102, entries.size());
    int entryCount = 0;
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertNotNull(employee);
        entryCount++;
    }
    assertEquals(102, entryCount);
    entries = map.entrySet(new SqlPredicate("active=true and age=23"));
    assertEquals(3, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    map.remove("2");
    entries = map.entrySet(new SqlPredicate("active=true and age=23"));
    assertEquals(2, entries.size());
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
    entries = map.entrySet(new SqlPredicate("age!=33"));
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertTrue(employee.getAge() != 33);
    }
    entries = map.entrySet(new SqlPredicate("active!=false"));
    for (Map.Entry entry : entries) {
        Employee employee = (Employee) entry.getValue();
        assertTrue(employee.isActive());
    }
}
Also used : Employee(com.hazelcast.query.SampleObjects.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Example 99 with SqlPredicate

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

the class QueryBasicTest method testSqlQueryUsingPortable__KeyField.

@Test
public void testSqlQueryUsingPortable__KeyField() {
    Config config = getConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    factory.newHazelcastInstance(config);
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap(randomMapName());
    Object key = new ChildPortableObject(123L);
    Object value = "value";
    map.put(key, value);
    Collection<Object> values = map.values(new SqlPredicate("__key.timestamp = 123"));
    assertEquals(1, values.size());
    assertEquals(value, values.iterator().next());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ChildPortableObject(com.hazelcast.nio.serialization.PortableTest.ChildPortableObject) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) EntryObject(com.hazelcast.query.EntryObject) ParentPortableObject(com.hazelcast.nio.serialization.PortableTest.ParentPortableObject) GrandParentPortableObject(com.hazelcast.nio.serialization.PortableTest.GrandParentPortableObject) ChildPortableObject(com.hazelcast.nio.serialization.PortableTest.ChildPortableObject) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 100 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)

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