Search in sources :

Example 6 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class ModificationStatement method buildCasFailureResultSet.

private static ResultSet buildCasFailureResultSet(RowIterator partition, Iterable<ColumnMetadata> columnsWithConditions, boolean isBatch, QueryOptions options, int nowInSeconds) {
    TableMetadata metadata = partition.metadata();
    Selection selection;
    if (columnsWithConditions == null) {
        selection = Selection.wildcard(metadata, false, false);
    } else {
        // We can have multiple conditions on the same columns (for collections) so use a set
        // to avoid duplicate, but preserve the order just to it follows the order of IF in the query in general
        Set<ColumnMetadata> defs = new LinkedHashSet<>();
        // of batches for compatibility sakes).
        if (isBatch)
            Iterables.addAll(defs, metadata.primaryKeyColumns());
        Iterables.addAll(defs, columnsWithConditions);
        selection = Selection.forColumns(metadata, new ArrayList<>(defs), false);
    }
    Selectors selectors = selection.newSelectors(options);
    ResultSetBuilder builder = new ResultSetBuilder(selection.getResultMetadata(), selectors);
    SelectStatement.forSelection(metadata, selection).processPartition(partition, options, builder, nowInSeconds);
    return builder.build();
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) ResultSetBuilder(org.apache.cassandra.cql3.selection.ResultSetBuilder) Selection(org.apache.cassandra.cql3.selection.Selection) Selectors(org.apache.cassandra.cql3.selection.Selection.Selectors)

Example 7 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class UpdateTest method testUpdateWithDefaultTtl.

@Test
public void testUpdateWithDefaultTtl() throws Throwable {
    final int secondsPerMinute = 60;
    createTable("CREATE TABLE %s (a int PRIMARY KEY, b int) WITH default_time_to_live = " + (10 * secondsPerMinute));
    execute("UPDATE %s SET b = 1 WHERE a = 1");
    UntypedResultSet resultSet = execute("SELECT ttl(b) FROM %s WHERE a = 1");
    assertEquals(1, resultSet.size());
    Row row = resultSet.one();
    assertTrue(row.getInt("ttl(b)") >= (9 * secondsPerMinute));
    execute("UPDATE %s USING TTL ? SET b = 3 WHERE a = 1", 0);
    assertRows(execute("SELECT ttl(b) FROM %s WHERE a = 1"), row(new Object[] { null }));
    execute("UPDATE %s SET b = 3 WHERE a = 1");
    resultSet = execute("SELECT ttl(b) FROM %s WHERE a = 1");
    assertEquals(1, resultSet.size());
    row = resultSet.one();
    assertTrue(row.getInt("ttl(b)") >= (9 * secondsPerMinute));
    execute("UPDATE %s USING TTL ? SET b = 2 WHERE a = 2", unset());
    resultSet = execute("SELECT ttl(b) FROM %s WHERE a = 2");
    assertEquals(1, resultSet.size());
    row = resultSet.one();
    assertTrue(row.getInt("ttl(b)") >= (9 * secondsPerMinute));
    execute("UPDATE %s USING TTL ? SET b = ? WHERE a = ?", null, 3, 3);
    assertRows(execute("SELECT ttl(b) FROM %s WHERE a = 3"), row(new Object[] { null }));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Row(org.apache.cassandra.cql3.UntypedResultSet.Row) Test(org.junit.Test)

Example 8 with ResultSet

use of org.apache.cassandra.cql3.ResultSet 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();
    }
}
Also used : SimpleStatement(com.datastax.driver.core.SimpleStatement) CQLStatement(org.apache.cassandra.cql3.CQLStatement) Statement(com.datastax.driver.core.Statement) SimpleStatement(com.datastax.driver.core.SimpleStatement) ICluster(org.apache.cassandra.distributed.api.ICluster) ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 9 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class CollectionsTest method testCollectionOperationResultSetMetadata.

@Test
public void testCollectionOperationResultSetMetadata() throws Throwable {
    createTable("CREATE TABLE %s (k int PRIMARY KEY," + "m map<text, text>," + "fm frozen<map<text, text>>," + "s set<text>," + "fs frozen<set<text>>)");
    execute("INSERT INTO %s (k, m, fm, s, fs) VALUES (?, ?, ?, ?, ?)", 0, map("1", "one", "2", "two"), map("1", "one", "2", "two"), set("1", "2", "3"), set("1", "2", "3"));
    String cql = "SELECT k, " + "m, m['2'], m['2'..'3'], m[..'2'], m['3'..], " + "fm, fm['2'], fm['2'..'3'], fm[..'2'], fm['3'..], " + "s, s['2'], s['2'..'3'], s[..'2'], s['3'..], " + "fs, fs['2'], fs['2'..'3'], fs[..'2'], fs['3'..] " + "FROM " + KEYSPACE + '.' + currentTable() + " WHERE k = 0";
    UntypedResultSet result = execute(cql);
    Iterator<ColumnSpecification> meta = result.metadata().iterator();
    meta.next();
    for (int i = 0; i < 4; i++) {
        // take the "full" collection selection
        ColumnSpecification ref = meta.next();
        ColumnSpecification selSingle = meta.next();
        assertEquals(ref.toString(), UTF8Type.instance, selSingle.type);
        for (int selOrSlice = 0; selOrSlice < 3; selOrSlice++) {
            ColumnSpecification selSlice = meta.next();
            assertEquals(ref.toString(), ref.type, selSlice.type);
        }
    }
    assertRows(result, row(0, map("1", "one", "2", "two"), "two", map("2", "two"), map("1", "one", "2", "two"), null, map("1", "one", "2", "two"), "two", map("2", "two"), map("1", "one", "2", "two"), map(), set("1", "2", "3"), "2", set("2", "3"), set("1", "2"), set("3"), set("1", "2", "3"), "2", set("2", "3"), set("1", "2"), set("3")));
    Session session = sessionNet();
    ResultSet rset = session.execute(cql);
    ColumnDefinitions colDefs = rset.getColumnDefinitions();
    Iterator<ColumnDefinitions.Definition> colDefIter = colDefs.asList().iterator();
    colDefIter.next();
    for (int i = 0; i < 4; i++) {
        // take the "full" collection selection
        ColumnDefinitions.Definition ref = colDefIter.next();
        ColumnDefinitions.Definition selSingle = colDefIter.next();
        assertEquals(ref.getName(), DataType.NativeType.text(), selSingle.getType());
        for (int selOrSlice = 0; selOrSlice < 3; selOrSlice++) {
            ColumnDefinitions.Definition selSlice = colDefIter.next();
            assertEquals(ref.getName() + ' ' + ref.getType(), ref.getType(), selSlice.getType());
        }
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ColumnSpecification(org.apache.cassandra.cql3.ColumnSpecification) ColumnDefinitions(com.datastax.driver.core.ColumnDefinitions) ResultSet(com.datastax.driver.core.ResultSet) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 10 with ResultSet

use of org.apache.cassandra.cql3.ResultSet in project cassandra by apache.

the class SASIIndexTest method testConditionalsWithReversedType.

@Test
public void testConditionalsWithReversedType() {
    final String TABLE_NAME = "reversed_clustering";
    QueryProcessor.executeOnceInternal(String.format("CREATE TABLE IF NOT EXISTS %s.%s (pk text, ck int, v int, PRIMARY KEY (pk, ck)) " + "WITH CLUSTERING ORDER BY (ck DESC);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (ck) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("CREATE CUSTOM INDEX ON %s.%s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex'", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 1, 1);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 2, 2);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Alex', 3, 3);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 1, 1);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 2, 2);", KS_NAME, TABLE_NAME));
    QueryProcessor.executeOnceInternal(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES ('Tom', 3, 3);", KS_NAME, TABLE_NAME));
    UntypedResultSet resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 1, 1), CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 1, 1), CQLTester.row("Tom", 2, 2));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck <= 2 AND v > 1 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 2, 2));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck < 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 1, 1), CQLTester.row("Tom", 1, 1));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Alex", 3, 3), CQLTester.row("Tom", 2, 2), CQLTester.row("Tom", 3, 3));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck >= 2 AND v < 3 ALLOW FILTERING;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 2, 2), CQLTester.row("Tom", 2, 2));
    resultSet = QueryProcessor.executeOnceInternal(String.format("SELECT * FROM %s.%s WHERE ck > 2;", KS_NAME, TABLE_NAME));
    CQLTester.assertRowsIgnoringOrder(resultSet, CQLTester.row("Alex", 3, 3), CQLTester.row("Tom", 3, 3));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

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