use of com.hazelcast.query.impl.predicates.SqlPredicate in project hazelcast by hazelcast.
the class CompositeIndexQueriesTest method check.
private void check(String sql, int expectedSize, int... queryCounts) {
if (sql != null) {
SqlPredicate sqlPredicate = (SqlPredicate) Predicates.sql(sql);
Set<Map.Entry<Integer, Person>> result = map.entrySet(sqlPredicate);
assertEquals(expectedSize, result.size());
// here we are checking the original unoptimized predicate
for (Map.Entry<Integer, Person> entry : result) {
assertTrue(sqlPredicate.apply(new ExtractableAdapter(entry)));
}
// The goal here is to check fallback predicates generated by
// CompositeEqualPredicate and CompositeRangePredicate.
Set<Map.Entry<Integer, Person>> noIndexResult = map.entrySet(new NoIndexPredicate(sqlPredicate.getPredicate()));
assertEquals(result, noIndexResult);
}
assert indexes.size() == queryCounts.length;
for (int i = 0; i < queryCounts.length; ++i) {
assertEquals(queryCounts[i], map.getLocalMapStats().getIndexStats().get(indexes.get(i)).getQueryCount());
}
}
use of com.hazelcast.query.impl.predicates.SqlPredicate 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)));
}
Aggregations