Search in sources :

Example 71 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class IndexEqualsFilterIterationTest method checkIteratorSimple.

private void checkIteratorSimple(IndexType indexType) {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(indexType).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(1)).getEntries(index, descendingDirection, evalContext));
    // Check single value.
    map.put(1, new Value(1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(1)).getEntries(index, descendingDirection, evalContext), 1);
    // Check multiple values.
    map.put(2, new Value(1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(1)).getEntries(index, descendingDirection, evalContext), 1, 2);
    // Check null value.
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, true)).getEntries(index, descendingDirection, evalContext));
    map.put(3, new Value(null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, true)).getEntries(index, descendingDirection, evalContext), 3);
    map.put(4, new Value(null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValue(null, true)).getEntries(index, descendingDirection, evalContext), 3, 4);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalIndex(com.hazelcast.query.impl.InternalIndex) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig)

Example 72 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class IndexEqualsFilterIterationTest method checkIteratorComposite.

private void checkIteratorComposite(IndexType indexType) {
    HazelcastInstance instance = factory.newHazelcastInstance();
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(indexType).addAttribute("value1").addAttribute("value2"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext));
    map.put(1, new Value(1, 1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext));
    map.put(2, new Value(2, 1));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext));
    // Check single value.
    map.put(3, new Value(1, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext), 3);
    // Check multiple values.
    map.put(4, new Value(1, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, 2)).getEntries(index, descendingDirection, evalContext), 3, 4);
    // Check null values (first).
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, 2, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, 2, false)).getEntries(index, descendingDirection, evalContext));
    map.put(5, new Value(null, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, 2, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, 2, false)).getEntries(index, descendingDirection, evalContext), 5);
    map.put(6, new Value(null, 2));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, 2, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, 2, false)).getEntries(index, descendingDirection, evalContext), 5, 6);
    // Check null values (last).
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, true)).getEntries(index, descendingDirection, evalContext));
    map.put(7, new Value(1, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, true)).getEntries(index, descendingDirection, evalContext), 7);
    map.put(8, new Value(1, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(1, false, null, true)).getEntries(index, descendingDirection, evalContext), 7, 8);
    // Check null values (both).
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, true)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, true)).getEntries(index, descendingDirection, evalContext));
    map.put(9, new Value(null, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, true)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, true)).getEntries(index, descendingDirection, evalContext), 9);
    map.put(10, new Value(null, null));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, false, null, true)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, false)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, new IndexEqualsFilter(intValues(null, true, null, true)).getEntries(index, descendingDirection, evalContext), 9, 10);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalIndex(com.hazelcast.query.impl.InternalIndex) IndexEqualsFilter(com.hazelcast.sql.impl.exec.scan.index.IndexEqualsFilter) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig)

Example 73 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class IndexRangeFilterIteratorTest method testIterator_composite.

/**
 * Test composite iterator. Note that parent components are always the same, therefore we do not test open bounds.
 */
@Test
public void testIterator_composite() {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1").addAttribute("value2"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    map.put(0, new Value(0, 0));
    map.put(1, new Value(0, 1));
    map.put(3, new Value(0, 3));
    map.put(4, new Value(0, 5));
    map.put(5, new Value(0, 6));
    map.put(6, new Value(2, 0));
    map.put(7, new Value(2, 1));
    map.put(8, new Value(2, 3));
    map.put(9, new Value(2, 5));
    map.put(10, new Value(2, 6));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext));
    map.put(11, new Value(1, 1));
    map.put(12, new Value(1, 1));
    map.put(13, new Value(1, 3));
    map.put(14, new Value(1, 3));
    map.put(15, new Value(1, 5));
    map.put(16, new Value(1, 5));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext), 13, 14);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), false, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext), 13, 14, 15, 16);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), false).getEntries(index, descendingDirection, evalContext), 11, 12, 13, 14);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValues(1, 1), true, intValues(1, 5), true).getEntries(index, descendingDirection, evalContext), 11, 12, 13, 14, 15, 16);
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class IndexRangeFilterIteratorTest method testIterator_simple_from.

@Test
public void testIterator_simple_from() {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    map.put(0, new Value(0));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, null, false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, null, false).getEntries(index, descendingDirection, evalContext));
    // Check single value.
    map.put(1, new Value(1));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, null, false).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, null, false).getEntries(index, descendingDirection, evalContext));
    // Check multiple values.
    map.put(2, new Value(1));
    map.put(3, new Value(2));
    map.put(4, new Value(2));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), true, null, false).getEntries(index, descendingDirection, evalContext), 1, 2, 3, 4);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(1), false, null, false).getEntries(index, descendingDirection, evalContext), 3, 4);
    // Check null value.
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), true, null, false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(intValue(null, false), false, null, false).getEntries(index, descendingDirection, evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 75 with IndexConfig

use of com.hazelcast.config.IndexConfig in project hazelcast by hazelcast.

the class IndexRangeFilterIteratorTest method testIterator_simple_to.

@Test
public void testIterator_simple_to() {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    IMap<Integer, Value> map = instance.getMap(MAP_NAME);
    map.addIndex(new IndexConfig().setName(INDEX_NAME).setType(SORTED).addAttribute("value1"));
    InternalIndex index = getIndex(instance);
    ExpressionEvalContext evalContext = createExpressionEvalContext();
    // Check missing value.
    map.put(0, new Value(10));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), true).getEntries(index, descendingDirection, evalContext));
    // Check single value.
    map.put(1, new Value(2));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), true).getEntries(index, descendingDirection, evalContext), 1);
    // Check multiple values.
    map.put(2, new Value(2));
    map.put(3, new Value(1));
    map.put(4, new Value(1));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), false).getEntries(index, descendingDirection, evalContext), 3, 4);
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(2), true).getEntries(index, descendingDirection, evalContext), 1, 2, 3, 4);
    // Check null value.
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(null, false), false).getEntries(index, descendingDirection, evalContext));
    checkIterator(SORTED, descendingDirection, new IndexRangeFilter(null, false, intValue(null, false), true).getEntries(index, descendingDirection, evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) IndexRangeFilter(com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IndexConfig (com.hazelcast.config.IndexConfig)130 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)45 Config (com.hazelcast.config.Config)42 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)38 MapConfig (com.hazelcast.config.MapConfig)34 HazelcastInstance (com.hazelcast.core.HazelcastInstance)29 ArrayList (java.util.ArrayList)16 Before (org.junit.Before)13 MapStoreConfig (com.hazelcast.config.MapStoreConfig)12 InternalIndex (com.hazelcast.query.impl.InternalIndex)12 AttributeConfig (com.hazelcast.config.AttributeConfig)9 MapContainer (com.hazelcast.map.impl.MapContainer)9 IndexRangeFilter (com.hazelcast.sql.impl.exec.scan.index.IndexRangeFilter)9 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)8 Node (org.w3c.dom.Node)8 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)7 IMap (com.hazelcast.map.IMap)7 Indexes (com.hazelcast.query.impl.Indexes)7 ExpressionEvalContext (com.hazelcast.sql.impl.expression.ExpressionEvalContext)7