diff --git a/src/java/org/apache/cassandra/cli/Cli.g b/src/java/org/apache/cassandra/cli/Cli.g index 1b77fee997..ed22b38386 100644 --- a/src/java/org/apache/cassandra/cli/Cli.g +++ b/src/java/org/apache/cassandra/cli/Cli.g @@ -235,10 +235,10 @@ exitStatement ; getStatement - : GET columnFamilyExpr ('AS' typeIdentifier)? - -> ^(NODE_THRIFT_GET columnFamilyExpr ( ^(CONVERT_TO_TYPE typeIdentifier) )? ) - | GET columnFamily 'WHERE' getCondition ('AND' getCondition)* ('LIMIT' limit=IntegerPositiveLiteral)* - -> ^(NODE_THRIFT_GET_WITH_CONDITIONS columnFamily ^(CONDITIONS getCondition+) ^(NODE_LIMIT $limit)*) + : GET columnFamilyExpr ('AS' typeIdentifier)? ('LIMIT' limit=IntegerPositiveLiteral)? + -> ^(NODE_THRIFT_GET columnFamilyExpr ( ^(CONVERT_TO_TYPE typeIdentifier) )? ^(NODE_LIMIT $limit)?) + | GET columnFamily 'WHERE' getCondition ('AND' getCondition)* ('LIMIT' limit=IntegerPositiveLiteral)? + -> ^(NODE_THRIFT_GET_WITH_CONDITIONS columnFamily ^(CONDITIONS getCondition+) ^(NODE_LIMIT $limit)?) ; getCondition diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index 2e3aa68ca4..3e2fcacc16 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -412,7 +412,7 @@ public class CliClient sessionState.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row" : "column")); } - private void doSlice(String keyspace, ByteBuffer key, String columnFamily, byte[] superColumnName) + private void doSlice(String keyspace, ByteBuffer key, String columnFamily, byte[] superColumnName, int limit) throws InvalidRequestException, UnavailableException, TimedOutException, TException, IllegalAccessException, NotFoundException, InstantiationException, NoSuchFieldException { @@ -420,7 +420,7 @@ public class CliClient if(superColumnName != null) parent.setSuper_column(superColumnName); - SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000000); + SliceRange range = new SliceRange(ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, limit); SlicePredicate predicate = new SlicePredicate().setColumn_names(null).setSlice_range(range); CfDef cfDef = getCfDef(columnFamily); @@ -529,10 +529,39 @@ public class CliClient byte[] superColumnName = null; ByteBuffer columnName; + Tree typeTree = null; + Tree limitTree = null; + + int limit = 1000000; + + if (statement.getChildCount() >= 2) + { + if (statement.getChild(1).getType() == CliParser.CONVERT_TO_TYPE) + { + typeTree = statement.getChild(1).getChild(0); + if (statement.getChildCount() == 3) + limitTree = statement.getChild(2).getChild(0); + } + else + { + limitTree = statement.getChild(1).getChild(0); + } + } + + if (limitTree != null) + { + limit = Integer.parseInt(limitTree.getText()); + + if (limit == 0) + { + throw new IllegalArgumentException("LIMIT should be greater than zero."); + } + } + // table.cf['key'] -- row slice if (columnSpecCnt == 0) { - doSlice(keySpace, key, columnFamily, superColumnName); + doSlice(keySpace, key, columnFamily, superColumnName, limit); return; } // table.cf['key']['column'] -- slice of a super, or get of a standard @@ -543,7 +572,7 @@ public class CliClient if (isSuper) { superColumnName = columnName.array(); - doSlice(keySpace, key, columnFamily, superColumnName); + doSlice(keySpace, key, columnFamily, superColumnName, limit); return; } } @@ -586,14 +615,12 @@ public class CliClient byte[] columnValue = column.getValue(); String valueAsString; - + // we have ^(CONVERT_TO_TYPE ) inside of GET statement // which means that we should try to represent byte[] value according // to specified type - if (statement.getChildCount() == 2) + if (typeTree != null) { - // getting ^(CONVERT_TO_TYPE ) tree - Tree typeTree = statement.getChild(1).getChild(0); // .getText() will give us String typeName = CliUtils.unescapeSQLString(typeTree.getText()); // building AbstractType from