Search in sources :

Example 1 with CompositeValue

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

the class PredicateDataSerializerHook method createFactory.

@Override
public DataSerializableFactory createFactory() {
    ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
    constructors[SQL_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new SqlPredicate();
        }
    };
    constructors[AND_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new AndPredicate();
        }
    };
    constructors[BETWEEN_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new BetweenPredicate();
        }
    };
    constructors[EQUAL_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new EqualPredicate();
        }
    };
    constructors[GREATERLESS_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new GreaterLessPredicate();
        }
    };
    constructors[LIKE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new LikePredicate();
        }
    };
    constructors[ILIKE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new ILikePredicate();
        }
    };
    constructors[IN_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new InPredicate();
        }
    };
    constructors[INSTANCEOF_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new InstanceOfPredicate();
        }
    };
    constructors[NOTEQUAL_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new NotEqualPredicate();
        }
    };
    constructors[NOT_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new NotPredicate();
        }
    };
    constructors[OR_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new OrPredicate();
        }
    };
    constructors[REGEX_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new RegexPredicate();
        }
    };
    constructors[FALSE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return FalsePredicate.INSTANCE;
        }
    };
    constructors[TRUE_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return TruePredicate.INSTANCE;
        }
    };
    constructors[PAGING_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PagingPredicateImpl();
        }
    };
    constructors[PARTITION_PREDICATE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return new PartitionPredicateImpl();
        }
    };
    constructors[NULL_OBJECT] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        public IdentifiedDataSerializable createNew(Integer arg) {
            return IndexImpl.NULL;
        }
    };
    constructors[COMPOSITE_VALUE] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        @Override
        public IdentifiedDataSerializable createNew(Integer arg) {
            return new CompositeValue();
        }
    };
    constructors[NEGATIVE_INFINITY] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        @Override
        public IdentifiedDataSerializable createNew(Integer arg) {
            return CompositeValue.NEGATIVE_INFINITY;
        }
    };
    constructors[POSITIVE_INFINITY] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {

        @Override
        public IdentifiedDataSerializable createNew(Integer arg) {
            return CompositeValue.POSITIVE_INFINITY;
        }
    };
    return new ArrayDataSerializableFactory(constructors);
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) CompositeValue(com.hazelcast.query.impl.CompositeValue)

Example 2 with CompositeValue

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

the class CompositeIndexVisitor method generateEqualPredicate.

private static Predicate generateEqualPredicate(InternalIndex index, Map<String, EqualPredicate> prefixes, boolean fast) {
    String[] components = index.getComponents();
    Comparable[] values = new Comparable[components.length];
    for (int i = 0; i < components.length; ++i) {
        String attribute = components[i];
        values[i] = fast ? prefixes.get(attribute).value : prefixes.remove(attribute).value;
    }
    return new CompositeEqualPredicate(index, new CompositeValue(values));
}
Also used : CompositeValue(com.hazelcast.query.impl.CompositeValue)

Example 3 with CompositeValue

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

the class CompositeIndexVisitor method generateRangePredicate.

private static Predicate generateRangePredicate(InternalIndex index, Map<String, EqualPredicate> prefixes, int prefixLength, boolean fast) {
    // see CompositeValue docs for more details on what is going on here
    String[] components = index.getComponents();
    Comparable[] from = new Comparable[components.length];
    Comparable[] to = new Comparable[components.length];
    for (int i = 0; i < prefixLength; ++i) {
        String attribute = components[i];
        Comparable value = fast ? prefixes.get(attribute).value : prefixes.remove(attribute).value;
        from[i] = value;
        to[i] = value;
    }
    for (int i = prefixLength; i < components.length; ++i) {
        from[i] = NEGATIVE_INFINITY;
        to[i] = POSITIVE_INFINITY;
    }
    return new CompositeRangePredicate(index, new CompositeValue(from), false, new CompositeValue(to), false, prefixLength);
}
Also used : CompositeValue(com.hazelcast.query.impl.CompositeValue)

Example 4 with CompositeValue

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

the class MapFetchIndexOperationTest method testRangeComposite.

@Test
public void testRangeComposite() throws ExecutionException, InterruptedException {
    PartitionIdSet partitions = getLocalPartitions(instance);
    IndexIterationPointer[] pointers = new IndexIterationPointer[1];
    pointers[0] = IndexIterationPointer.create(new CompositeValue(new Comparable[] { 30, CompositeValue.NEGATIVE_INFINITY }), true, new CompositeValue(new Comparable[] { CompositeValue.POSITIVE_INFINITY, CompositeValue.POSITIVE_INFINITY }), true, false, null);
    MapOperationProvider operationProvider = getOperationProvider(map);
    MapOperation operation = operationProvider.createFetchIndexOperation(mapName, compositeOrderedIndexName, pointers, partitions, 10);
    Address address = instance.getCluster().getLocalMember().getAddress();
    OperationServiceImpl operationService = getOperationService(instance);
    MapFetchIndexOperationResult result = operationService.createInvocationBuilder(MapService.SERVICE_NAME, operation, address).<MapFetchIndexOperationResult>invoke().get();
    assertResultSorted(result, Arrays.asList(new Person("person2", 39, "Dep1"), new Person("person5", 43, "Dep2"), new Person("person1", 45, "Dep1"), new Person("person4", 45, "Dep2"), new Person("person9", 45, "Dep3"), new Person("person10", 45, "Dep4"), new Person("person11", 45, "Dep5"), new Person("person3", 60, "Dep1"), new Person("person8", 79, null)));
}
Also used : Address(com.hazelcast.cluster.Address) IndexIterationPointer(com.hazelcast.internal.iteration.IndexIterationPointer) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) MapFetchIndexOperationResult(com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult) CompositeValue(com.hazelcast.query.impl.CompositeValue) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with CompositeValue

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

the class CompositeRangePredicateTest method testNoComparison.

@Test
public void testNoComparison() {
    assertEquals(0, map.getLocalMapStats().getIndexedQueryCount());
    for (int i = 0; i < 100; ++i) {
        final Integer age = randomQueryAge();
        final Long height = randomQueryHeight(true);
        int prefixLength = random.nextInt(2) + 1;
        final CompositeValue from;
        final CompositeValue to;
        final Predicate expected;
        switch(prefixLength) {
            case 1:
                from = value(age, NEGATIVE_INFINITY, NEGATIVE_INFINITY);
                to = value(age, POSITIVE_INFINITY, POSITIVE_INFINITY);
                expected = new Predicate<Integer, Person>() {

                    @Override
                    public boolean apply(Map.Entry<Integer, Person> mapEntry) {
                        return ObjectTestUtils.equals(mapEntry.getValue().age, age);
                    }
                };
                break;
            case 2:
                from = value(age, height, NEGATIVE_INFINITY);
                to = value(age, height, POSITIVE_INFINITY);
                expected = new Predicate<Integer, Person>() {

                    @Override
                    public boolean apply(Map.Entry<Integer, Person> mapEntry) {
                        return ObjectTestUtils.equals(mapEntry.getValue().age, age) && ObjectTestUtils.equals(mapEntry.getValue().height, height);
                    }
                };
                break;
            default:
                throw new IllegalStateException();
        }
        assertPredicate(expected, predicate(indexName, from, false, to, false, prefixLength, "age", "height", "__key"));
    }
    assertEquals(100, map.getLocalMapStats().getIndexedQueryCount());
}
Also used : Map(java.util.Map) IMap(com.hazelcast.map.IMap) CompositeValue(com.hazelcast.query.impl.CompositeValue) Predicate(com.hazelcast.query.Predicate) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

CompositeValue (com.hazelcast.query.impl.CompositeValue)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 IMap (com.hazelcast.map.IMap)2 Predicate (com.hazelcast.query.Predicate)2 Map (java.util.Map)2 Address (com.hazelcast.cluster.Address)1 IndexIterationPointer (com.hazelcast.internal.iteration.IndexIterationPointer)1 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)1 ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)1 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)1 MapFetchIndexOperationResult (com.hazelcast.map.impl.operation.MapFetchIndexOperation.MapFetchIndexOperationResult)1 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)1 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)1