Search in sources :

Example 26 with UntypedResultSet

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

the class TypeTest method testDateCompatibility.

@Test
public void testDateCompatibility() throws Throwable {
    createTable("CREATE TABLE %s (a int, b timestamp, c bigint, d varint, PRIMARY KEY (a, b, c, d))");
    execute("INSERT INTO %s (a, b, c, d) VALUES (0, toUnixTimestamp(now()), toTimestamp(now()), toTimestamp(now()))");
    UntypedResultSet results = execute("SELECT * FROM %s WHERE a=0 AND b <= toUnixTimestamp(now())");
    assertEquals(1, results.size());
    execute("INSERT INTO %s (a, b, c, d) VALUES (1, unixTimestampOf(now()), dateOf(now()), dateOf(now()))");
    results = execute("SELECT * FROM %s WHERE a=1 AND b <= toUnixTimestamp(now())");
    assertEquals(1, results.size());
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Test(org.junit.Test)

Example 27 with UntypedResultSet

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

the class UFJavaTest method testJavaUserType.

@Test
public void testJavaUserType() throws Throwable {
    String type = KEYSPACE + '.' + createType("CREATE TYPE %s (txt text, i int)");
    createTable("CREATE TABLE %s (key int primary key, udt frozen<" + type + ">)");
    String fUdt0 = createFunction(KEYSPACE, type, "CREATE FUNCTION %s( udt " + type + " ) " + "RETURNS NULL ON NULL INPUT " + "RETURNS " + type + " " + "LANGUAGE java " + "AS $$return " + "     udt;$$;");
    String fUdt1 = createFunction(KEYSPACE, type, "CREATE FUNCTION %s( udt " + type + ") " + "RETURNS NULL ON NULL INPUT " + "RETURNS text " + "LANGUAGE java " + "AS $$return " + "     udt.getString(\"txt\");$$;");
    String fUdt2 = createFunction(KEYSPACE, type, "CREATE FUNCTION %s( udt " + type + ") " + "CALLED ON NULL INPUT " + "RETURNS int " + "LANGUAGE java " + "AS $$return " + "     Integer.valueOf(udt.getInt(\"i\"));$$;");
    execute("INSERT INTO %s (key, udt) VALUES (1, {txt: 'one', i:1})");
    UntypedResultSet rows = execute("SELECT " + fUdt0 + "(udt) FROM %s WHERE key = 1");
    Assert.assertEquals(1, rows.size());
    assertRows(execute("SELECT " + fUdt1 + "(udt) FROM %s WHERE key = 1"), row("one"));
    assertRows(execute("SELECT " + fUdt2 + "(udt) FROM %s WHERE key = 1"), row(1));
    for (ProtocolVersion version : PROTOCOL_VERSIONS) {
        List<Row> rowsNet = executeNet(version, "SELECT " + fUdt0 + "(udt) FROM %s WHERE key = 1").all();
        Assert.assertEquals(1, rowsNet.size());
        UDTValue udtVal = rowsNet.get(0).getUDTValue(0);
        Assert.assertEquals("one", udtVal.getString("txt"));
        Assert.assertEquals(1, udtVal.getInt("i"));
        assertRowsNet(version, executeNet(version, "SELECT " + fUdt1 + "(udt) FROM %s WHERE key = 1"), row("one"));
        assertRowsNet(version, executeNet(version, "SELECT " + fUdt2 + "(udt) FROM %s WHERE key = 1"), row(1));
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) UDTValue(com.datastax.driver.core.UDTValue) Row(com.datastax.driver.core.Row) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) Test(org.junit.Test)

Example 28 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet 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");
    Assert.assertEquals(1, resultSet.size());
    Row row = resultSet.one();
    Assert.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");
    Assert.assertEquals(1, resultSet.size());
    row = resultSet.one();
    Assert.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");
    Assert.assertEquals(1, resultSet.size());
    row = resultSet.one();
    Assert.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 29 with UntypedResultSet

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

the class RowCacheCQLTest method test7636.

@Test
public void test7636() throws Throwable {
    CacheService.instance.setRowCacheCapacityInMB(1);
    createTable("CREATE TABLE %s (p1 bigint, c1 int, v int, PRIMARY KEY (p1, c1)) WITH caching = { 'keys': 'NONE', 'rows_per_partition': 'ALL' }");
    execute("INSERT INTO %s (p1, c1, v) VALUES (?, ?, ?)", 123L, 10, 12);
    assertEmpty(execute("SELECT * FROM %s WHERE p1 = ? and c1 > ?", 123L, 1000));
    UntypedResultSet res = execute("SELECT * FROM %s WHERE p1 = ? and c1 > ?", 123L, 0);
    assertEquals(1, res.size());
    assertEmpty(execute("SELECT * FROM %s WHERE p1 = ? and c1 > ?", 123L, 1000));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Test(org.junit.Test)

Example 30 with UntypedResultSet

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

the class ScrubTest method testFilterOutDuplicates.

/**
     * Tests with invalid sstables (containing duplicate entries in 2.0 and 3.0 storage format),
     * that were caused by upgrading from 2.x with duplicate range tombstones.
     *
     * See CASSANDRA-12144 for details.
     */
@Test
public void testFilterOutDuplicates() throws Exception {
    DatabaseDescriptor.setPartitionerUnsafe(Murmur3Partitioner.instance);
    QueryProcessor.process(String.format("CREATE TABLE \"%s\".cf_with_duplicates_3_0 (a int, b int, c int, PRIMARY KEY (a, b))", KEYSPACE), ConsistencyLevel.ONE);
    Keyspace keyspace = Keyspace.open(KEYSPACE);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("cf_with_duplicates_3_0");
    Path legacySSTableRoot = Paths.get(System.getProperty(INVALID_LEGACY_SSTABLE_ROOT_PROP), "Keyspace1", "cf_with_duplicates_3_0");
    for (String filename : new String[] { "mb-3-big-CompressionInfo.db", "mb-3-big-Digest.crc32", "mb-3-big-Index.db", "mb-3-big-Summary.db", "mb-3-big-Data.db", "mb-3-big-Filter.db", "mb-3-big-Statistics.db", "mb-3-big-TOC.txt" }) {
        Files.copy(Paths.get(legacySSTableRoot.toString(), filename), cfs.getDirectories().getDirectoryForNewSSTables().toPath().resolve(filename));
    }
    cfs.loadNewSSTables();
    cfs.scrub(true, true, true, 1);
    UntypedResultSet rs = QueryProcessor.executeInternal(String.format("SELECT * FROM \"%s\".cf_with_duplicates_3_0", KEYSPACE));
    assertEquals(1, rs.size());
    QueryProcessor.executeInternal(String.format("DELETE FROM \"%s\".cf_with_duplicates_3_0 WHERE a=1 AND b =2", KEYSPACE));
    rs = QueryProcessor.executeInternal(String.format("SELECT * FROM \"%s\".cf_with_duplicates_3_0", KEYSPACE));
    assertEquals(0, rs.size());
}
Also used : Path(java.nio.file.Path) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) SchemaLoader.createKeyspace(org.apache.cassandra.SchemaLoader.createKeyspace) Test(org.junit.Test)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)71 Test (org.junit.Test)22 Mutation (org.apache.cassandra.db.Mutation)5 ByteBuffer (java.nio.ByteBuffer)4 UUID (java.util.UUID)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 File (java.io.File)3 InetAddress (java.net.InetAddress)3 SchemaLoader.createKeyspace (org.apache.cassandra.SchemaLoader.createKeyspace)3 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 IOException (java.io.IOException)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 Row (org.apache.cassandra.cql3.UntypedResultSet.Row)2 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2