Search in sources :

Example 46 with SqlPredicate

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

the class QueryBasicTest method testQueryPortableField.

@Test(expected = QueryException.class)
public void testQueryPortableField() {
    Config config = getConfig();
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap(randomMapName());
    map.put(1, new GrandParentPortableObject(1, new ParentPortableObject(1L, new ChildPortableObject(1L))));
    Collection<Object> values = map.values(new SqlPredicate("child > 0"));
    values.size();
}
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) ParentPortableObject(com.hazelcast.nio.serialization.PortableTest.ParentPortableObject) GrandParentPortableObject(com.hazelcast.nio.serialization.PortableTest.GrandParentPortableObject) 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) GrandParentPortableObject(com.hazelcast.nio.serialization.PortableTest.GrandParentPortableObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 47 with SqlPredicate

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

the class QueryBasicTest method testWithDashInTheNameAndSqlPredicate.

@Test(timeout = 1000 * 60)
public void testWithDashInTheNameAndSqlPredicate() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Employee> map = instance.getMap("employee");
    Employee toto = new Employee("toto", 23, true, 165765.0);
    map.put("1", toto);
    Employee toto2 = new Employee("toto-super+hero", 23, true, 165765.0);
    map.put("2", toto2);
    // works well
    Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("name='toto-super+hero'"));
    assertTrue(entries.size() > 0);
    for (Map.Entry<String, Employee> entry : entries) {
        Employee e = entry.getValue();
        assertEquals(e, toto2);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) 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 48 with SqlPredicate

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

the class QueryBasicTest method testQueryUsingPortableObject.

private void testQueryUsingPortableObject(Config config, String mapName) {
    addPortableFactories(config);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    IMap<Object, Object> map = instance2.getMap(mapName);
    Object key = generateKeyOwnedBy(instance1);
    map.put(key, new ParentPortableObject(1L));
    waitAllForSafeState(instance1, instance2);
    Collection<Object> values = map.values(new SqlPredicate("timestamp > 0"));
    assertEquals(1, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParentPortableObject(com.hazelcast.nio.serialization.PortableTest.ParentPortableObject) GrandParentPortableObject(com.hazelcast.nio.serialization.PortableTest.GrandParentPortableObject) 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)

Example 49 with SqlPredicate

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

the class QueryBasicTest method testIndexingEnumAttributeWithSqlIssue597.

/**
     * see pull request 616
     */
@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeWithSqlIssue597() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap("default");
    map.addIndex("state", true);
    for (int i = 0; i < 4; i++) {
        Value v = new Value(i % 2 == 0 ? State.STATE1 : State.STATE2, new ValueType(), i);
        map.put(i, v);
    }
    Collection<Value> values = map.values(new SqlPredicate("state = 'STATE1'"));
    int[] expectedValues = new int[] { 0, 2 };
    assertEquals(expectedValues.length, values.size());
    int[] indexes = new int[2];
    int index = 0;
    for (Value configObject : values) {
        indexes[index++] = configObject.getIndex();
    }
    Arrays.sort(indexes);
    assertArrayEquals(indexes, expectedValues);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) 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)

Example 50 with SqlPredicate

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

the class QueryBasicTest method issue393SqlIn.

@Test(timeout = 1000 * 60)
public void issue393SqlIn() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, 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);
    }
    Predicate predicate = new SqlPredicate("name IN ('name0', 'name2')");
    Collection<Value> values = map.values(predicate);
    String[] expectedValues = new String[] { "name0", "name2" };
    assertEquals(expectedValues.length, values.size());
    List<String> names = new ArrayList<String>();
    for (Value configObject : values) {
        names.add(configObject.getName());
    }
    String[] array = names.toArray(new String[names.size()]);
    Arrays.sort(array);
    assertArrayEquals(names.toString(), expectedValues, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) 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)

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