Search in sources :

Example 36 with SimpleStatement

use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.

the class SASICQLTest method testPagingWithClustering.

@Test
public void testPagingWithClustering() throws Throwable {
    for (boolean forceFlush : new boolean[] { false, true }) {
        createTable("CREATE TABLE %s (pk int, ck int, v int, PRIMARY KEY (pk, ck));");
        createIndex("CREATE CUSTOM INDEX ON %s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex';");
        for (int i = 0; i < 10; i++) {
            execute("INSERT INTO %s (pk, ck, v) VALUES (?, ?, ?);", i, 1, 1);
            execute("INSERT INTO %s (pk, ck, v) VALUES (?, ?, ?);", i, 2, 1);
        }
        flush(forceFlush);
        Session session = sessionNet();
        SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v = 1");
        stmt.setFetchSize(5);
        List<Row> rs = session.execute(stmt).all();
        Assert.assertEquals(20, rs.size());
    }
}
Also used : SimpleStatement(com.datastax.driver.core.SimpleStatement) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 37 with SimpleStatement

use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.

the class SASICQLTest method testIntCompare.

@Test
public void testIntCompare() throws Throwable {
    for (String mode : new String[] { "PREFIX", "CONTAINS", "SPARSE" }) {
        for (boolean forceFlush : new boolean[] { false, true }) {
            try {
                createTable("CREATE TABLE %s (pk int primary key, v int);");
                createIndex(String.format("CREATE CUSTOM INDEX ON %%s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'mode': '%s'};", mode));
                execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 0, 100);
                execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 1, 200);
                execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 2, 300);
                flush(forceFlush);
                Session session = sessionNet();
                SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v > 200");
                stmt.setFetchSize(5);
                List<Row> rs = session.execute(stmt).all();
                Assert.assertFalse("CONTAINS mode on non-literal int type should not support RANGE operators", "CONTAINS".equals(mode));
                Assert.assertEquals(1, rs.size());
                Assert.assertEquals(2, rs.get(0).getInt("pk"));
            } catch (InvalidQueryException ex) {
                if (!"CONTAINS".equals(mode))
                    throw ex;
            } catch (Throwable th) {
                throw new AssertionError(String.format("Failure with mode:%s and flush:%s ", mode, forceFlush), th);
            }
        }
    }
}
Also used : SimpleStatement(com.datastax.driver.core.SimpleStatement) Row(com.datastax.driver.core.Row) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 38 with SimpleStatement

use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.

the class SASICQLTest method testStringCompare.

/**
 * Tests query condition '>' on string columns with is_literal=true (default).
 */
@Test
public void testStringCompare() throws Throwable {
    for (String mode : new String[] { "PREFIX", "CONTAINS" }) {
        for (boolean forceFlush : new boolean[] { false, true }) {
            try {
                createTable("CREATE TABLE %s (pk int primary key, v text);");
                createIndex(String.format("CREATE CUSTOM INDEX ON %%s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {'mode': '%s'};", mode));
                execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 0, "a");
                execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 1, "abc");
                execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 2, "ac");
                flush(forceFlush);
                Session session = sessionNet();
                SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v = 'ab'");
                stmt.setFetchSize(5);
                List<Row> rs = session.execute(stmt).all();
                Assert.assertEquals(0, rs.size());
                try {
                    session = sessionNet();
                    stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v > 'ab'");
                    stmt.setFetchSize(5);
                    rs = session.execute(stmt).all();
                    throw new AssertionError("literal string type should not support RANGE operators");
                } catch (InvalidQueryException ex) {
                }
            } catch (Throwable th) {
                throw new AssertionError(String.format("Failure with mode:%s and flush:%s ", mode, forceFlush), th);
            }
        }
    }
}
Also used : SimpleStatement(com.datastax.driver.core.SimpleStatement) Row(com.datastax.driver.core.Row) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

SimpleStatement (com.datastax.driver.core.SimpleStatement)38 ResultSet (com.datastax.driver.core.ResultSet)17 Row (com.datastax.driver.core.Row)17 Test (org.junit.Test)15 Session (com.datastax.driver.core.Session)13 Statement (com.datastax.driver.core.Statement)10 ArrayList (java.util.ArrayList)10 CassandraResultSet (org.apache.gora.cassandra.query.CassandraResultSet)7 GoraException (org.apache.gora.util.GoraException)7 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)6 ByteBuffer (java.nio.ByteBuffer)5 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)4 AbstractGettableData (com.datastax.driver.core.AbstractGettableData)3 BatchStatement (com.datastax.driver.core.BatchStatement)2 ConsistencyLevel (com.datastax.driver.core.ConsistencyLevel)2 DriverException (com.datastax.driver.core.exceptions.DriverException)2 UnavailableException (com.datastax.driver.core.exceptions.UnavailableException)2 CQLStatement (org.apache.cassandra.cql3.CQLStatement)2 BatchStatement (org.apache.cassandra.cql3.statements.BatchStatement)2 ICluster (org.apache.cassandra.distributed.api.ICluster)2