Search in sources :

Example 11 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class QueryEventFilterTest method mockEntryWithKeyData.

private QueryableEntry mockEntryWithKeyData(Data key) {
    QueryableEntry entry = mock(QueryableEntry.class);
    when(entry.getKeyData()).thenReturn(key);
    return entry;
}
Also used : QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 12 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class NotEqualPredicateTest method apply_givenAttributeValueIsNull_whenEntryHasTheAttributeIsNotNull_thenReturnTrue.

@Test
public void apply_givenAttributeValueIsNull_whenEntryHasTheAttributeIsNotNull_thenReturnTrue() {
    NotEqualPredicate name = new NotEqualPredicate("name", null);
    QueryableEntry mockEntry = newMockEntry("foo");
    boolean result = name.apply(mockEntry);
    assertTrue(result);
}
Also used : QueryableEntry(com.hazelcast.query.impl.QueryableEntry) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class NotEqualPredicateTest method newMockEntry.

private QueryableEntry newMockEntry(Object attributeValue) {
    QueryableEntry mockEntry = mock(QueryableEntry.class);
    when(mockEntry.getAttributeValue(anyString())).thenReturn(attributeValue);
    return mockEntry;
}
Also used : QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 14 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class QueryRunner method runIndexOrPartitionScanQueryOnOwnedPartitions.

// full query = index query (if possible), then partition-scan query
public Result runIndexOrPartitionScanQueryOnOwnedPartitions(Query query) throws ExecutionException, InterruptedException {
    int migrationStamp = getMigrationStamp();
    Collection<Integer> initialPartitions = mapServiceContext.getOwnedPartitions();
    MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
    // first we optimize the query
    Predicate predicate = queryOptimizer.optimize(query.getPredicate(), mapContainer.getIndexes());
    // then we try to run using an index, but if that doesn't work, we'll try a full table scan
    // This would be the point where a query-plan should be added. It should determine f a full table scan
    // or an index should be used.
    Collection<QueryableEntry> entries = runUsingIndexSafely(predicate, mapContainer, migrationStamp);
    if (entries == null) {
        entries = runUsingPartitionScanSafely(query.getMapName(), predicate, initialPartitions, migrationStamp);
    }
    updateStatistics(mapContainer);
    if (entries != null) {
        // so that caller is aware of partitions from which results were obtained.
        return populateTheResult(query, entries, initialPartitions);
    } else {
        // then return empty result set without any partition IDs set (so that it is ignored by callers).
        return resultProcessorRegistry.get(query.getResultType()).populateResult(query, queryResultSizeLimiter.getNodeResultLimit(initialPartitions.size()));
    }
}
Also used : MapContainer(com.hazelcast.map.impl.MapContainer) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate)

Example 15 with QueryableEntry

use of com.hazelcast.query.impl.QueryableEntry in project hazelcast by hazelcast.

the class CallerRunsAccumulationExecutor method execute.

@Override
@SuppressWarnings("unchecked")
public AggregationResult execute(Aggregator aggregator, Collection<QueryableEntry> entries, Collection<Integer> partitionIds) {
    Aggregator resultAggregator = serializationService.toObject(serializationService.toData(aggregator));
    try {
        for (QueryableEntry entry : entries) {
            resultAggregator.accumulate(entry);
        }
    } finally {
        resultAggregator.onAccumulationFinished();
    }
    AggregationResult result = new AggregationResult(resultAggregator);
    result.setPartitionIds(partitionIds);
    return result;
}
Also used : Aggregator(com.hazelcast.aggregation.Aggregator) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Aggregations

QueryableEntry (com.hazelcast.query.impl.QueryableEntry)34 Data (com.hazelcast.nio.serialization.Data)14 Predicate (com.hazelcast.query.Predicate)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)10 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Test (org.junit.Test)10 TruePredicate (com.hazelcast.query.TruePredicate)5 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)5 HashSet (java.util.HashSet)5 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)4 Indexes (com.hazelcast.query.impl.Indexes)4 Extractors (com.hazelcast.query.impl.getters.Extractors)4 SerializationService (com.hazelcast.spi.serialization.SerializationService)4 Map (java.util.Map)4 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)3 MapContainer (com.hazelcast.map.impl.MapContainer)3 Record (com.hazelcast.map.impl.record.Record)3 TransactionalMap (com.hazelcast.core.TransactionalMap)2 MapQueryEngine (com.hazelcast.map.impl.query.MapQueryEngine)2 Query (com.hazelcast.map.impl.query.Query)2