refactor of executeSet() to support super columns

Patch by eevans for CASSANDRA-567

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@887497 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eric Evans 2009-12-05 05:26:56 +00:00
parent 0a7bcd5c1f
commit 601d939e9b
2 changed files with 31 additions and 27 deletions

View File

@ -43,6 +43,6 @@ if [ -z $CLASSPATH ]; then
exit 1
fi
$JAVA -cp $CLASSPATH org.apache.cassandra.cli.CliMain "$@"
$JAVA -ea -cp $CLASSPATH org.apache.cassandra.cli.CliMain "$@"
# vi:ai sw=4 ts=4 tw=0 et

View File

@ -259,45 +259,49 @@ public class CliClient
if (!CliMain.isConnected())
return;
int childCount = ast.getChildCount();
assert(childCount == 2);
assert (ast.getChildCount() == 2) : "serious parsing error (this is a bug).";
CommonTree columnFamilySpec = (CommonTree)ast.getChild(0);
assert(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS);
String tableName = CliCompiler.getTableName(columnFamilySpec);
String key = CliCompiler.getKey(columnFamilySpec);
String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
String value = CliUtils.unescapeSQLString(ast.getChild(1).getText());
String tableName = CliCompiler.getTableName(columnFamilySpec);
String key = CliCompiler.getKey(columnFamilySpec);
String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
String value = CliUtils.unescapeSQLString(ast.getChild(1).getText());
// assume simple columnFamily for now
if (columnSpecCnt == 1)
byte[] superColumnName = null;
byte[] columnName = null;
try
{
// We have the table.cf['key']['column'] = 'value' case.
// get the column name
String columnName = CliCompiler.getColumn(columnFamilySpec, 0);
// do the insert
try
// table.cf['key']['column'] = 'value'
if (columnSpecCnt == 1)
{
thriftClient_.insert(tableName, key, new ColumnPath(columnFamily, null, columnName.getBytes("UTF-8")),
value.getBytes(), System.currentTimeMillis(), ConsistencyLevel.ONE);
// get the column name
columnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
}
catch (UnsupportedEncodingException e)
// table.cf['key']['super_column']['column'] = 'value'
else
{
throw new RuntimeException(e);
assert (columnSpecCnt == 2) : "serious parsing error (this is a bug).";
// get the super column and column names
superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
columnName = CliCompiler.getColumn(columnFamilySpec, 1).getBytes("UTF-8");
}
css_.out.println("Value inserted.");
}
else
catch (UnsupportedEncodingException e)
{
/* for now (until we support batch sets) */
assert(false);
throw new RuntimeException("Unable to encode column name as UTF-8", e);
}
}
// do the insert
thriftClient_.insert(tableName, key, new ColumnPath(columnFamily, superColumnName, columnName),
value.getBytes(), System.currentTimeMillis(), ConsistencyLevel.ONE);
css_.out.println("Value inserted.");
}
private void executeShowProperty(CommonTree ast, String propertyName) throws TException
{