Search in sources :

Example 51 with ResultSet

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 }));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Row(org.apache.cassandra.cql3.UntypedResultSet.Row) Test(org.junit.Test)

Example 52 with ResultSet

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;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 53 with ResultSet

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;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 54 with ResultSet

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);
}
Also used : ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Random(java.util.Random) ResultSet(org.apache.cassandra.cql3.ResultSet) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) ArrayList(java.util.ArrayList) List(java.util.List)

Example 55 with 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));
}
Also used : Selectors(org.apache.cassandra.cql3.selection.Selection.Selectors)

Aggregations

Test (org.junit.Test)32 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)12 ResultSet (com.google.api.ads.admanager.axis.v202202.ResultSet)12 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)9 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)8 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)8 Function (com.google.common.base.Function)8 DateTime (org.joda.time.DateTime)6 ResultSet (com.google.spanner.v1.ResultSet)5 ResultSet (com.datastax.driver.core.ResultSet)4 Session (com.datastax.driver.core.Session)4 ResultSet (com.google.api.ads.admanager.axis.v202105.ResultSet)4 Row (com.google.api.ads.admanager.axis.v202108.Row)4 Row (com.google.api.ads.admanager.axis.v202111.Row)4 Row (com.google.api.ads.admanager.axis.v202202.Row)4