Search in sources :

Example 6 with PagingPredicate

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++;
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) Employee(com.hazelcast.simulator.tests.map.helpers.Employee) SqlPredicate(com.hazelcast.query.SqlPredicate) PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate) TimeStep(com.hazelcast.simulator.test.annotations.TimeStep)

Example 7 with PagingPredicate

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());
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) Predicate(com.hazelcast.query.Predicate)

Example 8 with PagingPredicate

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;
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) IterationType(com.hazelcast.util.IterationType)

Example 9 with PagingPredicate

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);
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Data(com.hazelcast.nio.serialization.Data) LinkedList(java.util.LinkedList) MapContainer(com.hazelcast.map.impl.MapContainer) PagingPredicate(com.hazelcast.query.PagingPredicate) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) PagingPredicateAccessor.getNearestAnchorEntry(com.hazelcast.query.PagingPredicateAccessor.getNearestAnchorEntry) Extractors(com.hazelcast.query.impl.getters.Extractors) Record(com.hazelcast.map.impl.record.Record) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) Map(java.util.Map) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 10 with PagingPredicate

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;
}
Also used : QueryEntry(com.hazelcast.query.impl.QueryEntry) PagingPredicate(com.hazelcast.query.PagingPredicate) QueryEntry(com.hazelcast.query.impl.QueryEntry) ArrayList(java.util.ArrayList) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Aggregations

PagingPredicate (com.hazelcast.query.PagingPredicate)13 Predicate (com.hazelcast.query.Predicate)5 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 Data (com.hazelcast.nio.serialization.Data)3 InflatableSet (com.hazelcast.util.collection.InflatableSet)2 Map (java.util.Map)2 MapEntriesWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapEntriesWithPredicateCodec)1 MapKeySetWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapKeySetWithPredicateCodec)1 MapValuesWithPredicateCodec (com.hazelcast.client.impl.protocol.codec.MapValuesWithPredicateCodec)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.core.IMap)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 LazyMapEntry (com.hazelcast.map.impl.LazyMapEntry)1 MapContainer (com.hazelcast.map.impl.MapContainer)1 PartitionContainer (com.hazelcast.map.impl.PartitionContainer)1 AggregationResult (com.hazelcast.map.impl.query.AggregationResult)1 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)1 Query (com.hazelcast.map.impl.query.Query)1 Record (com.hazelcast.map.impl.record.Record)1 PagingPredicateAccessor.getNearestAnchorEntry (com.hazelcast.query.PagingPredicateAccessor.getNearestAnchorEntry)1