use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class InsertTest method testInsertWithDefaultTtl.
@Test
public void testInsertWithDefaultTtl() throws Throwable {
final int secondsPerMinute = 60;
createTable("CREATE TABLE %s (a int PRIMARY KEY, b int) WITH default_time_to_live = " + (10 * secondsPerMinute));
execute("INSERT INTO %s (a, b) VALUES (1, 1)");
UntypedResultSet resultSet = execute("SELECT ttl(b) FROM %s WHERE a = 1");
Assert.assertEquals(1, resultSet.size());
Row row = resultSet.one();
Assert.assertTrue(row.getInt("ttl(b)") >= (9 * secondsPerMinute));
execute("INSERT INTO %s (a, b) VALUES (2, 2) USING TTL ?", (5 * secondsPerMinute));
resultSet = execute("SELECT ttl(b) FROM %s WHERE a = 2");
Assert.assertEquals(1, resultSet.size());
row = resultSet.one();
Assert.assertTrue(row.getInt("ttl(b)") <= (5 * secondsPerMinute));
execute("INSERT INTO %s (a, b) VALUES (3, 3) USING TTL ?", 0);
assertRows(execute("SELECT ttl(b) FROM %s WHERE a = 3"), row(new Object[] { null }));
execute("INSERT INTO %s (a, b) VALUES (4, 4) USING TTL ?", unset());
resultSet = execute("SELECT ttl(b) FROM %s WHERE a = 4");
Assert.assertEquals(1, resultSet.size());
row = resultSet.one();
Assert.assertTrue(row.getInt("ttl(b)") >= (9 * secondsPerMinute));
execute("INSERT INTO %s (a, b) VALUES (?, ?) USING TTL ?", 4, 4, null);
assertRows(execute("SELECT ttl(b) FROM %s WHERE a = 4"), row(new Object[] { null }));
}
use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class SystemKeyspace method loadPreparedStatement.
public static int loadPreparedStatement(MD5Digest digest, TriFunction<MD5Digest, String, String, Boolean> onLoaded) {
String query = String.format("SELECT prepared_id, logged_keyspace, query_string FROM %s.%s WHERE prepared_id = ?", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
UntypedResultSet resultSet = executeOnceInternal(query, digest.byteBuffer());
int counter = 0;
for (UntypedResultSet.Row row : resultSet) {
if (onLoaded.accept(MD5Digest.wrap(row.getByteArray("prepared_id")), row.getString("query_string"), row.has("logged_keyspace") ? row.getString("logged_keyspace") : null))
counter++;
}
return counter;
}
use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class SystemKeyspace method loadPreparedStatements.
public static int loadPreparedStatements(TriFunction<MD5Digest, String, String, Boolean> onLoaded) {
String query = String.format("SELECT prepared_id, logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
UntypedResultSet resultSet = executeOnceInternal(query);
int counter = 0;
for (UntypedResultSet.Row row : resultSet) {
if (onLoaded.accept(MD5Digest.wrap(row.getByteArray("prepared_id")), row.getString("query_string"), row.has("logged_keyspace") ? row.getString("logged_keyspace") : null))
counter++;
}
return counter;
}
use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class BurnTestUtil method generateRows.
public static ResultMessage.Rows generateRows(int idx, SizeCaps sizeCaps) {
Random rnd = new Random(idx);
List<ColumnSpecification> columns = new ArrayList<>();
for (int i = 0; i < sizeCaps.columnCountCap; i++) {
columns.add(new ColumnSpecification("ks", "cf", new ColumnIdentifier(bytes(rnd, 5, 10), BytesType.instance), BytesType.instance));
}
List<List<ByteBuffer>> rows = new ArrayList<>();
int count = rnd.nextInt(sizeCaps.rowsCountCap);
for (int i = 0; i < count; i++) {
List<ByteBuffer> row = new ArrayList<>();
for (int j = 0; j < sizeCaps.columnCountCap; j++) row.add(bytes(rnd, sizeCaps.valueMinSize, sizeCaps.valueMaxSize));
rows.add(row);
}
ResultSet resultSet = new ResultSet(new ResultSet.ResultMetadata(columns), rows);
return new ResultMessage.Rows(resultSet);
}
use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.
the class SelectStatement method process.
public ResultSet process(PartitionIterator partitions, int nowInSec) throws InvalidRequestException {
QueryOptions options = QueryOptions.DEFAULT;
Selectors selectors = selection.newSelectors(options);
return process(partitions, options, selectors, nowInSec, getLimit(options));
}
Aggregations