You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2010/11/11 19:27:18 UTC
svn commit: r1034022 - in
/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli: Cli.g
CliClient.java
Author: jbellis
Date: Thu Nov 11 18:27:18 2010
New Revision: 1034022
URL: http://svn.apache.org/viewvc?rev=1034022&view=rev
Log:
allow uuid functions in row keys.
patch by Pavel Yaskevich; reviewed by jbellis for CASSANDRA-1687
Modified:
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g
cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g?rev=1034022&r1=1034021&r2=1034022&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/Cli.g Thu Nov 11 18:27:18 2010
@@ -439,7 +439,7 @@ columnFamily
;
rowKey
- : (Identifier | StringLiteral | IntegerLiteral)
+ : (Identifier | StringLiteral | IntegerLiteral | functionCall)
;
value
Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java?rev=1034022&r1=1034021&r2=1034022&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/cli/CliClient.java Thu Nov 11 18:27:18 2010
@@ -294,7 +294,7 @@ public class CliClient extends CliUserHe
sessionState.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row" : "column"));
}
- private void doSlice(String keyspace, String key, String columnFamily, byte[] superColumnName)
+ private void doSlice(String keyspace, ByteBuffer key, String columnFamily, byte[] superColumnName)
throws InvalidRequestException, UnavailableException, TimedOutException, TException, IllegalAccessException, NotFoundException, InstantiationException, NoSuchFieldException
{
@@ -303,8 +303,7 @@ public class CliClient extends CliUserHe
parent.setSuper_column(superColumnName);
SliceRange range = new SliceRange(FBUtilities.EMPTY_BYTE_BUFFER, FBUtilities.EMPTY_BYTE_BUFFER, true, 1000000);
- List<ColumnOrSuperColumn> columns = thriftClient.get_slice(ByteBuffer.wrap(key.getBytes(Charsets.UTF_8)),parent,
- new SlicePredicate().setColumn_names(null).setSlice_range(range), ConsistencyLevel.ONE);
+ List<ColumnOrSuperColumn> columns = thriftClient.get_slice(key, parent, new SlicePredicate().setColumn_names(null).setSlice_range(range), ConsistencyLevel.ONE);
AbstractType validator;
CfDef cfDef = getCfDef(columnFamily);
@@ -371,9 +370,8 @@ public class CliClient extends CliUserHe
return;
Tree columnFamilySpec = statement.getChild(0);
-
- String key = CliCompiler.getKey(columnFamilySpec);
String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
+ ByteBuffer key = getKeyAsBytes(columnFamily, columnFamilySpec.getChild(1));
int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
CfDef cfDef = getCfDef(columnFamily);
boolean isSuper = cfDef.comparator_type.equals("Super");
@@ -421,7 +419,7 @@ public class CliClient extends CliUserHe
Column column;
try
{
- column = thriftClient.get(ByteBuffer.wrap(key.getBytes(Charsets.UTF_8)), path, ConsistencyLevel.ONE).column;
+ column = thriftClient.get(key, path, ConsistencyLevel.ONE).column;
}
catch (NotFoundException e)
{
@@ -562,7 +560,8 @@ public class CliClient extends CliUserHe
// ^(NODE_COLUMN_ACCESS <cf> <key> <column>)
Tree columnFamilySpec = statement.getChild(0);
- String key = CliCompiler.getKey(columnFamilySpec);
+ Tree keyTree = columnFamilySpec.getChild(1); // could be a function or regular text
+
String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
String value = CliUtils.unescapeSQLString(statement.getChild(1).getText());
@@ -608,12 +607,8 @@ public class CliClient extends CliUserHe
parent.setSuper_column(superColumnName);
// do the insert
- AbstractType keyComparator = this.cfKeysComparators.get(columnFamily);
- ByteBuffer keyBytes = keyComparator == null
- ? ByteBuffer.wrap(key.getBytes(Charsets.UTF_8))
- : getBytesAccordingToType(key, keyComparator);
-
- thriftClient.insert(keyBytes, parent, new Column(columnName, columnValueInBytes, FBUtilities.timestampMicros()), ConsistencyLevel.ONE);
+ thriftClient.insert(getKeyAsBytes(columnFamily, keyTree), parent, new Column(columnName, columnValueInBytes,
+ FBUtilities.timestampMicros()), ConsistencyLevel.ONE);
sessionState.out.println("Value inserted.");
}
@@ -1867,4 +1862,18 @@ public class CliClient extends CliUserHe
: subColumnNameAsBytes(CliUtils.unescapeSQLString(columnTree.getText()), columnFamily);
}
+ public ByteBuffer getKeyAsBytes(String columnFamily, Tree keyTree)
+ {
+ if (keyTree.getType() == CliParser.FUNCTION_CALL)
+ return convertValueByFunction(keyTree, null, null);
+
+ String key = CliUtils.unescapeSQLString(keyTree.getText());
+
+ AbstractType keyComparator = this.cfKeysComparators.get(columnFamily);
+ return keyComparator == null
+ ? ByteBuffer.wrap(key.getBytes(Charsets.UTF_8))
+ : getBytesAccordingToType(key, keyComparator);
+
+ }
+
}