Search in sources :

Example 26 with QueryableEntry

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

the class AddIndexOperation method run.

@Override
public void run() throws Exception {
    Indexes indexes = mapContainer.getIndexes();
    Index index = indexes.addOrGetIndex(attributeName, ordered);
    final long now = getNow();
    final Iterator<Record> iterator = recordStore.iterator(now, false);
    SerializationService serializationService = getNodeEngine().getSerializationService();
    while (iterator.hasNext()) {
        final Record record = iterator.next();
        Data key = record.getKey();
        Object value = Records.getValueOrCachedValue(record, serializationService);
        QueryableEntry queryEntry = mapContainer.newQueryEntry(key, value);
        index.saveEntryIndex(queryEntry, null);
    }
}
Also used : SerializationService(com.hazelcast.spi.serialization.SerializationService) Index(com.hazelcast.query.impl.Index) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 27 with QueryableEntry

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

the class MapMigrationAwareService method migrateIndex.

private void migrateIndex(PartitionMigrationEvent event) {
    final long now = getNow();
    final PartitionContainer container = mapServiceContext.getPartitionContainer(event.getPartitionId());
    for (RecordStore recordStore : container.getMaps().values()) {
        final MapContainer mapContainer = mapServiceContext.getMapContainer(recordStore.getName());
        final Indexes indexes = mapContainer.getIndexes();
        if (!indexes.hasIndex()) {
            continue;
        }
        final Iterator<Record> iterator = recordStore.iterator(now, false);
        while (iterator.hasNext()) {
            Record record = iterator.next();
            Data key = record.getKey();
            if (event.getMigrationEndpoint() == SOURCE) {
                assert event.getNewReplicaIndex() != 0 : "Invalid migration event: " + event;
                Object value = Records.getValueOrCachedValue(record, serializationService);
                indexes.removeEntryIndex(key, value);
            } else if (event.getNewReplicaIndex() == 0) {
                Object value = Records.getValueOrCachedValue(record, serializationService);
                if (value != null) {
                    QueryableEntry queryEntry = mapContainer.newQueryEntry(record.getKey(), value);
                    indexes.saveEntryIndex(queryEntry, null);
                }
            }
        }
    }
}
Also used : RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) Record(com.hazelcast.map.impl.record.Record) Data(com.hazelcast.nio.serialization.Data) Indexes(com.hazelcast.query.impl.Indexes) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 28 with QueryableEntry

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

the class CallerRunsPartitionScanExecutorTest method execute_success.

@Test
public void execute_success() throws Exception {
    PartitionScanRunner runner = mock(PartitionScanRunner.class);
    CallerRunsPartitionScanExecutor executor = new CallerRunsPartitionScanExecutor(runner);
    Predicate predicate = Predicates.equal("attribute", 1);
    Collection<QueryableEntry> result = executor.execute("Map", predicate, asList(1, 2, 3));
    assertEquals(0, result.size());
}
Also used : QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with QueryableEntry

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

the class ParallelPartitionScanExecutorTest method execute_success.

@Test
public void execute_success() throws Exception {
    PartitionScanRunner runner = mock(PartitionScanRunner.class);
    ParallelPartitionScanExecutor executor = executor(runner);
    Predicate predicate = Predicates.equal("attribute", 1);
    List<QueryableEntry> result = executor.execute("Map", predicate, asList(1, 2, 3));
    assertEquals(0, result.size());
}
Also used : QueryableEntry(com.hazelcast.query.impl.QueryableEntry) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with QueryableEntry

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

the class QueryEventFilterTest method testEval_givenFilterContainsKey_whenKeyOfEntryIsEqualAndPredicacteIsMatching_thenReturnTrue.

@Test
public void testEval_givenFilterContainsKey_whenKeyOfEntryIsEqualAndPredicacteIsMatching_thenReturnTrue() {
    //given
    Data key1 = serializationService.toData("key1");
    Predicate predicate = TruePredicate.INSTANCE;
    QueryEventFilter filter = new QueryEventFilter(true, key1, predicate);
    //when
    Data key2 = serializationService.toData("key1");
    QueryableEntry entry = mockEntryWithKeyData(key2);
    //then
    boolean result = filter.eval(entry);
    assertTrue(result);
}
Also used : Data(com.hazelcast.nio.serialization.Data) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) TruePredicate(com.hazelcast.query.TruePredicate) FalsePredicate(com.hazelcast.query.impl.FalsePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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