Search in sources :

Example 96 with UntypedResultSet

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

the class OperationFctsTest method testPrecedenceAndParentheses.

@Test
public void testPrecedenceAndParentheses() throws Throwable {
    createTable("CREATE TABLE %s (a int, b int, c int, d int, PRIMARY KEY(a, b))");
    execute("INSERT INTO %S (a, b, c, d) VALUES (2, 5, 25, 4)");
    UntypedResultSet rs = execute("SELECT a - c / b + d FROM %s");
    assertColumnNames(rs, "a - c / b + d");
    assertRows(rs, row(1));
    rs = execute("SELECT (c - b) / a + d FROM %s");
    assertColumnNames(rs, "(c - b) / a + d");
    assertRows(rs, row(14));
    rs = execute("SELECT c / a / b FROM %s");
    assertColumnNames(rs, "c / a / b");
    assertRows(rs, row(2));
    rs = execute("SELECT c / b / d FROM %s");
    assertColumnNames(rs, "c / b / d");
    assertRows(rs, row(1));
    rs = execute("SELECT (c - a) %% d / a FROM %s");
    assertColumnNames(rs, "(c - a) % d / a");
    assertRows(rs, row(1));
    rs = execute("SELECT (c - a) %% d / a + d FROM %s");
    assertColumnNames(rs, "(c - a) % d / a + d");
    assertRows(rs, row(5));
    rs = execute("SELECT -(c - a) %% d / a + d FROM %s");
    assertColumnNames(rs, "-(c - a) % d / a + d");
    assertRows(rs, row(3));
    rs = execute("SELECT (-c - a) %% d / a + d FROM %s");
    assertColumnNames(rs, "(-c - a) % d / a + d");
    assertRows(rs, row(3));
    rs = execute("SELECT c - a %% d / a + d FROM %s");
    assertColumnNames(rs, "c - a % d / a + d");
    assertRows(rs, row(28));
    rs = execute("SELECT (int)((c - a) %% d / (a + d)) FROM %s");
    assertColumnNames(rs, "(int)((c - a) % d / (a + d))");
    assertRows(rs, row(0));
    // test with aliases
    rs = execute("SELECT (int)((c - a) %% d / (a + d)) as result FROM %s");
    assertColumnNames(rs, "result");
    assertRows(rs, row(0));
    rs = execute("SELECT c / a / b as divisions FROM %s");
    assertColumnNames(rs, "divisions");
    assertRows(rs, row(2));
    assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = (int) ? / 2 - 5", 2, 20), row(2, 5, 25, 4));
    assertRows(execute("SELECT * FROM %s WHERE a = ? AND b = (int) ? / (2 + 2)", 2, 20), row(2, 5, 25, 4));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Test(org.junit.Test)

Example 97 with UntypedResultSet

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

the class UFScriptTest method testJavascriptUserType.

@Test
public void testJavascriptUserType() throws Throwable {
    String type = createType("CREATE TYPE %s (txt text, i int)");
    createTable("CREATE TABLE %s (key int primary key, udt frozen<" + type + ">)");
    String fUdt1 = createFunction(KEYSPACE, type, "CREATE FUNCTION %s( udt " + type + " ) " + "RETURNS NULL ON NULL INPUT " + "RETURNS " + type + ' ' + "LANGUAGE javascript\n" + "AS $$" + "     udt;$$;");
    String fUdt2 = createFunction(KEYSPACE, type, "CREATE FUNCTION %s( udt " + type + " ) " + "RETURNS NULL ON NULL INPUT " + "RETURNS text " + "LANGUAGE javascript\n" + "AS $$" + "     udt.getString(\"txt\");$$;");
    String fUdt3 = createFunction(KEYSPACE, type, "CREATE FUNCTION %s( udt " + type + " ) " + "RETURNS NULL ON NULL INPUT " + "RETURNS int " + "LANGUAGE javascript\n" + "AS $$" + "     udt.getInt(\"i\");$$;");
    execute("INSERT INTO %s (key, udt) VALUES (1, {txt: 'one', i:1})");
    UntypedResultSet rows = execute("SELECT " + fUdt1 + "(udt) FROM %s WHERE key = 1");
    Assert.assertEquals(1, rows.size());
    assertRows(execute("SELECT " + fUdt2 + "(udt) FROM %s WHERE key = 1"), row("one"));
    assertRows(execute("SELECT " + fUdt3 + "(udt) FROM %s WHERE key = 1"), row(1));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Test(org.junit.Test)

Example 98 with UntypedResultSet

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

the class UFTest method testFunctionWithReservedName.

@Test
public void testFunctionWithReservedName() throws Throwable {
    execute("CREATE TABLE " + KEYSPACE_PER_TEST + ".second_tab (key int primary key, val double)");
    String fName = createFunction(KEYSPACE_PER_TEST, "", "CREATE OR REPLACE FUNCTION %s() " + "RETURNS NULL ON NULL INPUT " + "RETURNS timestamp " + "LANGUAGE JAVA " + "AS 'return null;';");
    execute("INSERT INTO " + KEYSPACE_PER_TEST + ".second_tab (key, val) VALUES (?, ?)", 1, 1d);
    execute("INSERT INTO " + KEYSPACE_PER_TEST + ".second_tab (key, val) VALUES (?, ?)", 2, 2d);
    execute("INSERT INTO " + KEYSPACE_PER_TEST + ".second_tab (key, val) VALUES (?, ?)", 3, 3d);
    // ensure that system now() is executed
    UntypedResultSet rows = execute("SELECT key, val, now() FROM " + KEYSPACE_PER_TEST + ".second_tab");
    Assert.assertEquals(3, rows.size());
    UntypedResultSet.Row row = rows.iterator().next();
    Date ts = row.getTimestamp(row.getColumns().get(2).name.toString());
    Assert.assertNotNull(ts);
    // ensure that KEYSPACE_PER_TEST's now() is executed
    rows = execute("SELECT key, val, " + fName + "() FROM " + KEYSPACE_PER_TEST + ".second_tab");
    Assert.assertEquals(3, rows.size());
    row = rows.iterator().next();
    Assert.assertFalse(row.has(row.getColumns().get(2).name.toString()));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Date(java.util.Date) Test(org.junit.Test)

Example 99 with UntypedResultSet

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

the class HintedHandOffMetricsTest method testHintsMetrics.

@Test
public void testHintsMetrics() throws Exception {
    DatabaseDescriptor.getHintsDirectory().tryCreateDirectories();
    for (int i = 0; i < 99; i++) HintsService.instance.metrics.incrPastWindow(InetAddressAndPort.getLocalHost());
    HintsService.instance.metrics.log();
    UntypedResultSet rows = executeInternal("SELECT hints_dropped FROM system." + SystemKeyspace.PEER_EVENTS_V2);
    Map<UUID, Integer> returned = rows.one().getMap("hints_dropped", UUIDType.instance, Int32Type.instance);
    assertEquals(Iterators.getLast(returned.values().iterator()).intValue(), 99);
    rows = executeInternal("SELECT hints_dropped FROM system." + SystemKeyspace.LEGACY_PEER_EVENTS);
    returned = rows.one().getMap("hints_dropped", UUIDType.instance, Int32Type.instance);
    assertEquals(Iterators.getLast(returned.values().iterator()).intValue(), 99);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) UUID(java.util.UUID) Test(org.junit.Test)

Example 100 with UntypedResultSet

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

the class TriggersTest method assertUpdateIsAugmented.

private void assertUpdateIsAugmented(int key, String originColumnName, Object originColumnValue) {
    UntypedResultSet rs = QueryProcessor.process(String.format("SELECT * FROM %s.%s WHERE k=%s", ksName, cfName, key), ConsistencyLevel.ONE);
    // from trigger
    assertRowValue(rs.one(), key, "v2", 999);
    // from original update
    assertRowValue(rs.one(), key, originColumnName, originColumnValue);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)107 Test (org.junit.Test)35 UUID (java.util.UUID)8 ByteBuffer (java.nio.ByteBuffer)6 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)6 HashSet (java.util.HashSet)5 Mutation (org.apache.cassandra.db.Mutation)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashMap (java.util.HashMap)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)3 Predicate (com.google.common.base.Predicate)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2