From 601d939e9b223320d00e93684ff20d80cba42fb8 Mon Sep 17 00:00:00 2001 From: Eric Evans Date: Sat, 5 Dec 2009 05:26:56 +0000 Subject: [PATCH] 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 --- bin/cassandra-cli | 2 +- .../org/apache/cassandra/cli/CliClient.java | 56 ++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/bin/cassandra-cli b/bin/cassandra-cli index 560cd4dcfa..b7c77ba816 100755 --- a/bin/cassandra-cli +++ b/bin/cassandra-cli @@ -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 diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index a9556280a5..7b4ea6dffd 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -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 {