Search in sources :

Example 11 with IndexConfig

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

the class IndexUtils method generateXml.

public static void generateXml(ConfigXmlGenerator.XmlGenerator gen, List<IndexConfig> indexConfigs) {
    if (indexConfigs.isEmpty()) {
        return;
    }
    gen.open("indexes");
    for (IndexConfig indexCfg : indexConfigs) {
        if (indexCfg.getName() != null) {
            gen.open("index", "name", indexCfg.getName(), "type", indexCfg.getType().name());
        } else {
            gen.open("index", "type", indexCfg.getType().name());
        }
        gen.open("attributes");
        for (String attribute : indexCfg.getAttributes()) {
            gen.node("attribute", attribute);
        }
        gen.close();
        if (indexCfg.getType() == IndexType.BITMAP) {
            BitmapIndexOptions bitmapIndexOptions = indexCfg.getBitmapIndexOptions();
            gen.open("bitmap-index-options");
            gen.node("unique-key", bitmapIndexOptions.getUniqueKey());
            gen.node("unique-key-transformation", bitmapIndexOptions.getUniqueKeyTransformation());
            gen.close();
        }
        gen.close();
    }
    gen.close();
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) BitmapIndexOptions(com.hazelcast.config.BitmapIndexOptions)

Example 12 with IndexConfig

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

the class IndexUtils method createIndexConfig.

/**
 * Create simple index definition with the given attributes
 *
 * @param type Index type.
 * @param attributes Attribute names.
 * @return Index definition.
 */
public static IndexConfig createIndexConfig(IndexType type, String... attributes) {
    IndexConfig res = new IndexConfig();
    res.setType(type);
    checkNotNull(attributes, "Index attributes cannot be null.");
    for (String attribute : attributes) {
        res.addAttribute(attribute);
    }
    return res;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig)

Example 13 with IndexConfig

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

the class IndexUtils method buildNormalizedConfig.

private static IndexConfig buildNormalizedConfig(String mapName, IndexType indexType, String indexName, List<String> normalizedAttributeNames) {
    IndexConfig newConfig = new IndexConfig().setType(indexType);
    StringBuilder nameBuilder = indexName == null ? new StringBuilder(mapName + "_" + getIndexTypeName(indexType)) : null;
    for (String normalizedAttributeName : normalizedAttributeNames) {
        newConfig.addAttribute(normalizedAttributeName);
        if (nameBuilder != null) {
            nameBuilder.append("_").append(normalizedAttributeName);
        }
    }
    if (nameBuilder != null) {
        indexName = nameBuilder.toString();
    }
    newConfig.setName(indexName);
    return newConfig;
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig)

Example 14 with IndexConfig

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

the class MapIndexInfo method writeData.

@Override
public void writeData(ObjectDataOutput out) throws IOException {
    out.writeString(mapName);
    out.writeInt(indexConfigs.size());
    for (IndexConfig indexConfig : indexConfigs) {
        out.writeObject(indexConfig);
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig)

Example 15 with IndexConfig

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

the class MapTableUtils method getPartitionedMapIndexes.

public static List<MapTableIndex> getPartitionedMapIndexes(MapContainer mapContainer, List<TableField> fields) {
    Map<QueryPath, Integer> pathToOrdinalMap = mapPathsToOrdinals(fields);
    if (mapContainer.getIndexes() == null) {
        return Collections.emptyList();
    }
    InternalIndex[] indexes = mapContainer.getIndexes().getIndexes();
    if (indexes == null || indexes.length == 0) {
        return Collections.emptyList();
    }
    List<MapTableIndex> res = new ArrayList<>(indexes.length);
    for (Index index : indexes) {
        IndexConfig indexConfig = index.getConfig();
        List<QueryDataType> resolvedFieldConverterTypes = indexConverterToSqlTypes(index.getConverter());
        List<String> indexAttributes = indexConfig.getAttributes();
        List<Integer> indexFieldOrdinals = new ArrayList<>(indexAttributes.size());
        List<QueryDataType> indexFieldConverterTypes = new ArrayList<>(indexAttributes.size());
        String[] components = index.getComponents();
        for (int i = 0; i < indexAttributes.size(); i++) {
            String attribute = indexAttributes.get(i);
            QueryPath attributePath = QueryPath.create(attribute);
            Integer ordinal = pathToOrdinalMap.get(attributePath);
            if (ordinal == null) {
                // No mapping for the field. Stop.
                break;
            }
            if (i >= resolvedFieldConverterTypes.size()) {
                // No more resolved converters. Stop.
                break;
            }
            QueryDataType fieldType = fields.get(ordinal).getType();
            QueryDataType converterType = resolvedFieldConverterTypes.get(i);
            if (!isCompatibleForIndexRequest(fieldType, converterType)) {
                // Field and converter types are not compatible (e.g. INT vs VARCHAR).
                break;
            }
            indexFieldOrdinals.add(ordinal);
            indexFieldConverterTypes.add(converterType);
        }
        MapTableIndex index0 = new MapTableIndex(indexConfig.getName(), indexConfig.getType(), components.length, indexFieldOrdinals, indexFieldConverterTypes);
        res.add(index0);
    }
    return res;
}
Also used : QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ArrayList(java.util.ArrayList) InternalIndex(com.hazelcast.query.impl.InternalIndex) Index(com.hazelcast.query.impl.Index) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) InternalIndex(com.hazelcast.query.impl.InternalIndex) 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