use of com.hazelcast.query.PagingPredicate in project hazelcast-simulator by hazelcast.
the class MapPredicateTest method pagePredicate.
@TimeStep(prob = 0.2)
public void pagePredicate(ThreadState state) {
double maxSalary = state.randomDouble() * Employee.MAX_SALARY;
Predicate predicate = Predicates.lessThan("salary", maxSalary);
SalaryComparator salaryComparator = new SalaryComparator();
PagingPredicate pagingPredicate = new PagingPredicate(predicate, salaryComparator, pageSize);
Collection<Employee> employees;
List<Employee> employeeList;
do {
employees = map.values(pagingPredicate);
employeeList = fillListWithQueryResultSet(employees);
Employee nextEmployee;
Employee currentEmployee;
for (int i = 0; i < employeeList.size() - 1; i++) {
currentEmployee = employeeList.get(i);
nextEmployee = employeeList.get(i + 1);
// check the order & max salary
assertTrue(format(baseAssertMessage, currentEmployee.getSalary(), predicate), currentEmployee.getSalary() <= nextEmployee.getSalary() && nextEmployee.getSalary() < maxSalary);
}
pagingPredicate.nextPage();
} while (!employees.isEmpty());
state.operationCounter.pagePredicateCount++;
}
use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.
the class PagingPredicateTest method mapPagingPredicateEmployeeObjectWithOrderedIndex.
private void mapPagingPredicateEmployeeObjectWithOrderedIndex(int maxEmployee) {
final IMap<Integer, Employee> map = makeEmployeeMap(maxEmployee);
map.addIndex(IndexType.SORTED, "id");
Predicate innerPredicate = Predicates.lessThan("id", 2);
PagingPredicate<Integer, Employee> predicate = Predicates.pagingPredicate(innerPredicate, 2);
Collection<Employee> values;
values = map.values(predicate);
System.out.println(values);
assertEquals(2, values.size());
predicate.nextPage();
values = map.values(predicate);
System.out.println(values);
assertEquals(0, values.size());
}
use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.
the class MapQueryEngineImpl method adjustQuery.
private Query adjustQuery(Query query) {
IterationType retrievalIterationType = getRetrievalIterationType(query.getPredicate(), query.getIterationType());
Query adjustedQuery = Query.of(query).iterationType(retrievalIterationType).build();
if (adjustedQuery.getPredicate() instanceof PagingPredicate) {
((PagingPredicate) adjustedQuery.getPredicate()).setIterationType(query.getIterationType());
} else {
if (adjustedQuery.getPredicate() == TruePredicate.INSTANCE) {
queryResultSizeLimiter.precheckMaxResultLimitOnLocalPartitions(adjustedQuery.getMapName());
}
}
return adjustedQuery;
}
use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.
the class PartitionScanRunner method run.
@SuppressWarnings("unchecked")
public Collection<QueryableEntry> run(String mapName, Predicate predicate, int partitionId) {
PagingPredicate pagingPredicate = predicate instanceof PagingPredicate ? (PagingPredicate) predicate : null;
List<QueryableEntry> resultList = new LinkedList<QueryableEntry>();
PartitionContainer partitionContainer = mapServiceContext.getPartitionContainer(partitionId);
MapContainer mapContainer = mapServiceContext.getMapContainer(mapName);
Iterator<Record> iterator = partitionContainer.getRecordStore(mapName).loadAwareIterator(getNow(), false);
Map.Entry<Integer, Map.Entry> nearestAnchorEntry = getNearestAnchorEntry(pagingPredicate);
boolean useCachedValues = isUseCachedDeserializedValuesEnabled(mapContainer);
Extractors extractors = mapServiceContext.getExtractors(mapName);
while (iterator.hasNext()) {
Record record = iterator.next();
Data key = (Data) toData(record.getKey());
Object value = toData(useCachedValues ? Records.getValueOrCachedValue(record, serializationService) : record.getValue());
if (value == null) {
continue;
}
//we want to always use CachedQueryEntry as these are short-living objects anyway
QueryableEntry queryEntry = new CachedQueryEntry(serializationService, key, value, extractors);
if (predicate.apply(queryEntry) && compareAnchor(pagingPredicate, queryEntry, nearestAnchorEntry)) {
resultList.add(queryEntry);
}
}
return getSortedSubList(resultList, pagingPredicate, nearestAnchorEntry);
}
use of com.hazelcast.query.PagingPredicate in project hazelcast by hazelcast.
the class ClientPagingPredicateTest method pagingPredicateWithEmployeeObjectTest.
private List<Employee> pagingPredicateWithEmployeeObjectTest(IMap<Integer, Employee> map, Predicate<Integer, Employee> predicate, int pageSize) {
PagingPredicate<Integer, Employee> pagingPredicate = new PagingPredicate<Integer, Employee>(predicate, pageSize);
Set<Map.Entry<Integer, Employee>> set;
List<Employee> results = new ArrayList<Employee>();
do {
set = map.entrySet(pagingPredicate);
for (Map.Entry<Integer, Employee> entry : set) {
Employee e = entry.getValue();
QueryEntry qe = new QueryEntry((InternalSerializationService) serializationService, serializationService.toData(e.getId()), e, Extractors.empty());
assertTrue(predicate.apply(qe));
results.add(e);
}
pagingPredicate.nextPage();
} while (!set.isEmpty());
return results;
}
Aggregations