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));
}
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));
}
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()));
}
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);
}
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);
}
Aggregations