use of org.apache.cassandra.cql3.functions.FunctionName in project cassandra by apache.
the class UFTest method testFunctionDropOnKeyspaceDrop.
@Test
public void testFunctionDropOnKeyspaceDrop() throws Throwable {
String fSin = createFunction(KEYSPACE_PER_TEST, "double", "CREATE FUNCTION %s ( input double ) " + "CALLED ON NULL INPUT " + "RETURNS double " + "LANGUAGE java " + "AS 'return Double.valueOf(Math.sin(input.doubleValue()));'");
FunctionName fSinName = parseFunctionName(fSin);
Assert.assertEquals(1, Schema.instance.getFunctions(parseFunctionName(fSin)).size());
assertRows(execute("SELECT function_name, language FROM system_schema.functions WHERE keyspace_name=?", KEYSPACE_PER_TEST), row(fSinName.name, "java"));
dropPerTestKeyspace();
assertRows(execute("SELECT function_name, language FROM system_schema.functions WHERE keyspace_name=?", KEYSPACE_PER_TEST));
Assert.assertEquals(0, Schema.instance.getFunctions(fSinName).size());
}
use of org.apache.cassandra.cql3.functions.FunctionName in project cassandra by apache.
the class UFTest method testUserTypeDrop.
@Test
public void testUserTypeDrop() 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 fName = createFunction(KEYSPACE, type, "CREATE FUNCTION %s( udt " + type + " ) " + "CALLED ON NULL INPUT " + "RETURNS int " + "LANGUAGE java " + "AS $$return " + " Integer.valueOf(udt.getInt(\"i\"));$$;");
FunctionName fNameName = parseFunctionName(fName);
Assert.assertEquals(1, Schema.instance.getFunctions(fNameName).size());
ResultMessage.Prepared prepared = QueryProcessor.prepare(String.format("SELECT key, %s(udt) FROM %s.%s", fName, KEYSPACE, currentTable()), ClientState.forInternalCalls());
Assert.assertNotNull(QueryProcessor.instance.getPrepared(prepared.statementId));
// UT still referenced by table
assertInvalidMessage("Cannot drop user type", "DROP TYPE " + type);
execute("DROP TABLE %s");
// UT still referenced by UDF
assertInvalidMessage("as it is still used by function", "DROP TYPE " + type);
Assert.assertNull(QueryProcessor.instance.getPrepared(prepared.statementId));
// function stays
Assert.assertEquals(1, Schema.instance.getFunctions(fNameName).size());
}
use of org.apache.cassandra.cql3.functions.FunctionName in project cassandra by apache.
the class UFAuthTest method testBatchStatement.
@Test
public void testBatchStatement() throws Throwable {
List<ModificationStatement> statements = new ArrayList<>();
List<String> functions = new ArrayList<>();
for (int i = 0; i < 3; i++) {
String functionName = createSimpleFunction();
ModificationStatement stmt = (ModificationStatement) getStatement(String.format("INSERT INTO %s (k, v1, v2) " + "VALUES (%s, %s, %s)", KEYSPACE + "." + currentTable(), i, i, functionCall(functionName)));
functions.add(functionName);
statements.add(stmt);
}
BatchStatement batch = new BatchStatement(-1, BatchStatement.Type.LOGGED, statements, Attributes.none());
assertUnauthorized(batch, functions);
grantExecuteOnFunction(functions.get(0));
assertUnauthorized(batch, functions.subList(1, functions.size()));
grantExecuteOnFunction(functions.get(1));
assertUnauthorized(batch, functions.subList(2, functions.size()));
grantExecuteOnFunction(functions.get(2));
batch.checkAccess(clientState);
}
Aggregations