From aa43b64d65a23783b039b1733efa19f0147429d7 Mon Sep 17 00:00:00 2001 From: samuel orji Date: Tue, 17 Oct 2023 13:52:27 +0100 Subject: [PATCH] review feedback, use prepared statements --- .../src/transport/large_batch_statements_test.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/scylla/src/transport/large_batch_statements_test.rs b/scylla/src/transport/large_batch_statements_test.rs index 0bbd06dfc9..11ade26b4d 100644 --- a/scylla/src/transport/large_batch_statements_test.rs +++ b/scylla/src/transport/large_batch_statements_test.rs @@ -33,17 +33,13 @@ async fn test_large_batch_statements() { async fn create_test_session(session: Session, ks: &String) -> Session { session .query( - format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1 }}",ks), + format!("CREATE KEYSPACE {} WITH REPLICATION = {{ 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1 }}",ks), &[], ) .await.unwrap(); - session - .query(format!("DROP TABLE IF EXISTS {}.pairs;", ks), &[]) - .await - .unwrap(); session .query( - format!("CREATE TABLE IF NOT EXISTS {}.pairs (dummy int, k blob, v blob, primary key (dummy, k))", ks), + format!("CREATE TABLE {}.pairs (dummy int, k blob, v blob, primary key (dummy, k))", ks), &[], ) .await.unwrap(); @@ -53,15 +49,16 @@ async fn create_test_session(session: Session, ks: &String) -> Session { async fn write_batch(session: &Session, n: usize, ks: &String) -> Result { let mut batch_query = Batch::new(BatchType::Unlogged); let mut batch_values = Vec::new(); + let query = format!("INSERT INTO {}.pairs (dummy, k, v) VALUES (0, ?, ?)", ks); + let query = Query::new(query); + let prepared_statement = session.prepare(query).await.unwrap(); for i in 0..n { let mut key = vec![0]; key.extend(i.to_be_bytes().as_slice()); let value = key.clone(); - let query = format!("INSERT INTO {}.pairs (dummy, k, v) VALUES (0, ?, ?)", ks); let values = vec![key, value]; batch_values.push(values); - let query = Query::new(query); - batch_query.append_statement(query); + batch_query.append_statement(prepared_statement.clone()); } session.batch(&batch_query, batch_values).await }