Search in sources :

Example 11 with FunctionName

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());
}
Also used : FunctionName(org.apache.cassandra.cql3.functions.FunctionName) Test(org.junit.Test)

Example 12 with FunctionName

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());
}
Also used : FunctionName(org.apache.cassandra.cql3.functions.FunctionName) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) Test(org.junit.Test)

Example 13 with FunctionName

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);
}
Also used : ModificationStatement(org.apache.cassandra.cql3.statements.ModificationStatement) BatchStatement(org.apache.cassandra.cql3.statements.BatchStatement) Test(org.junit.Test)

Aggregations

FunctionName (org.apache.cassandra.cql3.functions.FunctionName)9 Test (org.junit.Test)9 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)3 ArrayList (java.util.ArrayList)2 AbstractType (org.apache.cassandra.db.marshal.AbstractType)2 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)2 ImmutableList (com.google.common.collect.ImmutableList)1 MapDifference (com.google.common.collect.MapDifference)1 Maps (com.google.common.collect.Maps)1 String.format (java.lang.String.format)1 ByteBuffer (java.nio.ByteBuffer)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 java.util (java.util)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 org.apache.cassandra.config (org.apache.cassandra.config)1 org.apache.cassandra.cql3 (org.apache.cassandra.cql3)1