cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject cassandra git commit: cassandra-stress: cannot handle "value-less" tables
Date Mon, 28 Mar 2016 17:32:28 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk ca2e71c38 -> 5beedbc66


cassandra-stress: cannot handle "value-less" tables

patch by Cheng Ren reviewed by Robert Stupp for CASSANDRA-7739


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5beedbc6
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5beedbc6
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5beedbc6

Branch: refs/heads/trunk
Commit: 5beedbc6628fa00f6c38906cac441d7b6d260fff
Parents: ca2e71c
Author: Cheng Ren <cheng.ren@bloomreach.com>
Authored: Mon Mar 28 19:30:22 2016 +0200
Committer: Robert Stupp <snazy@snazy.de>
Committed: Mon Mar 28 19:30:22 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../apache/cassandra/stress/StressProfile.java  | 91 ++++++++++++--------
 2 files changed, 58 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5beedbc6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8e9cc44..307f8ab 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.6
+ * cassandra-stress: cannot handle "value-less" tables (CASSANDRA-7739)
  * Add/drop multiple columns in one ALTER TABLE statement (CASSANDRA-10411)
  * Add require_endpoint_verification opt for internode encryption (CASSANDRA-9220)
  * Add auto import java.util for UDF code block (CASSANDRA-11392)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5beedbc6/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 5243d96..d7b0540 100644
--- a/tools/stress/src/org/apache/cassandra/stress/StressProfile.java
+++ b/tools/stress/src/org/apache/cassandra/stress/StressProfile.java
@@ -368,41 +368,50 @@ public class StressProfile implements Serializable
                     maybeLoadSchemaInfo(settings);
 
                     Set<ColumnMetadata> keyColumns = com.google.common.collect.Sets.newHashSet(tableMetaData.getPrimaryKey());
-
-                    //Non PK Columns
-                    StringBuilder sb = new StringBuilder();
-
-                    sb.append("UPDATE \"").append(tableName).append("\" SET ");
-
-                    //PK Columns
-                    StringBuilder pred = new StringBuilder();
-                    pred.append(" WHERE ");
-
-                    boolean firstCol = true;
-                    boolean firstPred = true;
-                    for (ColumnMetadata c : tableMetaData.getColumns())
+                    Set<ColumnMetadata> allColumns = com.google.common.collect.Sets.newHashSet(tableMetaData.getColumns());
+                    boolean isKeyOnlyTable = (keyColumns.size() == allColumns.size());
+                    //With compact storage
+                    if (!isKeyOnlyTable && (keyColumns.size() == (allColumns.size()
- 1)))
                     {
-
-                        if (keyColumns.contains(c))
+                        com.google.common.collect.Sets.SetView diff = com.google.common.collect.Sets.difference(allColumns,
keyColumns);
+                        for (Object obj : diff)
                         {
-                            if (firstPred)
-                                firstPred = false;
-                            else
-                                pred.append(" AND ");
-
-                            pred.append(c.getName()).append(" = ?");
+                            ColumnMetadata col = (ColumnMetadata)obj;
+                            isKeyOnlyTable = col.getName().isEmpty();
+                            break;
                         }
-                        else
-                        {
-                            if (firstCol)
-                                firstCol = false;
-                            else
-                                sb.append(",");
-
-                            sb.append(c.getName()).append(" = ");
+                    }
 
-                            switch (c.getType().getName())
-                            {
+                    //Non PK Columns
+                    StringBuilder sb = new StringBuilder();
+                    if (!isKeyOnlyTable)
+                    {
+                        sb.append("UPDATE \"").append(tableName).append("\" SET ");
+                        //PK Columns
+                        StringBuilder pred = new StringBuilder();
+                        pred.append(" WHERE ");
+
+                        boolean firstCol = true;
+                        boolean firstPred = true;
+                        for (ColumnMetadata c : tableMetaData.getColumns()) {
+
+                            if (keyColumns.contains(c)) {
+                                if (firstPred)
+                                    firstPred = false;
+                                else
+                                    pred.append(" AND ");
+
+                                pred.append(c.getName()).append(" = ?");
+                            } else {
+                                if (firstCol)
+                                    firstCol = false;
+                                else
+                                    sb.append(',');
+
+                                sb.append(c.getName()).append(" = ");
+
+                                switch (c.getType().getName())
+                                {
                                 case SET:
                                 case LIST:
                                 case COUNTER:
@@ -411,12 +420,26 @@ public class StressProfile implements Serializable
                                 default:
                                     sb.append("?");
                                     break;
+                                }
                             }
                         }
-                    }
 
-                    //Put PK predicates at the end
-                    sb.append(pred);
+                        //Put PK predicates at the end
+                        sb.append(pred);
+                    }
+                    else
+                    {
+                        sb.append("INSERT INTO \"").append(tableName).append("\" (");
+                        StringBuilder value = new StringBuilder();
+                        for (ColumnMetadata c : tableMetaData.getPrimaryKey())
+                        {
+                            sb.append(c.getName()).append(", ");
+                            value.append("?, ");
+                        }
+                        sb.delete(sb.lastIndexOf(","), sb.length());
+                        value.delete(value.lastIndexOf(","), value.length());
+                        sb.append(") ").append("values(").append(value).append(')');
+                    }
 
                     if (insert == null)
                         insert = new HashMap<>();


Mime
View raw message