Search in sources :

Example 26 with Predicate

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

the class GenericPredicatesTest method testAnd.

@Test
public void testAnd() {
    final Predicate and1 = and(greaterThan(ATTRIBUTE, 4), lessThan(ATTRIBUTE, 6));
    assertPredicateTrue(and1, 5);
    final Predicate and2 = and(greaterThan(ATTRIBUTE, 5), lessThan(ATTRIBUTE, 6));
    assertPredicateFalse(and2, 4);
}
Also used : Predicate(com.hazelcast.query.Predicate) ILikePredicate(com.hazelcast.query.impl.predicates.ILikePredicate) Test(org.junit.Test)

Example 27 with Predicate

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

the class GenericPredicatesTest method testOr.

@Test
public void testOr() {
    final Predicate or1 = or(equal(ATTRIBUTE, 3), equal(ATTRIBUTE, 4), equal(ATTRIBUTE, 5));
    assertPredicateTrue(or1, 4);
    assertPredicateFalse(or1, 6);
}
Also used : Predicate(com.hazelcast.query.Predicate) ILikePredicate(com.hazelcast.query.impl.predicates.ILikePredicate) Test(org.junit.Test)

Example 28 with Predicate

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

the class SnapshotRepository method deleteAllSnapshots.

/**
 * Delete all snapshots for a given job
 */
void deleteAllSnapshots(long jobId) {
    final IMapJet<Long, SnapshotRecord> snapshotMap = getSnapshotMap(jobId);
    Predicate predicate = e -> !e.getKey().equals(LATEST_STARTED_SNAPSHOT_ID_KEY);
    for (Entry<Long, SnapshotRecord> entry : snapshotMap.entrySet(predicate)) {
        deleteSnapshotData(entry.getValue());
    }
    logFine(logger, "Deleted all snapshots for job %s", idToString(jobId));
    snapshotMap.destroy();
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Util.compute(com.hazelcast.jet.impl.util.Util.compute) SnapshotRecord(com.hazelcast.jet.impl.execution.SnapshotRecord) Collection(java.util.Collection) IMapJet(com.hazelcast.jet.IMapJet) LoggingUtil.logFinest(com.hazelcast.jet.impl.util.LoggingUtil.logFinest) SnapshotStatus(com.hazelcast.jet.impl.execution.SnapshotRecord.SnapshotStatus) Util.idToString(com.hazelcast.jet.impl.util.Util.idToString) IMap(com.hazelcast.core.IMap) ILogger(com.hazelcast.logging.ILogger) LoggingUtil.logFine(com.hazelcast.jet.impl.util.LoggingUtil.logFine) Entry(java.util.Map.Entry) Predicate(com.hazelcast.query.Predicate) Nullable(javax.annotation.Nullable) MaxByAggregator(com.hazelcast.aggregation.impl.MaxByAggregator) SnapshotRecord(com.hazelcast.jet.impl.execution.SnapshotRecord) Predicate(com.hazelcast.query.Predicate)

Example 29 with Predicate

use of com.hazelcast.query.Predicate in project jnosql-diana-driver by eclipse.

the class HazelcastBucketManagerQueryTest method shouldReturnActiveAndGreaterThan2000Predicate.

@Test
public void shouldReturnActiveAndGreaterThan2000Predicate() {
    Predicate predicate = and(equal("active", false), greaterEqual("year", 1990));
    Collection<Value> result = bucketManager.query(predicate);
    assertEquals(2, result.size());
}
Also used : Value(org.jnosql.diana.api.Value) Predicate(com.hazelcast.query.Predicate) Test(org.junit.jupiter.api.Test)

Example 30 with Predicate

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

the class HazelcastMessageBuilderStorageTest method testQueries.

@Test
public void testQueries() {
    // To ensure that the messages are stored in an indexable way, we add an index to query it directly.
    IMap<String, OptionalFields._Builder> map = instance.getMap(getClass().getName() + "_queries");
    HazelcastMessageBuilderStorage<String, OptionalFields, OptionalFields._Field, OptionalFields._Builder> storage = new HazelcastMessageBuilderStorage<>(map);
    map.addIndex(OptionalFields._Field.INTEGER_VALUE.getName(), true);
    for (int i = 0; i < 100; ++i) {
        storage.put(UUID.randomUUID().toString(), generator.generate(OptionalFields.kDescriptor));
    }
    generator.withGenerator(OptionalFields.kDescriptor, gen -> {
        gen.setAlwaysPresent(OptionalFields._Field.INTEGER_VALUE);
    });
    String theId = UUID.randomUUID().toString();
    OptionalFields toSearchFor = generator.generate(OptionalFields.kDescriptor);
    storage.put(theId, toSearchFor);
    EntryObject eo = new PredicateBuilder().getEntryObject();
    Predicate q = eo.get(OptionalFields._Field.INTEGER_VALUE.getName()).equal(toSearchFor.getIntegerValue());
    Set<Map.Entry<String, OptionalFields._Builder>> res = map.entrySet(q);
    // There is a 100 / 2 p 32 chance of collision.
    assertThat(res, hasSize(1));
    AtomicReference<String> id = new AtomicReference<>();
    AtomicReference<OptionalFields> value = new AtomicReference<>();
    res.forEach(e -> {
        id.set(e.getKey());
        value.set(e.getValue().build());
    });
    assertThat(id.get(), is(theId));
    assertThat(value.get(), is(toSearchFor));
}
Also used : EntryObject(com.hazelcast.query.EntryObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) Predicate(com.hazelcast.query.Predicate) OptionalFields(net.morimekta.test.providence.storage.hazelcast.OptionalFields) PredicateBuilder(com.hazelcast.query.PredicateBuilder) Test(org.junit.Test)

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