Java Code Examples for org.apache.cassandra.cql3.QueryProcessor#executeInternal()

The following examples show how to use org.apache.cassandra.cql3.QueryProcessor#executeInternal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrubTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * For CASSANDRA-6892 too, check that for a compact table with one cluster column, we can insert whatever
 * we want as value for the clustering column, including something that would conflict with a CQL column definition.
 */
@Test
public void testValidationCompactStorage() throws Exception
{
    QueryProcessor.process("CREATE TABLE \"Keyspace1\".test_compact_dynamic_columns (a int, b text, c text, PRIMARY KEY (a, b)) WITH COMPACT STORAGE", ConsistencyLevel.ONE);

    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("test_compact_dynamic_columns");

    QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'a', 'foo')");
    QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'b', 'bar')");
    QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_dynamic_columns (a, b, c) VALUES (0, 'c', 'boo')");
    cfs.forceBlockingFlush();
    CompactionManager.instance.performScrub(cfs, true);

    // Scrub is silent, but it will remove broken records. So reading everything back to make sure nothing to "scrubbed away"
    UntypedResultSet rs = QueryProcessor.executeInternal("SELECT * FROM \"Keyspace1\".test_compact_dynamic_columns");
    assertEquals(3, rs.size());

    Iterator<UntypedResultSet.Row> iter = rs.iterator();
    assertEquals("foo", iter.next().getString("c"));
    assertEquals("bar", iter.next().getString("c"));
    assertEquals("boo", iter.next().getString("c"));
}
 
Example 2
Source File: PerRowSecondaryIndexTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidSearch() throws IOException
{
    Mutation rm;
    rm = new Mutation("PerRowSecondaryIndex", ByteBufferUtil.bytes("k4"));
    rm.add("Indexed1", Util.cellname("indexed"), ByteBufferUtil.bytes("foo"), 1);
    rm.apply();
    
    // test we can search:
    UntypedResultSet result = QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'foo'");
    assertEquals(1, result.size());

    // test we can't search if the searcher doesn't validate the expression:
    try
    {
        QueryProcessor.executeInternal("SELECT * FROM \"PerRowSecondaryIndex\".\"Indexed1\" WHERE indexed = 'invalid'");
        fail("Query should have been invalid!");
    }
    catch (Exception e)
    {
        assertTrue(e instanceof InvalidRequestException || (e.getCause() != null && (e.getCause() instanceof InvalidRequestException)));
    }
}
 
Example 3
Source File: ScrubTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testScrubColumnValidation() throws InterruptedException, RequestExecutionException, ExecutionException
{
    QueryProcessor.process("CREATE TABLE \"Keyspace1\".test_compact_static_columns (a bigint, b timeuuid, c boolean static, d text, PRIMARY KEY (a, b))", ConsistencyLevel.ONE);

    Keyspace keyspace = Keyspace.open("Keyspace1");
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("test_compact_static_columns");

    QueryProcessor.executeInternal("INSERT INTO \"Keyspace1\".test_compact_static_columns (a, b, c, d) VALUES (123, c3db07e8-b602-11e3-bc6b-e0b9a54a6d93, true, 'foobar')");
    cfs.forceBlockingFlush();
    CompactionManager.instance.performScrub(cfs, false);
}
 
Example 4
Source File: TriggersTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void assertUpdateIsAugmented(int key)
{
    UntypedResultSet rs = QueryProcessor.executeInternal(
                            String.format("SELECT * FROM %s.%s WHERE k=%s", ksName, cfName, key));
    assertTrue(String.format("Expected value (%s) for augmented cell v2 was not found", key), rs.one().has("v2"));
    assertEquals(999, rs.one().getInt("v2"));
}
 
Example 5
Source File: TriggersTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private void assertUpdateNotExecuted(String cf, int key)
{
    UntypedResultSet rs = QueryProcessor.executeInternal(
            String.format("SELECT * FROM %s.%s WHERE k=%s", ksName, cf, key));
    assertTrue(rs.isEmpty());
}