Java 类com.datastax.driver.core.exceptions.QueryValidationException 实例源码

项目:storm-cassandra-cql    文件:CassandraCqlMapState.java   
protected void checkCassandraException(Exception e) {
    _mexceptions.incr();
    if (e instanceof AlreadyExistsException ||
            e instanceof AuthenticationException ||
            e instanceof DriverException ||
            e instanceof DriverInternalError ||
            e instanceof InvalidConfigurationInQueryException ||
            e instanceof InvalidQueryException ||
            e instanceof InvalidTypeException ||
            e instanceof QueryExecutionException ||
            e instanceof QueryTimeoutException ||
            e instanceof QueryValidationException ||
            e instanceof ReadTimeoutException ||
            e instanceof SyntaxError ||
            e instanceof TraceRetrievalException ||
            e instanceof TruncateException ||
            e instanceof UnauthorizedException ||
            e instanceof UnavailableException ||
            e instanceof ReadTimeoutException ||
            e instanceof WriteTimeoutException) {
        throw new ReportedFailedException(e);
    } else {
        throw new RuntimeException(e);
    }
}
项目:scylla-tools-java    文件:CustomIndexTest.java   
@Test
public void customExpressionsDisallowedInModifications() throws Throwable
{
    createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))");
    String indexName = currentTable() + "_custom_index";
    createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'",
                              indexName, StubIndex.class.getName()));

    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              ModificationStatement.CUSTOM_EXPRESSIONS_NOT_ALLOWED,
                              QueryValidationException.class,
                              String.format("DELETE FROM %%s WHERE expr(%s, 'foo bar baz ')", indexName));
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              ModificationStatement.CUSTOM_EXPRESSIONS_NOT_ALLOWED,
                              QueryValidationException.class,
                              String.format("UPDATE %%s SET d=0 WHERE expr(%s, 'foo bar baz ')", indexName));
}
项目:scylla-tools-java    文件:CustomIndexTest.java   
@Test
public void testCustomExpressionValueType() throws Throwable
{
    // verify that the type of the expression value is determined by Index::customExpressionValueType
    createTable("CREATE TABLE %s (k int, v1 uuid, v2 blob, PRIMARY KEY(k))");
    createIndex(String.format("CREATE CUSTOM INDEX int_index ON %%s() USING '%s'",
                              Int32ExpressionIndex.class.getName()));
    createIndex(String.format("CREATE CUSTOM INDEX text_index ON %%s() USING '%s'",
                              UTF8ExpressionIndex.class.getName()));

    execute("SELECT * FROM %s WHERE expr(text_index, 'foo')");
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              "Invalid INTEGER constant (99) for \"custom index expression\" of type text",
                              QueryValidationException.class,
                              "SELECT * FROM %s WHERE expr(text_index, 99)");

    execute("SELECT * FROM %s WHERE expr(int_index, 99)");
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              "Invalid STRING constant (foo) for \"custom index expression\" of type int",
                              QueryValidationException.class,
                              "SELECT * FROM %s WHERE expr(int_index, 'foo')");
}
项目:cassandra-loader    文件:CqlDelimUnload.java   
private boolean setup() throws IOException, ParseException {
    cdp = new CqlDelimParser(cqlSchema, delimiter, 4096, nullString, 
                             null, dateFormatString, localDateFormatString,
                             boolStyle, locale, null, session, false, -1);
    String select = cdp.generateSelect();
    String partitionKey = getPartitionKey(cdp, session);
    if (null != beginToken) {
        select = select + " WHERE Token(" + partitionKey + ") > " 
            + beginToken + " AND Token(" + partitionKey + ") <= " 
            + endToken;
        if (null != where)
            select = select + " AND " + where;
    }
    else {
        if (null != where)
            select = select + " WHERE " + where;
    }
    try {
        statement = session.prepare(select);
    }
    catch (QueryValidationException iqe) {
        System.err.println("Error creating statement: " + iqe.getMessage());
        System.err.println("CQL Query: " + select);
        if (null != where)
            System.err.println("Check your syntax for -where: " + where);
        return false;
    }
    statement.setConsistencyLevel(consistencyLevel);
    return true;
}
项目:scylla-tools-java    文件:CustomIndexTest.java   
@Test
public void customIndexDoesntSupportCustomExpressions() throws Throwable
{
    createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))");
    String indexName = currentTable() + "_custom_index";
    createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'",
                              indexName,
                              NoCustomExpressionsIndex.class.getName()));
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              String.format( IndexRestrictions.CUSTOM_EXPRESSION_NOT_SUPPORTED, indexName),
                              QueryValidationException.class,
                              String.format("SELECT * FROM %%s WHERE expr(%s, 'foo bar baz')", indexName));
}
项目:scylla-tools-java    文件:CustomIndexTest.java   
@Test
public void customIndexRejectsExpressionSyntax() throws Throwable
{
    createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))");
    String indexName = currentTable() + "_custom_index";
    createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'",
                              indexName,
                              AlwaysRejectIndex.class.getName()));
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              "None shall pass",
                              QueryValidationException.class,
                              String.format("SELECT * FROM %%s WHERE expr(%s, 'foo bar baz')", indexName));
}
项目:scylla-tools-java    文件:CustomIndexTest.java   
@Test
public void customExpressionsMustTargetCustomIndex() throws Throwable
{
    createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))");
    createIndex("CREATE INDEX non_custom_index ON %s(c)");
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              String.format(IndexRestrictions.NON_CUSTOM_INDEX_IN_EXPRESSION, "non_custom_index"),
                              QueryValidationException.class,
                              "SELECT * FROM %s WHERE expr(non_custom_index, 'c=0')");
}
项目:scylla-tools-java    文件:CustomIndexTest.java   
@Test
public void testCustomIndexExpressionSyntax() throws Throwable
{
    Object[] row = row(0, 0, 0, 0);
    createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY (a, b))");
    String indexName = currentTable() + "_custom_index";
    execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", row);


    assertInvalidMessage(String.format(IndexRestrictions.INDEX_NOT_FOUND, indexName, keyspace(), currentTable()),
                         String.format("SELECT * FROM %%s WHERE expr(%s, 'foo bar baz')", indexName));

    createIndex(String.format("CREATE CUSTOM INDEX %s ON %%s(c) USING '%s'", indexName, StubIndex.class.getName()));

    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              String.format(IndexRestrictions.INDEX_NOT_FOUND, "no_such_index", keyspace(), currentTable()),
                              QueryValidationException.class,
                              "SELECT * FROM %s WHERE expr(no_such_index, 'foo bar baz ')");

    // simple case
    assertRows(execute(String.format("SELECT * FROM %%s WHERE expr(%s, 'foo bar baz')", indexName)), row);
    assertRows(execute(String.format("SELECT * FROM %%s WHERE expr(\"%s\", 'foo bar baz')", indexName)), row);
    assertRows(execute(String.format("SELECT * FROM %%s WHERE expr(%s, $$foo \" ~~~ bar Baz$$)", indexName)), row);

    // multiple expressions on the same index
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              IndexRestrictions.MULTIPLE_EXPRESSIONS,
                              QueryValidationException.class,
                              String.format("SELECT * FROM %%s WHERE expr(%1$s, 'foo') AND expr(%1$s, 'bar')",
                                            indexName));

    // multiple expressions on different indexes
    createIndex(String.format("CREATE CUSTOM INDEX other_custom_index ON %%s(d) USING '%s'", StubIndex.class.getName()));
    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              IndexRestrictions.MULTIPLE_EXPRESSIONS,
                              QueryValidationException.class,
                              String.format("SELECT * FROM %%s WHERE expr(%s, 'foo') AND expr(other_custom_index, 'bar')",
                                            indexName));

    assertInvalidThrowMessage(Server.CURRENT_VERSION,
                              StatementRestrictions.REQUIRES_ALLOW_FILTERING_MESSAGE,
                              QueryValidationException.class,
                              String.format("SELECT * FROM %%s WHERE expr(%s, 'foo') AND d=0", indexName));
    assertRows(execute(String.format("SELECT * FROM %%s WHERE expr(%s, 'foo') AND d=0 ALLOW FILTERING", indexName)), row);
}