CLI `list <CF>` to limit number of columns and their order patch by Dave Brosius; reviewed by Pavel Yaskevich for CASSANDRA-3012
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/18c5441c Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/18c5441c Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/18c5441c Branch: refs/heads/cassandra-1.1 Commit: 18c5441cc83fb4fae5e537ad63453e5319453da8 Parents: eb68247 Author: Pavel Yaskevich <xe...@apache.org> Authored: Fri Feb 24 17:01:37 2012 +0300 Committer: Pavel Yaskevich <xe...@apache.org> Committed: Fri Feb 24 17:01:37 2012 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + src/java/org/apache/cassandra/cli/Cli.g | 21 ++++++++- src/java/org/apache/cassandra/cli/CliClient.java | 36 ++++++++++++++- .../org/apache/cassandra/cli/CliHelp.yaml | 7 +++ test/unit/org/apache/cassandra/cli/CliTest.java | 7 ++- 5 files changed, 66 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/18c5441c/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index b45bcc2..d7ace7b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,6 +10,7 @@ * Remove deprecated merge_shard_chance (CASSANDRA-3940) * add a convenient way to reset a node's schema (CASSANDRA-2963) * fix for intermittent SchemaDisagreementException (CASSANDRA-3884) + * CLI `list <CF>` to limit number of columns and their order (CASSANDRA-3012) Merged from 1.0: * remove the wait on hint future during write (CASSANDRA-3870) * (cqlsh) ignore missing CfDef opts (CASSANDRA-3933) http://git-wip-us.apache.org/repos/asf/cassandra/blob/18c5441c/src/java/org/apache/cassandra/cli/Cli.g ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cli/Cli.g b/src/java/org/apache/cassandra/cli/Cli.g index e7cba6c..7bf1ac2 100644 --- a/src/java/org/apache/cassandra/cli/Cli.g +++ b/src/java/org/apache/cassandra/cli/Cli.g @@ -79,6 +79,8 @@ tokens { PAIR; NODE_LIMIT; + NODE_COLUMNS; + NODE_REVERSED; NODE_KEY_RANGE; } @@ -291,8 +293,8 @@ showStatement ; listStatement - : LIST columnFamily keyRangeExpr? ('LIMIT' limit=IntegerPositiveLiteral)? - -> ^(NODE_LIST columnFamily keyRangeExpr? ^(NODE_LIMIT $limit)?) + : LIST columnFamily keyRangeExpr? rowLimitExpr? columnLimitExpr? + -> ^(NODE_LIST columnFamily keyRangeExpr? rowLimitExpr? columnLimitExpr?) ; truncateStatement @@ -428,6 +430,21 @@ keyRangeExpr -> ^(NODE_KEY_RANGE $startKey? $endKey?) ; +rowLimitExpr + : 'LIMIT' limit=IntegerPositiveLiteral + -> ^(NODE_LIMIT $limit) + ; + +columnLimitExpr + : 'COLUMNS' columns=IntegerPositiveLiteral reversedExpr? + -> ^(NODE_COLUMNS $columns reversedExpr?) + ; + +reversedExpr + : 'REVERSED' + -> ^(NODE_REVERSED) + ; + columnName : entityName ; http://git-wip-us.apache.org/repos/asf/cassandra/blob/18c5441c/src/java/org/apache/cassandra/cli/CliClient.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index f9bbd42..02c97f6 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -1309,6 +1309,8 @@ public class CliClient String rawStartKey = ""; String rawEndKey = ""; int limitCount = Integer.MAX_VALUE; // will reset to default later if it's not specified + int columnCount = Integer.MAX_VALUE; + boolean reversed = false; // optional arguments: key range and limit for (int i = 1; i < statement.getChildCount(); i++) @@ -1323,13 +1325,14 @@ public class CliClient rawEndKey = CliUtils.unescapeSQLString(child.getChild(1).getText()); } } - else + else if (child.getType() == CliParser.NODE_LIMIT) { if (child.getChildCount() != 1) { sessionState.out.println("Invalid limit clause"); return; } + limitCount = Integer.parseInt(child.getChild(0).getText()); if (limitCount <= 0) { @@ -1337,6 +1340,34 @@ public class CliClient return; } } + else if (child.getType() == CliParser.NODE_COLUMNS) + { + if ((child.getChildCount() < 1) || (child.getChildCount() > 2)) + { + sessionState.err.println("Invalid columns clause."); + return; + } + + String columns = child.getChild(0).getText(); + + try + { + columnCount = Integer.parseInt(columns); + if (columnCount < 0) + { + sessionState.err.println("Invalid column limit: " + columnCount); + return; + } + + if (child.getChildCount() == 2) + reversed = child.getChild(1).getType() == CliParser.NODE_REVERSED; + } + catch (NumberFormatException nfe) + { + sessionState.err.println("Invalid column number format: " + columns); + return; + } + } } if (limitCount == Integer.MAX_VALUE) @@ -1351,7 +1382,8 @@ public class CliClient SlicePredicate predicate = new SlicePredicate(); SliceRange sliceRange = new SliceRange(); sliceRange.setStart(new byte[0]).setFinish(new byte[0]); - sliceRange.setCount(Integer.MAX_VALUE); + sliceRange.setCount(columnCount); + sliceRange.setReversed(reversed); predicate.setSlice_range(sliceRange); // set the key range http://git-wip-us.apache.org/repos/asf/cassandra/blob/18c5441c/src/resources/org/apache/cassandra/cli/CliHelp.yaml ---------------------------------------------------------------------- diff --git a/src/resources/org/apache/cassandra/cli/CliHelp.yaml b/src/resources/org/apache/cassandra/cli/CliHelp.yaml index fc5ee5a..cde163f 100644 --- a/src/resources/org/apache/cassandra/cli/CliHelp.yaml +++ b/src/resources/org/apache/cassandra/cli/CliHelp.yaml @@ -993,6 +993,7 @@ commands: list <cf>[<startKey>:]; list <cf>[<startKey>:<endKey>]; list <cf>[<startKey>:<endKey>] limit <limit>; + list <cf>[<startKey>:<endKey>] ?(limit <limit>) ?(columns <col_limit> ?(reversed)); List a range of rows, and all of their columns, in the specified column family. @@ -1008,6 +1009,9 @@ commands: - limit: Number of rows to return. Default is 100. + - columns: Number of columns to return per row, Default to MAX_INTEGER. reversed - + columns in reverse order. + - startKey: Key start the range from. The start key will be included in the result. Defaults to an empty byte array. @@ -1015,6 +1019,9 @@ commands: list Standard1; list Super1[j:]; list Standard1[j:k] limit 40; + list Standard1 columns 2; + list Standard1 limit 40 columns 0; + list Standard1 columns 3 reversed; - name: NODE_TRUNCATE help: | truncate <cf>; http://git-wip-us.apache.org/repos/asf/cassandra/blob/18c5441c/test/unit/org/apache/cassandra/cli/CliTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cli/CliTest.java b/test/unit/org/apache/cassandra/cli/CliTest.java index db93aed..d764dc8 100644 --- a/test/unit/org/apache/cassandra/cli/CliTest.java +++ b/test/unit/org/apache/cassandra/cli/CliTest.java @@ -54,8 +54,11 @@ public class CliTest extends CleanupHelper "list 123;", "list 123[:];", "list 123[456:];", - "list 123 limit 5", - "list 123[12:15] limit 20", + "list 123 limit 5;", + "list 123[12:15] limit 20;", + "list 123[12:15] columns 2;", + "list 123 columns 2 reversed;", + "list 123 limit 10 columns 2 reversed;", "get 123[hello][-31337];", "get 123[hello][world];", "get 123[hello][test_quote];",