Search in sources :

Example 1 with UTF8Type

use of org.apache.cassandra.db.marshal.UTF8Type in project cassandra by apache.

the class IndexMode method getMode.

public static IndexMode getMode(ColumnMetadata column, Map<String, String> indexOptions) throws ConfigurationException {
    if (indexOptions == null || indexOptions.isEmpty())
        return IndexMode.NOT_INDEXED;
    Mode mode;
    try {
        mode = indexOptions.get(INDEX_MODE_OPTION) == null ? Mode.PREFIX : Mode.mode(indexOptions.get(INDEX_MODE_OPTION));
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException("Incorrect index mode: " + indexOptions.get(INDEX_MODE_OPTION));
    }
    boolean isAnalyzed = false;
    Class analyzerClass = null;
    try {
        if (indexOptions.get(INDEX_ANALYZER_CLASS_OPTION) != null) {
            analyzerClass = Class.forName(indexOptions.get(INDEX_ANALYZER_CLASS_OPTION));
            isAnalyzed = indexOptions.get(INDEX_ANALYZED_OPTION) == null ? true : Boolean.parseBoolean(indexOptions.get(INDEX_ANALYZED_OPTION));
        } else if (indexOptions.get(INDEX_ANALYZED_OPTION) != null) {
            isAnalyzed = Boolean.parseBoolean(indexOptions.get(INDEX_ANALYZED_OPTION));
        }
    } catch (ClassNotFoundException e) {
        // should not happen as we already validated we could instantiate an instance in validateAnalyzer()
        logger.error("Failed to find specified analyzer class [{}]. Falling back to default analyzer", indexOptions.get(INDEX_ANALYZER_CLASS_OPTION));
    }
    boolean isLiteral = false;
    try {
        String literalOption = indexOptions.get(INDEX_IS_LITERAL_OPTION);
        AbstractType<?> validator = column.cellValueType();
        isLiteral = literalOption == null ? (validator instanceof UTF8Type || validator instanceof AsciiType) : Boolean.parseBoolean(literalOption);
    } catch (Exception e) {
        logger.error("failed to parse {} option, defaulting to 'false'.", INDEX_IS_LITERAL_OPTION);
    }
    Long maxMemMb = indexOptions.get(INDEX_MAX_FLUSH_MEMORY_OPTION) == null ? // 1G default for memtable
    (long) (1073741824 * INDEX_MAX_FLUSH_DEFAULT_MULTIPLIER) : Long.parseLong(indexOptions.get(INDEX_MAX_FLUSH_MEMORY_OPTION));
    return new IndexMode(mode, isLiteral, isAnalyzed, analyzerClass, maxMemMb);
}
Also used : Mode(org.apache.cassandra.index.sasi.disk.OnDiskIndexBuilder.Mode) AsciiType(org.apache.cassandra.db.marshal.AsciiType) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Aggregations

AsciiType (org.apache.cassandra.db.marshal.AsciiType)1 UTF8Type (org.apache.cassandra.db.marshal.UTF8Type)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 Mode (org.apache.cassandra.index.sasi.disk.OnDiskIndexBuilder.Mode)1