Search in sources :

Example 1 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class MapMBean method entrySet.

@ManagedAnnotation(value = "entrySet", operation = true)
public String entrySet(String query) {
    Set<Map.Entry> entrySet;
    if (query != null && !query.isEmpty()) {
        Predicate predicate = new SqlPredicate(query);
        entrySet = managedObject.entrySet(predicate);
    } else {
        entrySet = managedObject.entrySet();
    }
    StringBuilder buf = new StringBuilder();
    if (entrySet.size() == 0) {
        buf.append("Empty");
    } else {
        buf.append("[");
        for (Map.Entry entry : entrySet) {
            buf.append("{key:");
            buf.append(entry.getKey());
            buf.append(", value:");
            buf.append(entry.getValue());
            buf.append("}, ");
        }
        buf.replace(buf.length() - 1, buf.length(), "]");
    }
    return buf.toString();
}
Also used : SqlPredicate(com.hazelcast.query.SqlPredicate) IMap(com.hazelcast.core.IMap) Map(java.util.Map) Predicate(com.hazelcast.query.Predicate) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 2 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class MapQueryEngineImplTest method runQueryOnAllPartitions_key.

@Test
public void runQueryOnAllPartitions_key() throws ExecutionException, InterruptedException {
    Predicate predicate = Predicates.equal("this", value);
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(KEY).build();
    QueryResult result = queryEngine.execute(query, Target.ALL_NODES);
    assertEquals(1, result.size());
    assertEquals(key, toObject(result.iterator().next().getKey()));
}
Also used : Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class MapQueryEngineImplTest method runQueryOnAllPartitions.

@Test
public void runQueryOnAllPartitions() throws ExecutionException, InterruptedException {
    Predicate predicate = Predicates.equal("this", value);
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(KEY).build();
    QueryResult result = queryEngine.execute(query, Target.ALL_NODES);
    assertEquals(1, result.size());
    assertEquals(key, toObject(result.iterator().next().getKey()));
}
Also used : Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class QueryRunner method runPartitionScanQueryOnGivenOwnedPartition.

Result runPartitionScanQueryOnGivenOwnedPartition(Query query, int partitionId) throws ExecutionException, InterruptedException {
    MapContainer mapContainer = mapServiceContext.getMapContainer(query.getMapName());
    Predicate predicate = queryOptimizer.optimize(query.getPredicate(), mapContainer.getIndexes());
    Collection<QueryableEntry> entries = partitionScanExecutor.execute(query.getMapName(), predicate, Collections.singletonList(partitionId));
    return populateTheResult(query, entries, Collections.singletonList(partitionId));
}
Also used : MapContainer(com.hazelcast.map.impl.MapContainer) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate)

Example 5 with Predicate

use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.

the class BetweenVisitor method findCandidatesAndGroupByAttribute.

/**
     * Find GreaterLessPredicates with equal flag set to true and group them by attribute name
     */
private InternalListMultiMap<String, GreaterLessPredicate> findCandidatesAndGroupByAttribute(Predicate[] predicates, Indexes indexService) {
    InternalListMultiMap<String, GreaterLessPredicate> candidates = null;
    for (Predicate predicate : predicates) {
        if (!(predicate instanceof GreaterLessPredicate)) {
            continue;
        }
        GreaterLessPredicate greaterLessPredicate = (GreaterLessPredicate) predicate;
        if (!(greaterLessPredicate.equal)) {
            continue;
        }
        String attributeName = greaterLessPredicate.attributeName;
        Index index = indexService.getIndex(attributeName);
        if (index == null || index.getConverter() == null) {
            continue;
        }
        candidates = addIntoCandidates(greaterLessPredicate, candidates);
    }
    return candidates;
}
Also used : Index(com.hazelcast.query.impl.Index) FalsePredicate(com.hazelcast.query.impl.FalsePredicate) Predicate(com.hazelcast.query.Predicate)

Aggregations

Predicate (com.hazelcast.query.Predicate)248 Test (org.junit.Test)165 QuickTest (com.hazelcast.test.annotation.QuickTest)159 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)105 HazelcastInstance (com.hazelcast.core.HazelcastInstance)38 MapListener (com.hazelcast.map.listener.MapListener)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)17 EntryListener (com.hazelcast.core.EntryListener)16 FalsePredicate (com.hazelcast.query.impl.FalsePredicate)15 ArrayList (java.util.ArrayList)15 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)14 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)14 Value (com.hazelcast.query.SampleTestObjects.Value)10 SqlPredicate (com.hazelcast.query.SqlPredicate)10 Config (com.hazelcast.config.Config)9 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)9 EntryEvent (com.hazelcast.core.EntryEvent)8 Data (com.hazelcast.internal.serialization.Data)8 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)8 Indexes (com.hazelcast.query.impl.Indexes)8