use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.
the class AlterNTSTest method testDropColumnAsPreparedStatement.
@Test
public void testDropColumnAsPreparedStatement() throws Throwable {
String table = createTable("CREATE TABLE %s (key int PRIMARY KEY, value int);");
PreparedStatement prepared = sessionNet().prepare("ALTER TABLE " + KEYSPACE + "." + table + " DROP value;");
executeNet("INSERT INTO %s (key, value) VALUES (1, 1)");
assertRowsNet(executeNet("SELECT * FROM %s"), row(1, 1));
sessionNet().execute(prepared.bind());
executeNet("ALTER TABLE %s ADD value int");
assertRows(execute("SELECT * FROM %s"), row(1, null));
}
use of com.datastax.driver.core.PreparedStatement in project storm by apache.
the class BoundCQLStatementTupleMapper method map.
/**
* {@inheritDoc}
*/
@Override
public List<Statement> map(Map<String, Object> config, Session session, ITuple tuple) {
final List<Column> columns = mapper.map(tuple);
final String query = contextQuery.resolves(config, tuple);
PreparedStatement statement = getPreparedStatement(session, query);
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) this.binder.apply(statement, columns));
}
use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.
the class CQLMetricsTest method testPreparedStatementsRatio.
@Test
public void testPreparedStatementsRatio() {
clearMetrics();
PreparedStatement metricsStatement = session.prepare("INSERT INTO junit.metricstest (id, val) VALUES (?, ?)");
assertEquals(Double.NaN, QueryProcessor.metrics.preparedStatementsRatio.getValue(), 0.0);
for (int i = 0; i < 10; i++) session.execute(metricsStatement.bind(i, "val" + i));
assertEquals(1.0, QueryProcessor.metrics.preparedStatementsRatio.getValue(), 0.0);
for (int i = 0; i < 10; i++) session.execute(String.format("INSERT INTO junit.metricstest (id, val) VALUES (%d, '%s')", i, "val" + i));
assertEquals(0.5, QueryProcessor.metrics.preparedStatementsRatio.getValue(), 0.0);
}
use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.
the class CQLMetricsTest method testRegularStatementsExecuted.
@Test
public void testRegularStatementsExecuted() {
clearMetrics();
PreparedStatement metricsStatement = session.prepare("INSERT INTO junit.metricstest (id, val) VALUES (?, ?)");
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
for (int i = 0; i < 10; i++) session.execute(String.format("INSERT INTO junit.metricstest (id, val) VALUES (%d, '%s')", i, "val" + i));
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(10, QueryProcessor.metrics.regularStatementsExecuted.getCount());
}
use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.
the class CQLMetricsTest method testPreparedStatementsExecuted.
@Test
public void testPreparedStatementsExecuted() {
clearMetrics();
PreparedStatement metricsStatement = session.prepare("INSERT INTO junit.metricstest (id, val) VALUES (?, ?)");
assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
for (int i = 0; i < 10; i++) session.execute(metricsStatement.bind(i, "val" + i));
assertEquals(10, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
}
Aggregations