Search in sources :

Example 1 with EqualPredicate

use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.

the class QueryRunnerTest method verifyIndexedQueryFailureWhileMigrating.

@Test
public void verifyIndexedQueryFailureWhileMigrating() {
    map.addIndex(IndexType.HASH, "this");
    Predicate predicate = new EqualPredicate("this", value);
    mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
    QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
    assertNull(result.getPartitionIds());
}
Also used : EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with EqualPredicate

use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.

the class QueryRunnerTest method verifyFullScanFailureWhileMigrating.

@Test
public void verifyFullScanFailureWhileMigrating() {
    Predicate predicate = new EqualPredicate("this", value);
    mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
    QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
    assertNull(result.getPartitionIds());
}
Also used : EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with EqualPredicate

use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.

the class IndexTest method testIndex.

@Test
public void testIndex() throws QueryException {
    Indexes indexes = Indexes.newBuilder(ss, copyBehavior, DEFAULT_IN_MEMORY_FORMAT).build();
    Index dIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "d"));
    Index boolIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "bool"));
    Index strIndex = indexes.addOrGetIndex(IndexUtils.createTestIndexConfig(IndexType.HASH, "str"));
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(i % 2 == 0, -10.34d, "joe" + i));
        indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
    }
    assertEquals(1000, dIndex.getRecords(-10.34d).size());
    assertEquals(1, strIndex.getRecords("joe23").size());
    assertEquals(500, boolIndex.getRecords(true).size());
    clearIndexes(dIndex, boolIndex, strIndex);
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(false, 11.34d, "joe"));
        indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
    }
    assertEquals(0, dIndex.getRecords(-10.34d).size());
    assertEquals(0, strIndex.getRecords("joe23").size());
    assertEquals(1000, strIndex.getRecords("joe").size());
    assertEquals(1000, boolIndex.getRecords(false).size());
    assertEquals(0, boolIndex.getRecords(true).size());
    clearIndexes(dIndex, boolIndex, strIndex);
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(false, -1 * (i + 1), "joe" + i));
        indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
    }
    assertEquals(0, dIndex.getRecords(1d, true, 1001d, true).size());
    assertEquals(1000, dIndex.getRecords(-1001d, true, -1d, true).size());
    assertEquals(0, dIndex.getRecords(-1d, true, -1001d, true).size());
    clearIndexes(dIndex, boolIndex, strIndex);
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(false, 1 * (i + 1), "joe" + i));
        indexes.putEntry(new QueryEntry(ss, key, value, newExtractor()), null, Index.OperationSource.USER);
    }
    assertEquals(1000, dIndex.getRecords(1d, true, 1001d, true).size());
    assertEquals(0, dIndex.getRecords(-1d, true, -1001d, true).size());
    assertEquals(400, dIndex.getRecords(Comparison.GREATER, 600d).size());
    assertEquals(401, dIndex.getRecords(Comparison.GREATER_OR_EQUAL, 600d).size());
    assertEquals(9, dIndex.getRecords(Comparison.LESS, 10d).size());
    assertEquals(10, dIndex.getRecords(Comparison.LESS_OR_EQUAL, 10d).size());
    assertEquals(1, size(indexes.query(new AndPredicate(new EqualPredicate("d", 1d), new EqualPredicate("bool", "false")), SKIP_PARTITIONS_COUNT_CHECK)));
    assertEquals(1, size(indexes.query(new AndPredicate(new EqualPredicate("d", 1), new EqualPredicate("bool", Boolean.FALSE)), SKIP_PARTITIONS_COUNT_CHECK)));
    assertEquals(1, size(indexes.query(new AndPredicate(new EqualPredicate("d", "1"), new EqualPredicate("bool", false)), SKIP_PARTITIONS_COUNT_CHECK)));
}
Also used : AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) TestUtil.toData(com.hazelcast.instance.impl.TestUtil.toData) Data(com.hazelcast.internal.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with EqualPredicate

use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.

the class QueryRunnerTest method verifyIndexedQueryFailureWhileMigratingInFlight.

@Test
public void verifyIndexedQueryFailureWhileMigratingInFlight() {
    map.addIndex(IndexType.HASH, "this");
    Predicate predicate = new EqualPredicate("this", value) {

        @Override
        public Set<QueryableEntry> filter(QueryContext queryContext) {
            // start a new migration while executing an indexed query
            mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
            return super.filter(queryContext);
        }
    };
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
    QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
    assertNull(result.getPartitionIds());
}
Also used : EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) QueryContext(com.hazelcast.query.impl.QueryContext) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with EqualPredicate

use of com.hazelcast.query.impl.predicates.EqualPredicate in project hazelcast by hazelcast.

the class QueryRunnerTest method verifyFullScanFailureWhileMigratingInFlight.

@Test
public void verifyFullScanFailureWhileMigratingInFlight() {
    Predicate predicate = new EqualPredicate("this", value) {

        @Override
        protected boolean applyForSingleAttributeValue(Comparable attributeValue) {
            // start a new migration while executing a full scan
            mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
            return super.applyForSingleAttributeValue(attributeValue);
        }
    };
    Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
    QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
    assertNull(result.getPartitionIds());
}
Also used : EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EqualPredicate (com.hazelcast.query.impl.predicates.EqualPredicate)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 PartitionMigrationEvent (com.hazelcast.internal.partition.PartitionMigrationEvent)4 Predicate (com.hazelcast.query.Predicate)4 Data (com.hazelcast.internal.serialization.Data)2 AndPredicate (com.hazelcast.query.impl.predicates.AndPredicate)2 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)1 TestUtil.toData (com.hazelcast.instance.impl.TestUtil.toData)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 QueryContext (com.hazelcast.query.impl.QueryContext)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1 SqlPredicate (com.hazelcast.query.impl.predicates.SqlPredicate)1