Search in sources :

Example 11 with Indexes

use of com.hazelcast.query.impl.Indexes 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 12 with Indexes

use of com.hazelcast.query.impl.Indexes 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 13 with Indexes

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

the class AbstractVisitorTest method testAllVisitMethodReturnTheOriginalPredicate.

@Test
public void testAllVisitMethodReturnTheOriginalPredicate() throws Exception {
    // Contract of AbstractVisitor mandates to return original predicate
    // for all methods on Visitor interface.
    // This test makes sure if a new method is added into Visitor interface
    // then it's added to AbstractVisitor and honour its contract
    AbstractVisitor visitor = new AbstractVisitor() {
    };
    Method[] methods = Visitor.class.getMethods();
    for (Method method : methods) {
        Class<?> predicateType = method.getParameterTypes()[0];
        Predicate predicate = (Predicate) predicateType.newInstance();
        Indexes indexes = mock(Indexes.class);
        Object result = method.invoke(visitor, predicate, indexes);
        assertSame("Method " + method + " does not return identity of the original predicate. " + "See contract of " + AbstractVisitor.class.getSimpleName(), predicate, result);
    }
}
Also used : Method(java.lang.reflect.Method) Indexes(com.hazelcast.query.impl.Indexes) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with Indexes

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

the class AndPredicateTest method accept_whenInnerPredicateChangedOnAccept_thenReturnAndNewAndPredicate.

@Test
public void accept_whenInnerPredicateChangedOnAccept_thenReturnAndNewAndPredicate() {
    Visitor mockVisitor = createPassthroughVisitor();
    Indexes mockIndexes = mock(Indexes.class);
    Predicate transformed = mock(Predicate.class);
    Predicate innerPredicate = createMockVisitablePredicate(transformed);
    Predicate[] innerPredicates = new Predicate[1];
    innerPredicates[0] = innerPredicate;
    AndPredicate andPredicate = new AndPredicate(innerPredicates);
    AndPredicate result = (AndPredicate) andPredicate.accept(mockVisitor, mockIndexes);
    assertThat(result, not(sameInstance(andPredicate)));
    Predicate[] newInnerPredicates = result.predicates;
    assertThat(newInnerPredicates, arrayWithSize(1));
    assertThat(newInnerPredicates[0], equalTo(transformed));
}
Also used : PredicateTestUtils.createPassthroughVisitor(com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor) PredicateTestUtils.createDelegatingVisitor(com.hazelcast.query.impl.predicates.PredicateTestUtils.createDelegatingVisitor) Indexes(com.hazelcast.query.impl.Indexes) PredicateTestUtils.createMockNegatablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockNegatablePredicate) PredicateTestUtils.createMockVisitablePredicate(com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with Indexes

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

the class EmptyOptimizerTest method optimize_returnsOriginalPredicate.

@Test
public void optimize_returnsOriginalPredicate() {
    EmptyOptimizer emptyOptimizer = new EmptyOptimizer();
    Predicate predicate = mock(Predicate.class);
    Indexes indexes = mock(Indexes.class);
    Predicate result = emptyOptimizer.optimize(predicate, indexes);
    assertSame(predicate, result);
}
Also used : Indexes(com.hazelcast.query.impl.Indexes) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Indexes (com.hazelcast.query.impl.Indexes)17 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 Data (com.hazelcast.nio.serialization.Data)6 Predicate (com.hazelcast.query.Predicate)5 PredicateTestUtils.createPassthroughVisitor (com.hazelcast.query.impl.predicates.PredicateTestUtils.createPassthroughVisitor)5 Record (com.hazelcast.map.impl.record.Record)4 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)4 PredicateTestUtils.createDelegatingVisitor (com.hazelcast.query.impl.predicates.PredicateTestUtils.createDelegatingVisitor)3 PredicateTestUtils.createMockVisitablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockVisitablePredicate)3 MapService (com.hazelcast.map.impl.MapService)2 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)2 RecordStore (com.hazelcast.map.impl.recordstore.RecordStore)2 Index (com.hazelcast.query.impl.Index)2 PredicateTestUtils.createMockNegatablePredicate (com.hazelcast.query.impl.predicates.PredicateTestUtils.createMockNegatablePredicate)2 HashMap (java.util.HashMap)2 LockService (com.hazelcast.concurrent.lock.LockService)1 NativeMemoryConfig (com.hazelcast.config.NativeMemoryConfig)1 MapInterceptor (com.hazelcast.map.MapInterceptor)1