Search in sources :

Example 81 with IndexConfig

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

the class SqlOrderByTest method checkSelectWithOrderBy.

protected void checkSelectWithOrderBy(List<String> indexAttrs, List<String> orderFields, List<Boolean> orderDirections) {
    IMap<Object, AbstractPojo> map = getTarget().getMap(mapName());
    IndexConfig indexConfig = new IndexConfig().setName("Index_" + randomName()).setType(SORTED);
    for (String indexAttr : indexAttrs) {
        indexConfig.addAttribute(indexAttr);
    }
    if (indexAttrs.size() > 0) {
        map.addIndex(indexConfig);
    }
    assertEquals(DATA_SET_SIZE, map.size());
    StringBuilder orders = new StringBuilder();
    for (int i = 0; i < orderFields.size(); ++i) {
        String orderField = orderFields.get(i);
        Boolean descending = orderDirections.get(i);
        orders.append(orderField);
        if (descending != null) {
            orders.append(descending ? " DESC " : " ASC ");
        }
        if (i < orderFields.size() - 1) {
            orders.append(", ");
        }
    }
    String sql = sqlWithOrderBy(orders.toString());
    assertSqlResultOrdered(sql, orderFields, orderDirections, map.size());
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) AbstractPojo(com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo)

Example 82 with IndexConfig

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

the class QueryCacheConfigHolder method of.

public static QueryCacheConfigHolder of(QueryCacheConfig config, SerializationService serializationService) {
    QueryCacheConfigHolder holder = new QueryCacheConfigHolder();
    holder.setBatchSize(config.getBatchSize());
    holder.setBufferSize(config.getBufferSize());
    holder.setCoalesce(config.isCoalesce());
    holder.setDelaySeconds(config.getDelaySeconds());
    holder.setEvictionConfigHolder(EvictionConfigHolder.of(config.getEvictionConfig(), serializationService));
    holder.setIncludeValue(config.isIncludeValue());
    holder.setInMemoryFormat(config.getInMemoryFormat().toString());
    holder.setName(config.getName());
    if (config.getIndexConfigs() != null && !config.getIndexConfigs().isEmpty()) {
        List<IndexConfig> indexConfigs = new ArrayList<>(config.getIndexConfigs().size());
        for (IndexConfig indexConfig : config.getIndexConfigs()) {
            indexConfigs.add(new IndexConfig(indexConfig));
        }
        holder.setIndexConfigs(indexConfigs);
    }
    if (config.getEntryListenerConfigs() != null && !config.getEntryListenerConfigs().isEmpty()) {
        List<ListenerConfigHolder> listenerConfigHolders = new ArrayList<>(config.getEntryListenerConfigs().size());
        for (EntryListenerConfig listenerConfig : config.getEntryListenerConfigs()) {
            listenerConfigHolders.add(ListenerConfigHolder.of(listenerConfig, serializationService));
        }
        holder.setListenerConfigs(listenerConfigHolders);
    }
    holder.setPredicateConfigHolder(PredicateConfigHolder.of(config.getPredicateConfig(), serializationService));
    holder.setPopulate(config.isPopulate());
    holder.setSerializeKeys(config.isSerializeKeys());
    return holder;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) ArrayList(java.util.ArrayList) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig)

Example 83 with IndexConfig

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

the class MapReplicationStateHolder method applyState.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:methodlength", "checkstyle:cyclomaticcomplexity", "checkstyle:nestedifdepth" })
void applyState() {
    ThreadUtil.assertRunningOnPartitionThread();
    applyIndexesState();
    if (!isNullOrEmpty(data)) {
        for (Map.Entry<String, List> dataEntry : data.entrySet()) {
            String mapName = dataEntry.getKey();
            List keyRecordExpiry = dataEntry.getValue();
            RecordStore recordStore = operation.getRecordStore(mapName);
            recordStore.beforeOperation();
            try {
                initializeRecordStore(mapName, recordStore);
                recordStore.setPreMigrationLoadedStatus(loaded.get(mapName));
                MapContainer mapContainer = recordStore.getMapContainer();
                PartitionContainer partitionContainer = recordStore.getMapContainer().getMapServiceContext().getPartitionContainer(operation.getPartitionId());
                for (Map.Entry<String, IndexConfig> indexDefinition : mapContainer.getIndexDefinitions().entrySet()) {
                    Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
                    indexes.addOrGetIndex(indexDefinition.getValue());
                }
                final Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
                final boolean populateIndexes = indexesMustBePopulated(indexes, operation);
                InternalIndex[] indexesSnapshot = null;
                if (populateIndexes) {
                    // defensively clear possible stale leftovers in non-global indexes from
                    // the previous failed promotion attempt
                    indexesSnapshot = indexes.getIndexes();
                    Indexes.beginPartitionUpdate(indexesSnapshot);
                    indexes.clearAll();
                }
                long nowInMillis = Clock.currentTimeMillis();
                forEachReplicatedRecord(keyRecordExpiry, mapContainer, recordStore, populateIndexes, nowInMillis);
                if (populateIndexes) {
                    Indexes.markPartitionAsIndexed(partitionContainer.getPartitionId(), indexesSnapshot);
                }
            } finally {
                recordStore.afterOperation();
            }
        }
    }
    for (Map.Entry<String, LocalRecordStoreStats> statsEntry : recordStoreStatsPerMapName.entrySet()) {
        String mapName = statsEntry.getKey();
        LocalRecordStoreStats stats = statsEntry.getValue();
        RecordStore recordStore = operation.getRecordStore(mapName);
        recordStore.setStats(stats);
    }
}
Also used : PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Indexes(com.hazelcast.query.impl.Indexes) MapContainer(com.hazelcast.map.impl.MapContainer) LocalRecordStoreStats(com.hazelcast.internal.monitor.LocalRecordStoreStats) InternalIndex(com.hazelcast.query.impl.InternalIndex) IndexConfig(com.hazelcast.config.IndexConfig) RecordStore(com.hazelcast.map.impl.recordstore.RecordStore) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 84 with IndexConfig

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

the class MapChunk method applyIndexStateBefore.

private void applyIndexStateBefore(RecordStore recordStore) {
    MapContainer mapContainer = recordStore.getMapContainer();
    PartitionContainer partitionContainer = mapContainer.getMapServiceContext().getPartitionContainer(getPartitionId());
    for (Map.Entry<String, IndexConfig> indexDefinition : mapContainer.getIndexDefinitions().entrySet()) {
        Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
        indexes.addOrGetIndex(indexDefinition.getValue());
    }
    Indexes indexes = mapContainer.getIndexes(partitionContainer.getPartitionId());
    boolean populateIndexes = indexesMustBePopulated(indexes);
    if (populateIndexes) {
        // defensively clear possible stale
        // leftovers in non-global indexes from
        // the previous failed promotion attempt
        Indexes.beginPartitionUpdate(indexes.getIndexes());
        indexes.clearAll();
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) Indexes(com.hazelcast.query.impl.Indexes) Map(java.util.Map) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) MapContainer(com.hazelcast.map.impl.MapContainer)

Example 85 with IndexConfig

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

the class IndexUtils method getIndexConfigFromXml.

public static IndexConfig getIndexConfigFromXml(Node indexNode, boolean domLevel3, boolean strict) {
    NamedNodeMap attrs = indexNode.getAttributes();
    String name = getTextContent(attrs.getNamedItem("name"), domLevel3);
    if (name.isEmpty()) {
        name = null;
    }
    String typeStr = getTextContent(attrs.getNamedItem("type"), domLevel3);
    IndexType type = getIndexTypeFromXmlName(typeStr);
    IndexConfig res = new IndexConfig().setName(name).setType(type);
    for (Node attributesNode : childElements(indexNode)) {
        if ("attributes".equals(cleanNodeName(attributesNode))) {
            for (Node attributeNode : childElements(attributesNode)) {
                if ("attribute".equals(cleanNodeName(attributeNode))) {
                    String attribute = getTextContent(attributeNode, domLevel3);
                    res.addAttribute(attribute);
                }
            }
        }
    }
    if (type == IndexType.BITMAP) {
        Node optionsNode = childElementWithName(indexNode, "bitmap-index-options", strict);
        if (optionsNode != null) {
            Node uniqueKeyNode = childElementWithName(optionsNode, "unique-key", strict);
            String uniqueKeyText = getTextContent(uniqueKeyNode, domLevel3);
            String uniqueKey = isNullOrEmpty(uniqueKeyText) ? BitmapIndexOptions.DEFAULT_UNIQUE_KEY : uniqueKeyText;
            Node uniqueKeyTransformationNode = childElementWithName(optionsNode, "unique-key-transformation", strict);
            String uniqueKeyTransformationText = getTextContent(uniqueKeyTransformationNode, domLevel3);
            UniqueKeyTransformation uniqueKeyTransformation = isNullOrEmpty(uniqueKeyTransformationText) ? BitmapIndexOptions.DEFAULT_UNIQUE_KEY_TRANSFORMATION : UniqueKeyTransformation.fromName(uniqueKeyTransformationText);
            res.getBitmapIndexOptions().setUniqueKey(uniqueKey);
            res.getBitmapIndexOptions().setUniqueKeyTransformation(uniqueKeyTransformation);
        }
    }
    return res;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IndexConfig(com.hazelcast.config.IndexConfig) Node(org.w3c.dom.Node) IndexType(com.hazelcast.config.IndexType) UniqueKeyTransformation(com.hazelcast.config.BitmapIndexOptions.UniqueKeyTransformation)

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