Updated Branches:
  refs/heads/cassandra-1.2 e7061901a -> 66599611d
  refs/heads/trunk ae26aab47 -> 3f8790769


quote identifiers in CqlPagingRecordReader
patch by Piotr Kołaczkowski; reviewed by jbellis for CASSANDRA-5763


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

Branch: refs/heads/cassandra-1.2
Commit: 66599611d585ec600bfdceed14868889e0cb423b
Parents: e706190
Author: Jonathan Ellis <jbel...@apache.org>
Authored: Mon Jul 15 17:37:31 2013 -0500
Committer: Jonathan Ellis <jbel...@apache.org>
Committed: Mon Jul 15 17:37:31 2013 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../hadoop/cql3/CqlPagingRecordReader.java      | 20 +++++++++++++-------
 2 files changed, 14 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/66599611/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index ee277aa..00148a3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 1.2.7
+ * (Hadoop) quote identifiers in CqlPagingRecordReader (CASSANDRA-5763)
  * Add replace_node functionality for vnodes (CASSANDRA-5337)
  * Add timeout events to query traces (CASSANDRA-5520)
  * make starting native protocol server idempotent (CASSANDRA-5728)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/66599611/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java 
b/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
index 55f67cc..c9842d0 100644
--- a/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
+++ b/src/java/org/apache/cassandra/hadoop/cql3/CqlPagingRecordReader.java
@@ -430,13 +430,13 @@ public class CqlPagingRecordReader extends 
RecordReader<Map<String, ByteBuffer>,
 
                 columns = withoutKeyColumns(columns);
                 columns = (clusterKey == null || "".equals(clusterKey))
-                        ? partitionKey + "," + columns
-                        : partitionKey + "," + clusterKey + "," + columns;
+                        ? quote(partitionKey) + "," + columns
+                        : quote(partitionKey) + "," + quote(clusterKey) + "," 
+ columns;
             }
 
             return Pair.create(clause.left,
                                "SELECT " + columns
-                               + " FROM " + cfName
+                               + " FROM " + quote(cfName)
                                + clause.right
                                + (userDefinedWhereClauses == null ? "" : " AND 
" + userDefinedWhereClauses)
                                + " LIMIT " + pageRowSize
@@ -459,7 +459,8 @@ public class CqlPagingRecordReader extends 
RecordReader<Map<String, ByteBuffer>,
                 if (keyNames.contains(trimmed))
                     continue;
 
-                result = result == null ? trimmed : result + "," + trimmed;
+                String quoted = quote(trimmed);
+                result = result == null ? quoted : result + "," + quoted;
             }
             return result;
         }
@@ -492,10 +493,10 @@ public class CqlPagingRecordReader extends 
RecordReader<Map<String, ByteBuffer>,
         private Pair<Integer, String> whereClause(List<BoundColumn> column, 
int position)
         {
             if (position == column.size() - 1 || column.get(position + 
1).value == null)
-                return Pair.create(position + 2, " AND " + 
column.get(position).name + " > ? ");
+                return Pair.create(position + 2, " AND " + 
quote(column.get(position).name) + " > ? ");
 
             Pair<Integer, String> clause = whereClause(column, position + 1);
-            return Pair.create(clause.left, " AND " + 
column.get(position).name + " = ? " + clause.right);
+            return Pair.create(clause.left, " AND " + 
quote(column.get(position).name) + " = ? " + clause.right);
         }
 
         /** check whether all key values are null */
@@ -514,7 +515,7 @@ public class CqlPagingRecordReader extends 
RecordReader<Map<String, ByteBuffer>,
         {
             String result = null;
             for (BoundColumn column : columns)
-                result = result == null ? column.name : result + "," + 
column.name;
+                result = result == null ? quote(column.name) : result + "," + 
quote(column.name);
 
             return result == null ? "" : result;
         }
@@ -591,6 +592,11 @@ public class CqlPagingRecordReader extends 
RecordReader<Map<String, ByteBuffer>,
             return cqlPreparedResult.itemId;
         }
 
+        /** Quoting for working with uppercase */
+        private String quote(String identifier) {
+            return "\"" + identifier.replaceAll("\"", "\"\"") + "\"";
+        }
+
         /** execute the prepared query */
         private void executeQuery()
         {

Reply via email to