Search in sources :

Example 6 with ModificationStatement

use of org.apache.cassandra.cql3.statements.ModificationStatement in project cassandra by apache.

the class UFIdentificationTest method testBatchStatementWithConditions.

@Test
public void testBatchStatementWithConditions() throws Throwable {
    List<ModificationStatement> statements = new ArrayList<>();
    statements.add(modificationStatement(cql("UPDATE %s SET i_val = %s WHERE key=0 AND i_cc=0 and t_cc='foo' IF l_val = %s", functionCall(iFunc, "0"), functionCall(lFunc, "[1]"))));
    statements.add(modificationStatement(cql("UPDATE %s SET i_val = %s WHERE key=0 AND i_cc=1 and t_cc='foo' IF s_val = %s", functionCall(iFunc, "0"), functionCall(sFunc, "{1}"))));
    BatchStatement batch = new BatchStatement(BatchStatement.Type.LOGGED, VariableSpecifications.empty(), statements, Attributes.none());
    assertFunctions(batch, iFunc, lFunc, sFunc);
}
Also used : ModificationStatement(org.apache.cassandra.cql3.statements.ModificationStatement) BatchStatement(org.apache.cassandra.cql3.statements.BatchStatement) Test(org.junit.Test)

Example 7 with ModificationStatement

use of org.apache.cassandra.cql3.statements.ModificationStatement 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(BatchStatement.Type.LOGGED, VariableSpecifications.empty(), 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.authorize(clientState);
}
Also used : ModificationStatement(org.apache.cassandra.cql3.statements.ModificationStatement) BatchStatement(org.apache.cassandra.cql3.statements.BatchStatement) Test(org.junit.Test)

Aggregations

BatchStatement (org.apache.cassandra.cql3.statements.BatchStatement)7 ModificationStatement (org.apache.cassandra.cql3.statements.ModificationStatement)7 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ByteBuffer (java.nio.ByteBuffer)2 QueryHandler (org.apache.cassandra.cql3.QueryHandler)2 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)2 PreparedQueryNotFoundException (org.apache.cassandra.exceptions.PreparedQueryNotFoundException)2 MD5Digest (org.apache.cassandra.utils.MD5Digest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 List (java.util.List)1 UUID (java.util.UUID)1 BatchQueryOptions (org.apache.cassandra.cql3.BatchQueryOptions)1 CQLStatement (org.apache.cassandra.cql3.CQLStatement)1 ParsedStatement (org.apache.cassandra.cql3.statements.ParsedStatement)1 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1 ClientState (org.apache.cassandra.service.ClientState)1 QueryState (org.apache.cassandra.service.QueryState)1 Message (org.apache.cassandra.transport.Message)1