Search in sources :

Example 46 with Predicate

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

the class QueryIndexTest method testInnerIndex.

@Test(timeout = 1000 * 60)
public void testInnerIndex() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<String, SampleObjects.Value> map = instance.getMap("default");
    map.addIndex("name", false);
    map.addIndex("type.typeName", false);
    for (int i = 0; i < 10; i++) {
        Value v = new Value("name" + i, i < 5 ? null : new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = new PredicateBuilder().getEntryObject().get("type.typeName").in("type8", "type6");
    Collection<SampleObjects.Value> values = map.values(predicate);
    assertEquals(2, values.size());
    List<String> typeNames = new ArrayList<String>();
    for (Value configObject : values) {
        typeNames.add(configObject.getType().getTypeName());
    }
    String[] array = typeNames.toArray(new String[typeNames.size()]);
    Arrays.sort(array);
    assertArrayEquals(typeNames.toString(), new String[] { "type6", "type8" }, array);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) 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 47 with Predicate

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

the class QueryIndexTest method testResultsReturned_whenCustomAttributeIndexed.

@Test
public void testResultsReturned_whenCustomAttributeIndexed() {
    HazelcastInstance h1 = createHazelcastInstance();
    IMap<String, CustomObject> imap = h1.getMap("objects");
    imap.addIndex("attribute", true);
    for (int i = 0; i < 10; i++) {
        CustomAttribute attr = new CustomAttribute(i, 200);
        CustomObject object = new CustomObject("o" + i, randomUUID(), attr);
        imap.put(object.getName(), object);
    }
    EntryObject entry = new PredicateBuilder().getEntryObject();
    Predicate predicate = entry.get("attribute").greaterEqual(new CustomAttribute(5, 200));
    Collection<CustomObject> values = imap.values(predicate);
    assertEquals(5, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.EntryObject) PredicateBuilder(com.hazelcast.query.PredicateBuilder) 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 48 with Predicate

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

the class QueryIndexTest method testInnerIndexSql.

@Test(timeout = 1000 * 60)
public void testInnerIndexSql() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<String, SampleObjects.Value> map = instance.getMap("default");
    map.addIndex("name", false);
    map.addIndex("type.typeName", false);
    for (int i = 0; i < 4; i++) {
        Value v = new Value("name" + i, new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    Predicate predicate = new SqlPredicate("type.typeName='type1'");
    Collection<SampleObjects.Value> values = map.values(predicate);
    assertEquals(1, values.size());
    List<String> typeNames = new ArrayList<String>();
    for (Value configObject : values) {
        typeNames.add(configObject.getType().getTypeName());
    }
    assertArrayEquals(typeNames.toString(), new String[] { "type1" }, typeNames.toArray(new String[typeNames.size()]));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) Value(com.hazelcast.query.SampleObjects.Value) ArrayList(java.util.ArrayList) 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 49 with Predicate

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

the class QueryBasicTest method negativeDouble.

@Test(timeout = 1000 * 60)
public void negativeDouble() {
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<String, Employee> map = instance.getMap("default");
    map.addIndex("salary", false);
    map.put("" + 4, new Employee(1, "default", 1, true, -70D));
    map.put("" + 3, new Employee(1, "default", 1, true, -60D));
    map.put("" + 1, new Employee(1, "default", 1, true, -10D));
    map.put("" + 2, new Employee(2, "default", 2, true, 10D));
    Predicate predicate = new SqlPredicate("salary >= -60");
    Collection<Employee> values = map.values(predicate);
    assertEquals(3, values.size());
    predicate = new SqlPredicate("salary between -20 and 20");
    values = map.values(predicate);
    assertEquals(2, values.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) 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 50 with Predicate

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

the class QueryBasicTest method testInPredicateWithEmptyArray.

@Test(timeout = 1000 * 60)
public void testInPredicateWithEmptyArray() {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    Config cfg = getConfig();
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(cfg);
    final IMap<String, Value> map = instance.getMap("default");
    for (int i = 0; i < 10; i++) {
        final Value v = new Value("name" + i, new ValueType("type" + i), i);
        map.put("" + i, v);
    }
    String[] emptyArray = new String[2];
    final Predicate predicate = new PredicateBuilder().getEntryObject().get("name").in(emptyArray);
    final Collection<Value> values = map.values(predicate);
    assertEquals(values.size(), 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ValueType(com.hazelcast.query.SampleObjects.ValueType) PredicateBuilder(com.hazelcast.query.PredicateBuilder) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) Value(com.hazelcast.query.SampleObjects.Value) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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

Predicate (com.hazelcast.query.Predicate)160 Test (org.junit.Test)125 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)107 TruePredicate (com.hazelcast.query.TruePredicate)41 SqlPredicate (com.hazelcast.query.SqlPredicate)33 HazelcastInstance (com.hazelcast.core.HazelcastInstance)26 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)23 PredicateBuilder (com.hazelcast.query.PredicateBuilder)19 EntryListener (com.hazelcast.core.EntryListener)16 MapListener (com.hazelcast.map.listener.MapListener)16 EntryObject (com.hazelcast.query.EntryObject)14 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)12 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)10 Value (com.hazelcast.query.SampleObjects.Value)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 ArrayList (java.util.ArrayList)9 EntryEvent (com.hazelcast.core.EntryEvent)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 ValueType (com.hazelcast.query.SampleObjects.ValueType)7