Search in sources :

Example 86 with SqlPredicate

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

the class QueryAdvancedTest method testTwoNodesWithPartialIndexes.

@Test
public void testTwoNodesWithPartialIndexes() throws Exception {
    Config config = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance1.getMap("employees");
    map.addIndex("name", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    for (int i = 0; i < 500; i++) {
        Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), (double) i);
        map.put(String.valueOf(i), employee);
    }
    assertEquals(2, instance1.getCluster().getMembers().size());
    assertEquals(2, instance2.getCluster().getMembers().size());
    map = instance2.getMap("employees");
    map.addIndex("name", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    Collection<Employee> entries = map.values(new SqlPredicate("name='name3' and city='city3' and age > 2"));
    assertEquals(5, entries.size());
    for (Employee employee : entries) {
        assertEquals("name3", employee.getName());
        assertEquals("city3", employee.getCity());
    }
    entries = map.values(new SqlPredicate("name LIKE '%name3' and city like '%city3' and age > 2"));
    assertEquals(5, entries.size());
    for (Employee employee : entries) {
        assertEquals("name3", employee.getName());
        assertEquals("city3", employee.getCity());
        assertTrue(employee.getAge() > 2);
    }
    entries = map.values(new SqlPredicate("name LIKE '%name3%' and city like '%city30%'"));
    assertEquals(5, entries.size());
    for (Employee employee : entries) {
        assertTrue(employee.getName().startsWith("name3"));
        assertTrue(employee.getCity().startsWith("city3"));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 87 with SqlPredicate

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

the class QueryAdvancedTest method testTwoMembersWithIndexesAndShutdown3.

@Test
public void testTwoMembersWithIndexesAndShutdown3() {
    Config config = getConfig();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    IMap<String, Employee> map = instance1.getMap("employees");
    map.addIndex("name", false);
    map.addIndex("age", true);
    map.addIndex("active", false);
    QueryBasicTest.doFunctionalQueryTest(map);
    assertEquals(101, map.size());
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    assertEquals(101, map.size());
    instance1.getLifecycleService().shutdown();
    map = instance2.getMap("employees");
    assertEquals(101, map.size());
    Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("active and age=23"));
    assertEquals(2, entries.size());
    for (Map.Entry<String, Employee> entry : entries) {
        Employee employee = entry.getValue();
        assertEquals(employee.getAge(), 23);
        assertTrue(employee.isActive());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) SqlPredicate(com.hazelcast.query.SqlPredicate) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 88 with SqlPredicate

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

the class QueryAdvancedTest method testOneMemberSQLWithoutIndex.

@Test
public void testOneMemberSQLWithoutIndex() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Employee> map = instance.getMap("employees");
    QueryBasicTest.doFunctionalSQLQueryTest(map);
    Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("active and age>23"));
    assertEquals(27, entries.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) PortableEmployee(com.hazelcast.query.SampleObjects.PortableEmployee) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 89 with SqlPredicate

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

the class QueryIndexTest method issue685RemoveIndexesOnClear.

@Test(timeout = 1000 * 60)
public void issue685RemoveIndexesOnClear() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<String, SampleObjects.Value> map = instance.getMap("default");
    map.addIndex("name", true);
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i);
        map.put("" + i, v);
    }
    map.clear();
    Predicate predicate = new SqlPredicate("name='name0'");
    Collection<SampleObjects.Value> values = map.values(predicate);
    assertEquals(0, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleObjects.Value) SqlPredicate(com.hazelcast.query.SqlPredicate) SqlPredicate(com.hazelcast.query.SqlPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 90 with SqlPredicate

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

the class QueryIndexTest method testQueryDoesNotMatchOldResults_whenEntriesAreUpdated.

@Test(timeout = 1000 * 60)
public void testQueryDoesNotMatchOldResults_whenEntriesAreUpdated() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<String, SampleObjects.Value> map = instance.getMap("default");
    map.addIndex("name", true);
    map.put("0", new Value("name"));
    map.put("0", new Value("newName"));
    Collection<SampleObjects.Value> values = map.values(new SqlPredicate("name='name'"));
    assertEquals(0, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleObjects.Value) SqlPredicate(com.hazelcast.query.SqlPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) 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