Example usage for org.apache.cassandra.cql3.statements SelectStatement.RawStatement keyspace

List of usage examples for org.apache.cassandra.cql3.statements SelectStatement.RawStatement keyspace

Introduction

In this page you can find the example usage for org.apache.cassandra.cql3.statements SelectStatement.RawStatement keyspace.

Prototype

public String keyspace() 

Source Link

Usage

From source file:com.protectwise.cassandra.retrospect.deletion.RuleBasedDeletionConvictor.java

License:Apache License

/**
 * Called by {{{DeletingCompactionStrategy.validateOptions}}} to allow the convictor to
 * read and validate convictor-specific options at the same time.
 * <p/>//from   ww  w. j ava 2 s  .  co  m
 * See {@link org.apache.cassandra.db.compaction.AbstractCompactionStrategy#validateOptions(Map)}
 *
 * @param options
 * @return
 */
public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException {
    String select = options.get(RULES_STATEMENT_KEY);
    if (select == null) {
        throw new ConfigurationException(RULES_STATEMENT_KEY + " is a required parameter");
    }
    try {
        ParsedStatement stmt = QueryProcessor.parseStatement(select);
        if (!(stmt instanceof SelectStatement.RawStatement)) {
            throw new ConfigurationException(RULES_STATEMENT_KEY + " must be a SELECT statement");
        }
        SelectStatement.RawStatement sel = (SelectStatement.RawStatement) stmt;

        try {
            sel.keyspace();
        } catch (AssertionError e) {
            throw new ConfigurationException(
                    RULES_STATEMENT_KEY + " must define a fully qualified keyspace.tablename");
        }

        // This will validate that the data types of the columns in the select are correct.
        parseRules(select);
    } catch (SyntaxException e) {
        throw new ConfigurationException("Invalid select statement: " + e.getMessage(), e);
    }

    options.remove(RULES_STATEMENT_KEY);
    return options;
}

From source file:com.protectwise.cassandra.retrospect.deletion.RuleBasedLateTTLConvictor.java

License:Apache License

/**
 * Called by {{{DeletingCompactionStrategy.validateOptions}}} to allow the convictor to
 * read and validate convictor-specific options at the same time.
 * <p/>//  w w w  .j  av a  2s .c o  m
 * See {@link org.apache.cassandra.db.compaction.AbstractCompactionStrategy#validateOptions(Map)}
 *
 * @param options
 * @return
 */
public static Map<String, String> validateOptions(Map<String, String> options) throws ConfigurationException {
    String select = options.get(RULES_STATEMENT_KEY);
    if (select == null) {
        throw new ConfigurationException(RULES_STATEMENT_KEY + " is a required parameter");
    }
    try {
        ParsedStatement stmt = QueryProcessor.parseStatement(select);
        if (!(stmt instanceof SelectStatement.RawStatement)) {
            throw new ConfigurationException(RULES_STATEMENT_KEY + " must be a SELECT statement");
        }
        SelectStatement.RawStatement sel = (SelectStatement.RawStatement) stmt;

        try {
            sel.keyspace();
        } catch (AssertionError e) {
            throw new ConfigurationException(
                    RULES_STATEMENT_KEY + " must define a fully qualified keyspace.tablename");
        }

        // This will validate that the data types of the columns in the select are correct.
        parseRules(select);
    } catch (SyntaxException e) {
        throw new ConfigurationException("Invalid select statement: " + e.getMessage(), e);
    }

    String defaultTTL = options.get(DEFAULT_TTL_KEY);
    if (defaultTTL != null) {
        try {
            Long.parseLong(defaultTTL);
        } catch (NumberFormatException e) {
            throw new ConfigurationException(
                    "Invalid value '" + options.get(DEFAULT_TTL_KEY) + "' for " + DEFAULT_TTL_KEY, e);
        }
    }

    options.remove(DEFAULT_TTL_KEY);
    options.remove(RULES_STATEMENT_KEY);
    return options;
}