Author: jake
Date: Fri Aug 26 15:43:39 2011
New Revision: 1162143
URL: http://svn.apache.org/viewvc?rev=1162143&view=rev
Log:
Change cli to use hashes rather than array of hashes for strategy options
Patch by tjake; reviewed by xedin for CASSANDRA-3081
Modified:
cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g
cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
cassandra/trunk/src/resources/org/apache/cassandra/cli/CliHelp.yaml
cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java
Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g?rev=1162143&r1=1162142&r2=1162143&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g Fri Aug 26 15:43:39
2011
@@ -388,11 +388,12 @@ keyValuePairExpr
keyValuePair
: attr_name '=' attrValue
- -> attr_name attrValue
+ -> attr_name attrValue
;
attrValue
: arrayConstruct
+ | hashConstruct
| attrValueString
| attrValueInt
| attrValueDouble
@@ -410,8 +411,8 @@ hashConstruct
;
hashElementPair
- : rowKey ':' value
- -> ^(PAIR rowKey value)
+ : rowKey ':' rowValue
+ -> ^(PAIR rowKey rowValue)
;
columnFamilyExpr
@@ -428,70 +429,74 @@ keyRangeExpr
;
columnName
- : (StringLiteral | Identifier | IntegerPositiveLiteral |
IntegerNegativeLiteral)
- ;
+ : (StringLiteral | Identifier | IntegerPositiveLiteral |
IntegerNegativeLiteral)
+ ;
attr_name
- : Identifier
- ;
+ : Identifier
+ ;
attrValueString
- : (Identifier | StringLiteral)
- ;
+ : (Identifier | StringLiteral)
+ ;
attrValueInt
- : IntegerPositiveLiteral
+ : IntegerPositiveLiteral
| IntegerNegativeLiteral
- ;
+ ;
attrValueDouble
- : DoubleLiteral
- ;
+ : DoubleLiteral
+ ;
objectName
- : Identifier
- ;
+ : Identifier
+ ;
keyspace
- : Identifier
- ;
+ : Identifier
+ ;
replica_placement_strategy
- : StringLiteral
- ;
+ : StringLiteral
+ ;
keyspaceNewName
- : Identifier
- ;
+ : Identifier
+ ;
comparator
- : StringLiteral
- ;
+ : StringLiteral
+ ;
-command : Identifier
- ;
+command : Identifier
+ ;
newColumnFamily
- : Identifier
- ;
+ : Identifier
+ ;
username: Identifier
- ;
+ ;
password: StringLiteral
- ;
+ ;
columnFamily
- : Identifier
- ;
+ : Identifier
+ ;
-rowKey
+rowKey
: (Identifier | StringLiteral | IntegerPositiveLiteral |
IntegerNegativeLiteral | functionCall)
- ;
+ ;
+
+rowValue
+ : (Identifier | StringLiteral | IntegerPositiveLiteral |
IntegerNegativeLiteral | functionCall | hashConstruct)
+ ;
-value
+value
: (Identifier | IntegerPositiveLiteral | IntegerNegativeLiteral |
StringLiteral | functionCall)
- ;
+ ;
functionCall
: functionName=Identifier '(' functionArgument? ')'
@@ -504,34 +509,34 @@ functionArgument
startKey
: (Identifier | StringLiteral)
- ;
+ ;
-endKey
+endKey
: (Identifier | StringLiteral)
- ;
+ ;
columnOrSuperColumn
- : (Identifier | IntegerPositiveLiteral | IntegerNegativeLiteral |
StringLiteral | functionCall)
- ;
+ : (Identifier | IntegerPositiveLiteral | IntegerNegativeLiteral |
StringLiteral | functionCall)
+ ;
-host
+host
: host_name
-> ^(NODE_ID_LIST host_name)
- ;
+ ;
host_name
- : Identifier ('.' Identifier)*
- ;
-
+ : Identifier ('.' Identifier)*
+ ;
+
ip_address
- : IP_ADDRESS
- -> ^(NODE_ID_LIST IP_ADDRESS)
- ;
+ : IP_ADDRESS
+ -> ^(NODE_ID_LIST IP_ADDRESS)
+ ;
-port
+port
: IntegerPositiveLiteral
- ;
+ ;
incrementValue
: IntegerPositiveLiteral
@@ -628,52 +633,52 @@ StringLiteral
;
fragment SingleStringCharacter
- : ~('\'' | '\\')
- | '\\' EscapeSequence
- ;
+ : ~('\'' | '\\')
+ | '\\' EscapeSequence
+ ;
fragment EscapeSequence
- : CharacterEscapeSequence
- | '0'
- | HexEscapeSequence
- | UnicodeEscapeSequence
- ;
+ : CharacterEscapeSequence
+ | '0'
+ | HexEscapeSequence
+ | UnicodeEscapeSequence
+ ;
fragment CharacterEscapeSequence
- : SingleEscapeCharacter
- | NonEscapeCharacter
- ;
+ : SingleEscapeCharacter
+ | NonEscapeCharacter
+ ;
fragment NonEscapeCharacter
- : ~(EscapeCharacter)
- ;
+ : ~(EscapeCharacter)
+ ;
fragment SingleEscapeCharacter
- : '\'' | '"' | '\\' | 'b' | 'f' | 'n' | 'r' | 't' | 'v'
- ;
+ : '\'' | '"' | '\\' | 'b' | 'f' | 'n' | 'r' | 't' | 'v'
+ ;
fragment EscapeCharacter
- : SingleEscapeCharacter
- | DecimalDigit
- | 'x'
- | 'u'
- ;
+ : SingleEscapeCharacter
+ | DecimalDigit
+ | 'x'
+ | 'u'
+ ;
fragment HexEscapeSequence
- : 'x' HexDigit HexDigit
- ;
+ : 'x' HexDigit HexDigit
+ ;
fragment UnicodeEscapeSequence
- : 'u' HexDigit HexDigit HexDigit HexDigit
- ;
+ : 'u' HexDigit HexDigit HexDigit HexDigit
+ ;
fragment HexDigit
- : DecimalDigit | ('a'..'f') | ('A'..'F')
- ;
+ : DecimalDigit | ('a'..'f') | ('A'..'F')
+ ;
fragment DecimalDigit
- : ('0'..'9')
- ;
+ : ('0'..'9')
+ ;
//
// syntactic elements
Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java?rev=1162143&r1=1162142&r2=1162143&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Fri Aug 26
15:43:39 2011
@@ -2386,24 +2386,18 @@ public class CliClient
{
// this map will be returned
Map<String, String> strategyOptions = new HashMap<String, String>();
+
+ // each child node is ^(PAIR $key $value)
+ for (int j = 0; j < options.getChildCount(); j++)
+ {
+ Tree optionPair = options.getChild(j);
+
+ // current $key
+ String key =
CliUtils.unescapeSQLString(optionPair.getChild(0).getText());
+ // current $value
+ String val =
CliUtils.unescapeSQLString(optionPair.getChild(1).getText());
- // each child node is a ^(HASH ...)
- for (int i = 0; i < options.getChildCount(); i++)
- {
- Tree optionsHash = options.getChild(i);
-
- // each child node is ^(PAIR $key $value)
- for (int j = 0; j < optionsHash.getChildCount(); j++)
- {
- Tree optionPair = optionsHash.getChild(j);
-
- // current $key
- String key =
CliUtils.unescapeSQLString(optionPair.getChild(0).getText());
- // current $value
- String val =
CliUtils.unescapeSQLString(optionPair.getChild(1).getText());
-
- strategyOptions.put(key, val);
- }
+ strategyOptions.put(key, val);
}
return strategyOptions;
Modified: cassandra/trunk/src/resources/org/apache/cassandra/cli/CliHelp.yaml
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/resources/org/apache/cassandra/cli/CliHelp.yaml?rev=1162143&r1=1162142&r2=1162143&view=diff
==============================================================================
--- cassandra/trunk/src/resources/org/apache/cassandra/cli/CliHelp.yaml
(original)
+++ cassandra/trunk/src/resources/org/apache/cassandra/cli/CliHelp.yaml Fri Aug
26 15:43:39 2011
@@ -246,7 +246,7 @@ commands:
specifies the replication factor for the cluster.
- strategy_options: Optional additional options for placement_strategy.
- Options have the form [{key:value}], see the information on each
+ Options have the form {key:value}, see the information on each
strategy and the examples.
- durable_writes: When set to false all RowMutations on keyspace will
by-pass CommitLog.
@@ -255,13 +255,13 @@ commands:
Examples:
create keyspace Keyspace2
with placement_strategy =
'org.apache.cassandra.locator.SimpleStrategy'
- and strategy_options = [{replication_factor:4}];
+ and strategy_options = {replication_factor:4};
create keyspace Keyspace3
with placement_strategy =
'org.apache.cassandra.locator.NetworkTopologyStrategy'
- and strategy_options=[{DC1:2, DC2:2}];
+ and strategy_options={DC1:2, DC2:2};
create keyspace Keyspace4
with placement_strategy =
'org.apache.cassandra.locator.OldNetworkTopologyStrategy'
- and strategy_options = [{replication_factor:1}];
+ and strategy_options = {replication_factor:1};
- name: NODE_UPDATE_KEYSPACE
help: |
update keyspace <keyspace>;
@@ -314,7 +314,7 @@ commands:
specifies the replication factor for the cluster.
- strategy_options: Optional additional options for placement_strategy.
- Options have the form [{key:value}], see the information on each
+ Options have the form {key:value}, see the information on each
strategy and the examples.
- durable_writes: When set to false all RowMutations on keyspace will
by-pass CommitLog.
@@ -323,13 +323,13 @@ commands:
Examples:
update keyspace Keyspace2
with placement_strategy =
'org.apache.cassandra.locator.SimpleStrategy'
- and strategy_options = [{replication_factor:4}];
+ and strategy_options = {replication_factor:4};
update keyspace Keyspace3
with placement_strategy =
'org.apache.cassandra.locator.NetworkTopologyStrategy'
- and strategy_options=[{DC1:2, DC2:2}];
+ and strategy_options={DC1:2, DC2:2};
update keyspace Keyspace4
with placement_strategy =
'org.apache.cassandra.locator.OldNetworkTopologyStrategy'
- and strategy_options = [{replication_factor:1}];
+ and strategy_options = {replication_factor:1};
- name: NODE_ADD_COLUMN_FAMILY
help: |
create column family <name>;
Modified: cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java?rev=1162143&r1=1162142&r2=1162143&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java Fri Aug 26
15:43:39 2011
@@ -121,7 +121,7 @@ public class CliTest extends CleanupHelp
"drop index on CF1.617070;",
"drop index on CF1.'-617071';",
"update keyspace TestKeySpace with
placement_strategy='org.apache.cassandra.locator.LocalStrategy' and
durable_writes = false;",
- "update keyspace TestKeySpace with strategy_options=[{DC1:3, DC2:4,
DC5:1}];",
+ "update keyspace TestKeySpace with strategy_options={DC1:3, DC2:4,
DC5:1};",
"assume CF1 comparator as utf8;",
"assume CF1 sub_comparator as integer;",
"assume CF1 validator as lexicaluuid;",
@@ -158,7 +158,7 @@ public class CliTest extends CleanupHelp
"set Countries[1][name] = USA;",
"get Countries[1][name];",
"update column family Countries with compaction_strategy =
'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy';",
- "create column family Cities with compaction_strategy =
'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy' and
compaction_strategy_options = [{min_sstable_size:1024}];",
+ "create column family Cities with compaction_strategy =
'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy' and
compaction_strategy_options = {min_sstable_size:1024};",
"set myCF['key']['scName']['firstname'] = 'John';",
"get myCF['key']['scName']",
"assume CF3 keys as utf8;",