diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java index e1e4e9aeaa..b0633ea860 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterAdder.java @@ -88,14 +88,14 @@ public class CqlCounterAdder extends Operation { Integer stmntId = getPreparedStatement(client, cqlQuery); if (session.cqlVersion.startsWith("3")) - client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key))), session.getConsistencyLevel()); + client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes())), session.getConsistencyLevel()); else - client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key)))); + client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes()))); } else { if (formattedQuery == null) - formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key))); + formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3")))); if (session.cqlVersion.startsWith("3")) client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel()); else diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java index db99d0d75b..7feee5b301 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlCounterGetter.java @@ -89,14 +89,14 @@ public class CqlCounterGetter extends Operation { Integer stmntId = getPreparedStatement(client, cqlQuery); if (session.cqlVersion.startsWith("3")) - result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key))), session.getConsistencyLevel()); + result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key)), session.getConsistencyLevel()); else - result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key)))); + result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key))); } else { if (formattedQuery == null) - formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key))); + formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3")))); if (session.cqlVersion.startsWith("3")) result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel()); diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java index 5a18b30f34..b1fa85e048 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlIndexedRangeSlicer.java @@ -62,7 +62,7 @@ public class CqlIndexedRangeSlicer extends Operation if (session.cqlVersion.startsWith("2")) query.append(" USING CONSISTENCY ").append(session.getConsistencyLevel()); - query.append(" WHERE C1=").append(getUnQuotedCqlBlob(values.get(1).array())) + query.append(" WHERE C1=").append(getUnQuotedCqlBlob(values.get(1).array(), session.cqlVersion.startsWith("3"))) .append(" AND KEY > ? LIMIT ").append(session.getKeysPerCall()); cqlQuery = query.toString(); @@ -81,7 +81,7 @@ public class CqlIndexedRangeSlicer extends Operation String exceptionMessage = null; CqlResult results = null; String formattedQuery = null; - List queryParms = Collections.singletonList(getUnQuotedCqlBlob(startOffset)); + List queryParms = Collections.singletonList(getUnQuotedCqlBlob(startOffset, session.cqlVersion.startsWith("3"))); for (int t = 0; t < session.getRetryTimes(); t++) { diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java index 7a3eab99d0..ed03f1f439 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlInserter.java @@ -89,11 +89,11 @@ public class CqlInserter extends Operation for (int i = 0; i < session.getColumnsPerKey(); i++) { // Column value - queryParms.add(getUnQuotedCqlBlob(values.get(i % values.size()).array())); + queryParms.add(getUnQuotedCqlBlob(values.get(i % values.size()).array(), session.cqlVersion.startsWith("3"))); } String key = String.format("%0" + session.getTotalKeysLength() + "d", index); - queryParms.add(getUnQuotedCqlBlob(key)); + queryParms.add(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); String formattedQuery = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java index 0e27f671ad..acf06028cd 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlRangeSlicer.java @@ -82,14 +82,14 @@ public class CqlRangeSlicer extends Operation { Integer stmntId = getPreparedStatement(client, cqlQuery); if (session.cqlVersion.startsWith("3")) - result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key))), session.getConsistencyLevel()); + result = client.execute_prepared_cql3_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes())), session.getConsistencyLevel()); else - result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBufferUtil.bytes(getUnQuotedCqlBlob(key)))); + result = client.execute_prepared_cql_query(stmntId, Collections.singletonList(ByteBuffer.wrap(key.getBytes()))); } else { if (formattedQuery == null) - formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key))); + formattedQuery = formatCqlQuery(cqlQuery, Collections.singletonList(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3")))); if (session.cqlVersion.startsWith("3")) result = client.execute_cql3_query(ByteBuffer.wrap(formattedQuery.getBytes()), Compression.NONE, session.getConsistencyLevel()); else diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java b/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java index a7f9a090ba..58d77ddb81 100644 --- a/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java +++ b/tools/stress/src/org/apache/cassandra/stress/operations/CqlReader.java @@ -80,10 +80,10 @@ public class CqlReader extends Operation List queryParams = new ArrayList(); if (session.columnNames != null) for (int i = 0; i < session.columnNames.size(); i++) - queryParams.add(getUnQuotedCqlBlob(session.columnNames.get(i).array())); + queryParams.add(getUnQuotedCqlBlob(session.columnNames.get(i).array(), session.cqlVersion.startsWith("3"))); byte[] key = generateKey(); - queryParams.add(getUnQuotedCqlBlob(key)); + queryParams.add(getUnQuotedCqlBlob(key, session.cqlVersion.startsWith("3"))); String formattedQuery = null; diff --git a/tools/stress/src/org/apache/cassandra/stress/util/Operation.java b/tools/stress/src/org/apache/cassandra/stress/util/Operation.java index d5910f9b48..d1cfc22ee1 100644 --- a/tools/stress/src/org/apache/cassandra/stress/util/Operation.java +++ b/tools/stress/src/org/apache/cassandra/stress/util/Operation.java @@ -230,14 +230,16 @@ public abstract class Operation System.err.println(message); } - protected String getUnQuotedCqlBlob(String term) + protected String getUnQuotedCqlBlob(String term, boolean isCQL3) { - return getUnQuotedCqlBlob(term.getBytes()); + return getUnQuotedCqlBlob(term.getBytes(), isCQL3); } - protected String getUnQuotedCqlBlob(byte[] term) + protected String getUnQuotedCqlBlob(byte[] term, boolean isCQL3) { - return Hex.bytesToHex(term); + return isCQL3 + ? "0x" + Hex.bytesToHex(term) + : Hex.bytesToHex(term); } protected List queryParamsAsByteBuffer(List queryParams) @@ -246,7 +248,9 @@ public abstract class Operation { public ByteBuffer apply(String param) { - return ByteBufferUtil.bytes(param); + if (param.startsWith("0x")) + param = param.substring(2); + return ByteBufferUtil.hexToBytes(param); } }); } @@ -270,7 +274,7 @@ public abstract class Operation for (String parm : parms) { result.append(query.substring(position, marker)); - result.append('\'').append(parm).append('\''); + result.append(parm); position = marker + 1; if (-1 == (marker = query.indexOf('?', position + 1)))