Search in sources :

Example 6 with EqualPredicate

use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.

the class IndexJsonTest method testJsonIndex.

@Test
public void testJsonIndex() {
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    Indexes indexes = Indexes.newBuilder(ss, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).extractors(Extractors.newBuilder(ss).build()).indexProvider(new DefaultIndexProvider()).usesCachedQueryableEntries(true).statsEnabled(true).global(true).build();
    Index numberIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "age"));
    Index boolIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "active"));
    Index stringIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "name"));
    for (int i = 0; i < 1001; i++) {
        Data key = ss.toData(i);
        String jsonString = "{\"age\" : " + i + "  , \"name\" : \"sancar\" , \"active\" :  " + (i % 2 == 0) + " } ";
        indexes.putEntry(new QueryEntry(ss, key, new HazelcastJsonValue(jsonString), Extractors.newBuilder(ss).build()), null, Index.OperationSource.USER);
    }
    assertEquals(1, numberIndex.getRecords(10).size());
    assertEquals(0, numberIndex.getRecords(-1).size());
    assertEquals(1001, stringIndex.getRecords("sancar").size());
    assertEquals(501, boolIndex.getRecords(true).size());
    assertEquals(501, size(indexes.query(new AndPredicate(new EqualPredicate("name", "sancar"), new EqualPredicate("active", "true")), SKIP_PARTITIONS_COUNT_CHECK)));
    assertEquals(300, size(indexes.query(Predicates.and(Predicates.greaterThan("age", 400), Predicates.equal("active", true)), SKIP_PARTITIONS_COUNT_CHECK)));
    assertEquals(1001, size(indexes.query(new SqlPredicate("name == sancar"), SKIP_PARTITIONS_COUNT_CHECK)));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) SqlPredicate(com.hazelcast.query.impl.predicates.SqlPredicate) Data(com.hazelcast.internal.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EqualPredicate (com.hazelcast.query.impl.predicates.EqualPredicate)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 PartitionMigrationEvent (com.hazelcast.internal.partition.PartitionMigrationEvent)4 Predicate (com.hazelcast.query.Predicate)4 Data (com.hazelcast.internal.serialization.Data)2 AndPredicate (com.hazelcast.query.impl.predicates.AndPredicate)2 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)1 TestUtil.toData (com.hazelcast.instance.impl.TestUtil.toData)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 QueryContext (com.hazelcast.query.impl.QueryContext)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1 SqlPredicate (com.hazelcast.query.impl.predicates.SqlPredicate)1