Author: jbellis
Date: Wed Oct 20 15:59:32 2010
New Revision: 1025623
URL: http://svn.apache.org/viewvc?rev=1025623&view=rev
Log:
remove supercolumn option from cli list command; clean up grammar and fix limit
support.
patch by jbellis and Jim Ancona for CASSANDRA-1619
Modified:
cassandra/trunk/CHANGES.txt
cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g
cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java
Modified: cassandra/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1025623&r1=1025622&r2=1025623&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Wed Oct 20 15:59:32 2010
@@ -38,7 +38,7 @@ dev
avoid synchronization bottleneck (CASSANDRA-1481)
* PropertyFileSnitch configuration file renamed to
cassandra-topology.properties
- * add cli support for get_range_slices (CASSANDRA-1088)
+ * add cli support for get_range_slices (CASSANDRA-1088, CASSANDRA-1619)
* Make memtable flush thresholds per-CF instead of global (CASSANDRA-1007)
* add cli support for binary data without CfDef hints (CASSANDRA-1603)
* fix building SSTable statistics post-stream (CASSANDRA-1620)
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=1025623&r1=1025622&r2=1025623&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g Wed Oct 20 15:59:32
2010
@@ -68,7 +68,7 @@ tokens {
PAIR;
NODE_LIMIT;
- NODE_KEY_RANGE_ACCESS;
+ NODE_KEY_RANGE;
}
@parser::header {
@@ -213,12 +213,8 @@ showStatement
;
listStatement
- : K_LIST keyRangeExpr limitClause?
- -> ^(NODE_LIST keyRangeExpr limitClause?)
- ;
-
-limitClause
- : K_LIMIT^ IntegerLiteral
+ : K_LIST columnFamily keyRangeExpr? ('LIMIT' limit=IntegerLiteral)?
+ -> ^(NODE_LIST columnFamily keyRangeExpr? ^(NODE_LIMIT $limit)?)
;
showClusterName
@@ -319,10 +315,10 @@ columnFamilyExpr
;
keyRangeExpr
- : columnFamily '[' startKey ':' endKey ']' ('[' columnOrSuperColumn
']')?
- -> ^(NODE_KEY_RANGE_ACCESS columnFamily startKey endKey
columnOrSuperColumn?)
+ : '[' ( startKey? ':' endKey? )? ']'
+ -> ^(NODE_KEY_RANGE startKey? endKey?)
;
-
+
table: Identifier;
columnName: Identifier;
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=1025623&r1=1025622&r2=1025623&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Wed Oct 20
15:59:32 2010
@@ -413,11 +413,13 @@ public class CliClient
break;
case CliParser.NODE_LIST:
- css_.out.println("list <cf>['<startKey>':'<endKey']\n");
- css_.out.println("list <cf>['<startKey>':'<endKey'] limit
M\n");
- css_.out.println("list
<cf>['<startKey>':'<endKey']['<super>']\n");
- css_.out.println("list <cf>['<startKey>':'<endKey']['<super>']
limit M\n");
+ css_.out.println("list <cf>");
+ css_.out.println("list <cf>[<startKey>:]");
+ css_.out.println("list <cf>[<startKey>:<endKey>]");
+ css_.out.println("list ... limit N");
css_.out.println("List a range of rows in the column or
supercolumn family.\n");
+ css_.out.println("example:");
+ css_.out.println("list Users[j:] limit 40");
break;
default:
@@ -462,8 +464,11 @@ public class CliClient
css_.out.println("del <cf>['<key>']['<super>']['<col>']
Delete sub column.");
css_.out.println("count <cf>['<key>']
Count columns in record.");
css_.out.println("count <cf>['<key>']['<super>']
Count columns in a super column.");
- css_.out.println("list <cf>['<startKey>':'<endKey']
List rows in the column family.");
- css_.out.println("list <cf>['<startKey>':'<endKey']['<super>']
List the super column across rows.");
+ css_.out.println("list <cf> List
all rows in the column family.");
+ css_.out.println("list <cf>[<startKey>:]");
+ css_.out.println(" List rows in the column
family beginning with <startKey>.");
+ css_.out.println("list <cf>[<startKey>:<endKey>]");
+ css_.out.println(" List rows in the column family in the
range from <startKey> to <endKey>.");
css_.out.println("list ... limit N
Limit the list results to N.");
}
}
@@ -1086,32 +1091,51 @@ public class CliClient
if (!CliMain.isConnected())
return;
- // AST check
- assert (ast.getChildCount() == 1 || ast.getChildCount() == 2) :
"Incorrect AST Construct!";
+ assert (ast.getChildCount() >= 1 || ast.getChildCount() <= 3) :
"Incorrect AST Construct!";
+ Iterator<CommonTree> iter = ast.getChildren().iterator();
- CommonTree keyRangeSpec = (CommonTree) ast.getChild(0);
- assert (keyRangeSpec.getType() == CliParser.NODE_KEY_RANGE_ACCESS);
+ // extract column family
+ String columnFamily = iter.next().getText();
- // extract key range, column family, and super column name
- String columnFamily = keyRangeSpec.getChild(0).getText();
- String startKey =
CliUtils.unescapeSQLString(keyRangeSpec.getChild(1).getText());
- String endKey =
CliUtils.unescapeSQLString(keyRangeSpec.getChild(2).getText());
+ String startKey = "";
+ String endKey = "";
+ int limitCount = Integer.MAX_VALUE; // will reset to default later if
it's not specified
- String superColumnName = null;
- if (keyRangeSpec.getChildCount() == 4)
+ // optional arguments: key range and limit
+ while (iter.hasNext())
{
- superColumnName =
CliUtils.unescapeSQLString(keyRangeSpec.getChild(3).getText());
+ CommonTree child = iter.next();
+ if (child.getType() == CliParser.NODE_KEY_RANGE)
+ {
+ if (child.getChildCount() > 0)
+ {
+ startKey =
CliUtils.unescapeSQLString(child.getChild(0).getText());
+ if (child.getChildCount() > 1)
+ endKey =
CliUtils.unescapeSQLString(child.getChild(1).getText());
+ }
+ }
+ else
+ {
+ assert child.getType() == CliParser.NODE_LIMIT;
+ if (child.getChildCount() != 1)
+ {
+ css_.out.println("Invalid limit clause");
+ return;
+ }
+ limitCount = Integer.parseInt(child.getChild(0).getText());
+ if (limitCount <= 0)
+ {
+ css_.out.println("Invalid limit " + limitCount);
+ return;
+ }
+ }
}
- // extract LIMIT clause
- int limitCount = Integer.MAX_VALUE;
- if (ast.getChildCount() == 2)
+ if (limitCount == Integer.MAX_VALUE)
{
- CommonTree limitSpec = (CommonTree) ast.getChild(1);
- assert (limitSpec.getType() == CliParser.NODE_LIMIT);
- limitCount = Integer.parseInt(limitSpec.getChild(0).getText());
+ limitCount = 100;
+ css_.out.println("Using default limit of 100");
}
- assert (limitCount > 0) : "Limit count should be > 0!";
List<String> cfnames = new ArrayList<String>();
for (CfDef cfd : keyspacesMap.get(keySpace).cf_defs)
@@ -1133,19 +1157,12 @@ public class CliClient
predicate.setSlice_range(sliceRange);
// set the key range
- KeyRange range = new KeyRange(10);
+ KeyRange range = new KeyRange(limitCount);
range.setStart_key(startKey.getBytes()).setEnd_key(endKey.getBytes());
ColumnParent columnParent = new ColumnParent(columnFamily);
- if (StringUtils.isNotBlank(superColumnName))
- {
- columnParent.setSuper_column(superColumnName.getBytes());
- }
-
List<KeySlice> keySlices =
thriftClient_.get_range_slices(columnParent, predicate, range,
ConsistencyLevel.ONE);
int toIndex = keySlices.size();
- if (limitCount < keySlices.size()) // limitCount could be
Integer.MAX_VALUE
- toIndex = limitCount;
List<KeySlice> limitSlices = keySlices.subList(0, toIndex);
for (KeySlice ks : limitSlices)
@@ -1175,7 +1192,7 @@ public class CliClient
}
}
- css_.out.printf("\n%d Row%s Returned.\n", limitSlices.size(),
(limitSlices.size() > 1 ? "s" : ""));
+ css_.out.printf("\n%d row%s returned\n", toIndex, (toIndex == 0 ||
toIndex > 1 ? "s" : ""));
}
private void executeShowVersion() throws TException
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=1025623&r1=1025622&r2=1025623&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/cli/CliTest.java Wed Oct 20
15:59:32 2010
@@ -46,6 +46,11 @@ public class CliTest extends TestCase
"create column family CF3 with comparator=UTF8Type and
column_metadata=[{column_name:'big world', validation_class:LongType}]",
"set CF3['hello']['big world'] = 3748",
"get CF3['hello']['big world']",
+ "list CF3",
+ "list CF3[:]",
+ "list CF3[h:]",
+ "list CF3 limit 10",
+ "list CF3[h:g] limit 10",
"update keyspace TestKeySpace with
placement_strategy='org.apache.cassandra.locator.LocalStrategy'",
"update keyspace TestKeySpace with replication_factor=1 and
strategy_options=[{DC1:3, DC2:4, DC5:1}]"
};