Repository: cassandra Updated Branches: refs/heads/trunk 7a4752843 -> 270a05d63
Fix NPE when passing wrong argument in ALTER TABLE statement patch by Benjamin Lerer; reviewed by Robert Stupp for CASSANDRA-8355 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/25d4a13d Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/25d4a13d Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/25d4a13d Branch: refs/heads/trunk Commit: 25d4a13d5621f11290af83b81b0be1588ffc87db Parents: cf07fc2 Author: Benjamin Lerer <b_le...@hotmail.com> Authored: Wed Jan 14 19:18:49 2015 +0300 Committer: Aleksey Yeschenko <alek...@apache.org> Committed: Wed Jan 14 19:18:49 2015 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + src/java/org/apache/cassandra/cql3/Cql.g | 15 +++++++++------ .../org/apache/cassandra/cql3/AlterTableTest.java | 11 +++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/25d4a13d/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 175a78a..8f312a7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.1.3 + * Fix NPE when passing wrong argument in ALTER TABLE statement (CASSANDRA-8355) * Pig: Refactor and deprecate CqlStorage (CASSANDRA-8599) * Don't reuse the same cleanup strategy for all sstables (CASSANDRA-8537) * Fix case-sensitivity of index name on CREATE and DROP INDEX http://git-wip-us.apache.org/repos/asf/cassandra/blob/25d4a13d/src/java/org/apache/cassandra/cql3/Cql.g ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g index eda0529..9067fc4 100644 --- a/src/java/org/apache/cassandra/cql3/Cql.g +++ b/src/java/org/apache/cassandra/cql3/Cql.g @@ -942,16 +942,19 @@ functionName returns [String s] | K_TOKEN { $s = "token"; } ; -functionArgs returns [List<Term.Raw> a] - : '(' ')' { $a = Collections.emptyList(); } - | '(' t1=term { List<Term.Raw> args = new ArrayList<Term.Raw>(); args.add(t1); } - ( ',' tn=term { args.add(tn); } )* - ')' { $a = args; } +function returns [Term.Raw t] + : f=functionName '(' ')' { $t = new FunctionCall.Raw(f, Collections.<Term.Raw>emptyList()); } + | f=functionName '(' args=functionArgs ')' { $t = new FunctionCall.Raw(f, args); } + ; + +functionArgs returns [List<Term.Raw> args] + @init{ $args = new ArrayList<Term.Raw>(); } + : t1=term {args.add(t1); } ( ',' tn=term { args.add(tn); } )* ; term returns [Term.Raw term] : v=value { $term = v; } - | f=functionName args=functionArgs { $term = new FunctionCall.Raw(f, args); } + | f=function { $term = f; } | '(' c=comparatorType ')' t=term { $term = new TypeCast(c, t); } ; http://git-wip-us.apache.org/repos/asf/cassandra/blob/25d4a13d/test/unit/org/apache/cassandra/cql3/AlterTableTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/AlterTableTest.java b/test/unit/org/apache/cassandra/cql3/AlterTableTest.java index f5747ed..9668a41 100644 --- a/test/unit/org/apache/cassandra/cql3/AlterTableTest.java +++ b/test/unit/org/apache/cassandra/cql3/AlterTableTest.java @@ -19,8 +19,6 @@ package org.apache.cassandra.cql3; import org.junit.Test; -import org.apache.cassandra.exceptions.InvalidRequestException; - public class AlterTableTest extends CQLTester { @Test @@ -83,4 +81,13 @@ public class AlterTableTest extends CQLTester assertInvalid("ALTER TABLE %s ADD myCollection map<int, int>;"); } + + @Test + public void testChangeStrategyWithUnquotedAgrument() throws Throwable + { + createTable("CREATE TABLE %s (id text PRIMARY KEY);"); + + assertInvalidSyntaxMessage("no viable alternative at input '}'", + "ALTER TABLE %s WITH caching = {'keys' : 'all', 'rows_per_partition' : ALL};"); + } }