This is an automated email from the ASF dual-hosted git repository. mck pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push: new dd014bb Batch statement preparation fails if multiple tables and parameters are used dd014bb is described below commit dd014bbf583a9101b9b21d5a345be3e4cd79ad96 Author: bryn <brynco...@gmail.com> AuthorDate: Thu Apr 16 16:35:38 2020 +0100 Batch statement preparation fails if multiple tables and parameters are used The logic for detecting if a batch statement affects multiple tables in BatchStatement#getPartitionKeyBindVariableIndexes is inverted. BatchTest#testBatchMultipleTablePrepare has been added to demonstrate the issue. patch by Bryn Cooke; reviewed by Eduard Tudenhöfner, Robert Stupp for CASSANDRA-15730 --- CHANGES.txt | 1 + .../cassandra/cql3/statements/BatchStatement.java | 2 +- .../cql3/validation/operations/BatchTest.java | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index c43414d..102b1aa 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0-alpha4 + * Fix batch statement preparation when multiple tables and parameters are used (CASSANDRA-15730) * Fix regression with traceOutgoingMessage printing message size (CASSANDRA-15687) * Ensure repaired data tracking reads a consistent amount of data across replicas (CASSANDRA-15601) * Fix CQLSH to avoid arguments being evaluated (CASSANDRA-15660) diff --git a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java index fa637ef..c165969 100644 --- a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java @@ -141,7 +141,7 @@ public class BatchStatement implements CQLStatement public short[] getPartitionKeyBindVariableIndexes() { boolean affectsMultipleTables = - !statements.isEmpty() && statements.stream().map(s -> s.metadata().id).allMatch(isEqual(statements.get(0).metadata().id)); + !statements.isEmpty() && !statements.stream().map(s -> s.metadata().id).allMatch(isEqual(statements.get(0).metadata().id)); // Use the TableMetadata of the first statement for partition key bind indexes. If the statements affect // multiple tables, we won't send partition key bind indexes. diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/BatchTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/BatchTest.java index 3790305..bc220fd 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/operations/BatchTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/BatchTest.java @@ -168,6 +168,26 @@ public class BatchTest extends CQLTester } @Test + public void testBatchMultipleTablePrepare() throws Throwable + { + String tbl1 = KEYSPACE + "." + createTableName(); + String tbl2 = KEYSPACE + "." + createTableName(); + + schemaChange(String.format("CREATE TABLE %s (k1 int PRIMARY KEY, v1 int)", tbl1)); + schemaChange(String.format("CREATE TABLE %s (k2 int PRIMARY KEY, v2 int)", tbl2)); + + String query = "BEGIN BATCH " + + String.format("UPDATE %s SET v1 = 1 WHERE k1 = ?;", tbl1) + + String.format("UPDATE %s SET v2 = 2 WHERE k2 = ?;", tbl2) + + "APPLY BATCH;"; + prepare(query); + execute(query, 0, 1); + + assertRows(execute(String.format("SELECT * FROM %s", tbl1)), row(0, 1)); + assertRows(execute(String.format("SELECT * FROM %s", tbl2)), row(1, 2)); + } + + @Test public void testBatchWithInRestriction() throws Throwable { createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a,b))"); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org