Repository: cassandra Updated Branches: refs/heads/trunk f580fb0ff -> adbef7982
cassandra-stress should support case sensitive schemas patch by Giampaolo Trapasso; reviewed by tjake for CASSANDRA-11546 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/adbef798 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/adbef798 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/adbef798 Branch: refs/heads/trunk Commit: adbef79823e91627989ba3893931986ded510550 Parents: f580fb0 Author: Giampaolo Trapasso <[email protected]> Authored: Thu Apr 14 10:40:29 2016 +0200 Committer: T Jake Luciani <[email protected]> Committed: Fri May 6 09:52:55 2016 -0400 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../apache/cassandra/stress/StressProfile.java | 23 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/adbef798/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index c6b0af5..8e545c4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.8 + * cassandra-stress profiles should support case sensitive schemas (CASSANDRA-11546) * Remove DatabaseDescriptor dependency from FileUtils (CASSANDRA-11578) * Faster streaming (CASSANDRA-9766) http://git-wip-us.apache.org/repos/asf/cassandra/blob/adbef798/tools/stress/src/org/apache/cassandra/stress/StressProfile.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java index d7b0540..8b59bda 100644 --- a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java +++ b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java @@ -28,6 +28,7 @@ import java.io.Serializable; import java.net.URI; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; import com.google.common.base.Function; import com.google.common.util.concurrent.Uninterruptibles; @@ -87,6 +88,8 @@ public class StressProfile implements Serializable transient volatile Map<String, PreparedStatement> queryStatements; transient volatile Map<String, Integer> thriftQueryIds; + private static final Pattern lowercaseAlphanumeric = Pattern.compile("[a-z0-9_]+"); + private void init(StressYaml yaml) throws RequestValidationException { keyspaceName = yaml.keyspace; @@ -243,7 +246,7 @@ public class StressProfile implements Serializable TableMetadata metadata = client.getCluster() .getMetadata() .getKeyspace(keyspaceName) - .getTable(tableName); + .getTable(quoteIdentifier(tableName)); if (metadata == null) throw new RuntimeException("Unable to find table " + keyspaceName + "." + tableName); @@ -386,7 +389,7 @@ public class StressProfile implements Serializable StringBuilder sb = new StringBuilder(); if (!isKeyOnlyTable) { - sb.append("UPDATE \"").append(tableName).append("\" SET "); + sb.append("UPDATE ").append(quoteIdentifier(tableName)).append(" SET "); //PK Columns StringBuilder pred = new StringBuilder(); pred.append(" WHERE "); @@ -401,21 +404,21 @@ public class StressProfile implements Serializable else pred.append(" AND "); - pred.append(c.getName()).append(" = ?"); + pred.append(quoteIdentifier(c.getName())).append(" = ?"); } else { if (firstCol) firstCol = false; else sb.append(','); - sb.append(c.getName()).append(" = "); + sb.append(quoteIdentifier(c.getName())).append(" = "); switch (c.getType().getName()) { case SET: case LIST: case COUNTER: - sb.append(c.getName()).append(" + ?"); + sb.append(quoteIdentifier(c.getName())).append(" + ?"); break; default: sb.append("?"); @@ -429,11 +432,11 @@ public class StressProfile implements Serializable } else { - sb.append("INSERT INTO \"").append(tableName).append("\" ("); + sb.append("INSERT INTO ").append(quoteIdentifier(tableName)).append(" ("); StringBuilder value = new StringBuilder(); for (ColumnMetadata c : tableMetaData.getPrimaryKey()) { - sb.append(c.getName()).append(", "); + sb.append(quoteIdentifier(c.getName())).append(", "); value.append("?, "); } sb.delete(sb.lastIndexOf(","), sb.length()); @@ -692,4 +695,10 @@ public class StressProfile implements Serializable for (Map.Entry<String, V> e : reinsert) map.put(e.getKey().toLowerCase(), e.getValue()); } + + /* Quote a identifier if it contains uppercase letters */ + private static String quoteIdentifier(String identifier) + { + return lowercaseAlphanumeric.matcher(identifier).matches() ? identifier : '\"'+identifier+ '\"'; + } }
