CQL viene fornito con un'istruzione BEGIN BATCH ... APPLY BATCH che consente di raggruppare più inserti, in modo che uno sviluppatore possa creare una stringa di tale richiesta batch ed eseguirla. [http://www.datastax.com/dev/blog/client-side-improvements-in-cassandra-2-0]
Di seguito ha lavorato per me:
PreparedStatement ps = session.prepare(
"BEGIN BATCH" +
"INSERT INTO messages (user_id, msg_id, title, body) VALUES (?, ?, ?, ?);" +
"INSERT INTO messages (user_id, msg_id, title, body) VALUES (?, ?, ?, ?);" +
"INSERT INTO messages (user_id, msg_id, title, body) VALUES (?, ?, ?, ?);" +
"APPLY BATCH");
session.execute(ps.bind(uid, mid1, title1, body1, uid, mid2, title2, body2, uid, mid3, title3, body3));
Se non si conosce in anticipo ciò che le dichiarazioni che si desidera eseguire, è possibile utilizzare la seguente sintassi (Scala):
var statement: PreparedStatement = session.prepare("INSERT INTO people (name,age) VALUES (?,?)")
var boundStatement = new BoundStatement(statement)
val batchStmt = new BatchStatement()
batchStmt.add(boundStatement.bind("User A", "10"))
batchStmt.add(boundStatement.bind("User B", "12"))
session.execute(batchStmt)
Nota: BatchStatement può contenere fino a 65536 istruzioni. Ho imparato questo nel modo più duro. :-)
Quale driver stai usando? Stai usando CQL? Quale versione di Cassandra? – Richard
La versione di Cassandra è 1.2.2x e sto usando hector apis. – ajjain