re-add support for using KEY in a select even when that is not the defined alias, for backwards compatibility. Add case-insensitivity for the actual alias.
patch by jbellis; reviewed by pyaskevich for CASSANDRA-3700 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e2231a19 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e2231a19 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e2231a19 Branch: refs/heads/trunk Commit: e2231a19711009659f791c372837852b604d9816 Parents: 044eb1e Author: Jonathan Ellis <jbel...@apache.org> Authored: Tue Jan 10 12:36:04 2012 -0600 Committer: Jonathan Ellis <jbel...@apache.org> Committed: Tue Jan 10 12:52:45 2012 -0600 ---------------------------------------------------------------------- src/java/org/apache/cassandra/cql/WhereClause.java | 20 ++++++++++---- 1 files changed, 14 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/e2231a19/src/java/org/apache/cassandra/cql/WhereClause.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql/WhereClause.java b/src/java/org/apache/cassandra/cql/WhereClause.java index 964aad8..129de65 100644 --- a/src/java/org/apache/cassandra/cql/WhereClause.java +++ b/src/java/org/apache/cassandra/cql/WhereClause.java @@ -21,6 +21,7 @@ package org.apache.cassandra.cql; */ import java.nio.ByteBuffer; +import java.nio.charset.CharacterCodingException; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -142,20 +143,27 @@ public class WhereClause public void extractKeysFromColumns(CFMetaData cfm) { - ByteBuffer realKeyAlias = cfm.getKeyName(); + String realKeyAlias = null; + try + { + // ThriftValidation ensures that key_alias is ascii + realKeyAlias = ByteBufferUtil.string(cfm.getKeyName()).toUpperCase(); + } + catch (CharacterCodingException e) + { + throw new RuntimeException(e); + } if (!keys.isEmpty()) return; // we already have key(s) set (<key> IN (.., ...) construction used) for (Relation relation : clauseRelations) { - String nameText = relation.getEntity().getText(); - ByteBuffer name = ByteBufferUtil.bytes(nameText); - - if (name.equals(realKeyAlias)) + String name = relation.getEntity().getText().toUpperCase(); + if (name.equals(realKeyAlias) || name.equals("KEY")) { if (keyAlias == null) // setting found key as an alias - keyAlias = nameText.toUpperCase(); + keyAlias = name; if (relation.operator() == RelationType.EQ) {