use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.
the class NativeProtocolTest method withCounters.
@Test
public void withCounters() throws Throwable {
try (ICluster ignored = init(builder().withNodes(3).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start())) {
final com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
Session session = cluster.connect();
session.execute("CREATE TABLE " + KEYSPACE + ".tbl (pk int, ck counter, PRIMARY KEY (pk));");
session.execute("UPDATE " + KEYSPACE + ".tbl set ck = ck + 10 where pk = 1;");
Statement select = new SimpleStatement("select * from " + KEYSPACE + ".tbl;").setConsistencyLevel(ConsistencyLevel.ALL);
final ResultSet resultSet = session.execute(select);
assertRows(RowUtil.toObjects(resultSet), row(1, 10L));
Assert.assertEquals(3, cluster.getMetadata().getAllHosts().size());
session.close();
cluster.close();
}
}
use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.
the class DescribeStatementTest method testSchemaChangeDuringPaging.
@Test
public void testSchemaChangeDuringPaging() {
SimpleStatement stmt = new SimpleStatement("DESCRIBE KEYSPACES");
stmt.setFetchSize(1);
ResultSet rs = executeNet(ProtocolVersion.CURRENT, stmt);
Iterator<Row> iter = rs.iterator();
assertTrue(iter.hasNext());
iter.next();
createKeyspace("CREATE KEYSPACE %s WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1};");
try {
iter.next();
fail("Expected InvalidQueryException");
} catch (InvalidQueryException e) {
assertEquals(DescribeStatement.SCHEMA_CHANGED_WHILE_PAGING_MESSAGE, e.getMessage());
}
}
use of com.datastax.driver.core.SimpleStatement in project storm by apache.
the class SimpleCQLStatementMapper method map.
/**
* {@inheritDoc}.
*/
@Override
public List<Statement> map(Map<String, Object> conf, Session session, ITuple tuple) {
List<Column> columns = mapper.map(tuple);
SimpleStatement statement = new SimpleStatement(queryString, Column.getVals(columns));
if (hasRoutingKeys()) {
List<ByteBuffer> keys = rkGenerator.getRoutingKeys(tuple);
if (keys.size() == 1) {
statement.setRoutingKey(keys.get(0));
} else {
statement.setRoutingKey(keys.toArray(new ByteBuffer[keys.size()]));
}
}
return Arrays.asList((Statement) statement);
}
use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.
the class FQLReplayTest method compareStatements.
private void compareStatements(Statement statement1, Statement statement2) {
assertTrue(statement1 instanceof SimpleStatement && statement2 instanceof SimpleStatement);
SimpleStatement simpleStmt1 = (SimpleStatement) statement1;
SimpleStatement simpleStmt2 = (SimpleStatement) statement2;
assertEquals(simpleStmt1.getQueryString(CodecRegistry.DEFAULT_INSTANCE), simpleStmt2.getQueryString(CodecRegistry.DEFAULT_INSTANCE));
assertArrayEquals(simpleStmt1.getValues(com.datastax.driver.core.ProtocolVersion.fromInt(QueryOptions.DEFAULT.getProtocolVersion().asInt()), CodecRegistry.DEFAULT_INSTANCE), simpleStmt2.getValues(com.datastax.driver.core.ProtocolVersion.fromInt(QueryOptions.DEFAULT.getProtocolVersion().asInt()), CodecRegistry.DEFAULT_INSTANCE));
}
use of com.datastax.driver.core.SimpleStatement in project cassandra by apache.
the class SASICQLTest method testBlobCompare.
/**
* Tests query condition '>' on blob columns.
*/
@Test
public void testBlobCompare() 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 blob);");
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, 0x1234);
execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 1, 0x12345678);
execute("INSERT INTO %s (pk, v) VALUES (?, ?);", 2, 0x12350000);
flush(forceFlush);
Session session = sessionNet();
SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v > 0x1234");
stmt.setFetchSize(5);
List<Row> rs = session.execute(stmt).all();
Assert.assertFalse("CONTAINS mode on non-literal blob type should not support RANGE operators", "CONTAINS".equals(mode));
Assert.assertEquals(2, rs.size());
Assert.assertEquals(1, 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);
}
}
}
}
Aggregations