Search in sources :

Example 11 with PredicateBuilder

use of com.hazelcast.query.PredicateBuilder 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)

Example 12 with PredicateBuilder

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

the class NestedPredicateTest method nestedAttributeQuery_predicates.

@Test
public void nestedAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("limb.name").equal("leg");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body2", values.toArray(new Body[values.size()])[0].getName());
}
Also used : 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)

Example 13 with PredicateBuilder

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

the class NestedPredicateTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
}
Also used : 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)

Example 14 with PredicateBuilder

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

the class NestedPredicateWithExtractorTest method singleAttributeQuery_predicates.

@Test
public void singleAttributeQuery_predicates() throws Exception {
    // GIVEN
    map.put(1, new Body("body1", new Limb("hand")));
    map.put(2, new Body("body2", new Limb("leg")));
    // WHEN
    EntryObject e = new PredicateBuilder().getEntryObject();
    Predicate predicate = e.get("name").equal("body1");
    Collection<Body> values = map.values(predicate);
    // THEN
    assertEquals(1, values.size());
    assertEquals("body1", values.toArray(new Body[values.size()])[0].getName());
    assertEquals(2 + 1, bodyExtractorExecutions);
    assertEquals(0, limbExtractorExecutions);
}
Also used : 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)

Example 15 with PredicateBuilder

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

the class QueryBasicTest method testIndexingEnumAttributeIssue597.

@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeIssue597() {
    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);
    }
    Predicate predicate = new PredicateBuilder().getEntryObject().get("state").equal(State.STATE1);
    Collection<Value> values = map.values(predicate);
    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) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Value(com.hazelcast.query.SampleObjects.Value) 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

PredicateBuilder (com.hazelcast.query.PredicateBuilder)29 Test (org.junit.Test)20 Predicate (com.hazelcast.query.Predicate)19 SqlPredicate (com.hazelcast.query.SqlPredicate)19 QuickTest (com.hazelcast.test.annotation.QuickTest)19 EntryObject (com.hazelcast.query.EntryObject)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 ParallelTest (com.hazelcast.test.annotation.ParallelTest)12 Config (com.hazelcast.config.Config)6 Employee (com.hazelcast.query.SampleObjects.Employee)6 Value (com.hazelcast.query.SampleObjects.Value)6 MapConfig (com.hazelcast.config.MapConfig)4 MapIndexConfig (com.hazelcast.config.MapIndexConfig)3 IMap (com.hazelcast.core.IMap)3 ValueType (com.hazelcast.query.SampleObjects.ValueType)3 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 IndexAwarePredicate (com.hazelcast.query.IndexAwarePredicate)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2