Search in sources :

Example 16 with IndexConfig

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

the class ClientAggregatorsSpecTest method getMapWithNodeCount.

@Override
protected <K, V> IMap<K, V> getMapWithNodeCount(int nodeCount, boolean parallelAccumulation, boolean useIndex) {
    if (nodeCount < 1) {
        throw new IllegalArgumentException("node count < 1");
    }
    MapConfig mapConfig = new MapConfig().setName("aggr").setInMemoryFormat(inMemoryFormat);
    if (useIndex) {
        mapConfig.addIndexConfig(new IndexConfig(IndexConfig.DEFAULT_TYPE, "fieldWeCanQuery"));
    }
    Config config = new Config().setProperty(PARTITION_COUNT.getName(), String.valueOf(nodeCount)).setProperty(AGGREGATION_ACCUMULATION_PARALLEL_EVALUATION.getName(), String.valueOf(parallelAccumulation)).addMapConfig(mapConfig);
    factory = new TestHazelcastFactory();
    for (int i = 0; i < nodeCount; i++) {
        factory.newHazelcastInstance(config);
    }
    HazelcastInstance instance = factory.newHazelcastClient();
    return instance.getMap("aggr");
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) MapConfig(com.hazelcast.config.MapConfig)

Example 17 with IndexConfig

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

the class YamlMemberDomConfigProcessor method mapIndexesHandle.

@Override
protected void mapIndexesHandle(Node n, MapConfig mapConfig) {
    for (Node indexNode : childElements(n)) {
        IndexConfig indexConfig = IndexUtils.getIndexConfigFromYaml(indexNode, domLevel3, strict);
        mapConfig.addIndexConfig(indexConfig);
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) Node(org.w3c.dom.Node) YamlNode(com.hazelcast.internal.yaml.YamlNode)

Example 18 with IndexConfig

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

the class DynamicConfigYamlGenerator method getIndexConfigsAsList.

private static List<Map<String, Object>> getIndexConfigsAsList(List<IndexConfig> indexConfigs) {
    if (indexConfigs == null || indexConfigs.isEmpty()) {
        return null;
    }
    List<Map<String, Object>> indexConfigsAsList = new LinkedList<>();
    for (IndexConfig indexConfig : indexConfigs) {
        Map<String, Object> indexConfigAsMap = new LinkedHashMap<>();
        addNonNullToMap(indexConfigAsMap, "name", indexConfig.getName());
        addNonNullToMap(indexConfigAsMap, "type", indexConfig.getType().name());
        addNonNullToMap(indexConfigAsMap, "attributes", indexConfig.getAttributes());
        if (indexConfig.getType() == IndexType.BITMAP) {
            Map<String, Object> bitmapIndexOptionsAsMap = new LinkedHashMap<>();
            addNonNullToMap(bitmapIndexOptionsAsMap, "unique-key", indexConfig.getBitmapIndexOptions().getUniqueKey());
            addNonNullToMap(bitmapIndexOptionsAsMap, "unique-key-transformation", indexConfig.getBitmapIndexOptions().getUniqueKeyTransformation().name());
            indexConfigAsMap.put("bitmap-index-options", bitmapIndexOptionsAsMap);
        }
        addNonNullToList(indexConfigsAsList, indexConfigAsMap);
    }
    return indexConfigsAsList;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with IndexConfig

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

the class SqlSplitBrainTest method test_indexScan.

@Test
public // test for https://github.com/hazelcast/hazelcast/issues/19472
void test_indexScan() throws InterruptedException {
    Thread[] threads = new Thread[2];
    AtomicBoolean done = new AtomicBoolean();
    AtomicInteger numQueries = new AtomicInteger();
    Consumer<HazelcastInstance[]> beforeSplit = instances -> {
        IMap<Integer, Integer> m = instances[0].getMap("m");
        for (int i = 0; i < 10_000; i++) {
            m.put(i, i);
        }
        m.addIndex(new IndexConfig().addAttribute("this"));
        SqlTestSupport.createMapping(instances[0], "m", Integer.class, Integer.class);
        for (int i = 0, threadsLength = threads.length; i < threadsLength; i++) {
            HazelcastInstance inst = createHazelcastClient();
            threads[i] = new Thread(() -> {
                int numQueriesLocal = 0;
                while (!done.get()) {
                    try {
                        // noinspection StatementWithEmptyBody
                        for (SqlRow ignored : inst.getSql().execute("select * from m where this>100 and this<1000")) {
                        // do nothing
                        }
                    } catch (Throwable e) {
                        logger.info(e);
                    }
                    numQueriesLocal++;
                }
                numQueries.addAndGet(numQueriesLocal);
            });
            threads[i].start();
            sleepSeconds(1);
        }
    };
    testSplitBrain(1, 1, beforeSplit, null, null);
    done.set(true);
    boolean stuck = false;
    for (Thread t : threads) {
        t.join(5000);
        if (t.isAlive()) {
            logger.info("thread " + t + " stuck");
            stuck = true;
        }
    }
    logger.info("num queries executed: " + numQueries.get());
    if (stuck) {
        fail("some threads were stuck");
    }
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) RunWith(org.junit.runner.RunWith) MAX_BACKUP_COUNT(com.hazelcast.internal.partition.IPartition.MAX_BACKUP_COUNT) SqlTestSupport(com.hazelcast.jet.sql.SqlTestSupport) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) IndexConfig(com.hazelcast.config.IndexConfig) Consumer(java.util.function.Consumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JetSplitBrainTestSupport(com.hazelcast.jet.core.JetSplitBrainTestSupport) Assert.fail(org.junit.Assert.fail) SqlRow(com.hazelcast.sql.SqlRow) IMap(com.hazelcast.map.IMap) SqlRow(com.hazelcast.sql.SqlRow) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMap(com.hazelcast.map.IMap) IndexConfig(com.hazelcast.config.IndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 20 with IndexConfig

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

the class IndexInFilterIterationTest method check.

private void check(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();
    map.put(1, new Value(null));
    map.put(2, new Value(0));
    map.put(3, new Value(1));
    // No values from both filters
    checkIterator(indexType, descendingDirection, in(equals(2), equals(3)).getEntries(index, descendingDirection, evalContext));
    checkIterator(indexType, descendingDirection, in(equals(3), equals(2)).getEntries(index, descendingDirection, evalContext));
    // No values from one filter
    checkIterator(indexType, descendingDirection, in(equals(1), equals(2)).getEntries(index, descendingDirection, evalContext), 3);
    checkIterator(indexType, descendingDirection, in(equals(2), equals(1)).getEntries(index, descendingDirection, evalContext), 3);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(2)).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(indexType, descendingDirection, in(equals(2), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    // Values from both filters
    checkIterator(indexType, descendingDirection, in(equals(0), equals(1)).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(indexType, descendingDirection, in(equals(1), equals(0)).getEntries(index, descendingDirection, evalContext), 2, 3);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(0)).getEntries(index, descendingDirection, evalContext), 1, 2);
    checkIterator(indexType, descendingDirection, in(equals(0), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1, 2);
    // One distinct value
    checkIterator(indexType, descendingDirection, in(equals(0), equals(0)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    // One null value
    checkIterator(indexType, descendingDirection, in(equals(0), equals(null, false)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(0)).getEntries(index, descendingDirection, evalContext), 2);
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(null, true)).getEntries(index, descendingDirection, evalContext), 1);
    checkIterator(indexType, descendingDirection, in(equals(null, true), equals(null, false)).getEntries(index, descendingDirection, evalContext), 1);
    // Two null values
    checkIterator(indexType, descendingDirection, in(equals(null, false), equals(null, false)).getEntries(index, descendingDirection, evalContext));
}
Also used : ExpressionEvalContext(com.hazelcast.sql.impl.expression.ExpressionEvalContext) InternalIndex(com.hazelcast.query.impl.InternalIndex) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IndexConfig(com.hazelcast.config.IndexConfig)

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