cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r802909 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/cli: Cli.g CliClient.java CliCompiler.java CliMain.java CliUtils.java
Date Mon, 10 Aug 2009 19:34:46 GMT
Author: eevans
Date: Mon Aug 10 19:34:45 2009
New Revision: 802909

URL: http://svn.apache.org/viewvc?rev=802909&view=rev
Log:
CASSANDRA-296 remove CQL support from the CLI

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliUtils.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompiler.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g?rev=802909&r1=802908&r2=802909&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/Cli.g Mon Aug 10 19:34:45
2009
@@ -16,13 +16,7 @@
  * limitations under the License.
  */
 
-//
 // ANTLR Grammar for the Cassandra Command Line Interface (CLI).
-//
-// Note: This grammar handles all but the CQL statements. CQL
-// statements are detected separately (based on the first token)
-// and directly sent to server-side for processing.
-//
 
 grammar Cli;
 
@@ -99,11 +93,11 @@
     ;
 
 getStmt
-    : K_THRIFT K_GET columnFamilyExpr -> ^(NODE_THRIFT_GET columnFamilyExpr)
+    : K_GET columnFamilyExpr -> ^(NODE_THRIFT_GET columnFamilyExpr)
     ;
 
 setStmt
-    : K_THRIFT K_SET columnFamilyExpr '=' value -> ^(NODE_THRIFT_SET columnFamilyExpr
value)
+    : K_SET columnFamilyExpr '=' value -> ^(NODE_THRIFT_SET columnFamilyExpr value)
     ;
 
 showStmt
@@ -180,7 +174,6 @@
 K_SHOW:       'SHOW';
 K_TABLE:      'KEYSPACE';
 K_TABLES:     'KEYSPACES';
-K_THRIFT:     'THRIFT';
 K_VERSION:    'VERSION';
 
 // private syntactic rules

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java?rev=802909&r1=802908&r2=802909&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Mon Aug 10
19:34:45 2009
@@ -20,9 +20,7 @@
 import org.apache.thrift.*;
 
 import org.antlr.runtime.tree.*;
-import org.apache.cassandra.cql.common.Utils;
 import org.apache.cassandra.service.*;
-import org.apache.cassandra.utils.LogUtil;
 
 import java.util.*;
 import java.io.UnsupportedEncodingException;
@@ -91,23 +89,19 @@
     private void printCmdHelp()
     {
        css_.out.println("List of all CLI commands:");
-       css_.out.println("?                                                         Same as
help.");
-       css_.out.println("connect <hostname>/<port>                          
      Connect to Cassandra's thrift service.");
-       css_.out.println("describe keyspace <keyspacename>                         
Describe keyspace.");
-       css_.out.println("exit                                                      Exit CLI.");
-       css_.out.println("explain plan [<set stmt>|<get stmt>|<select stmt>]
       Explains the PLAN for specified stmt.");
-       css_.out.println("help                                                      Display
this help.");
-       css_.out.println("quit                                                      Exit CLI.");
-       css_.out.println("show config file                                          Display
contents of config file");
-       css_.out.println("show cluster name                                         Display
cassandra server version");
-       css_.out.println("show keyspaces                                               Show
list of keyspaces.");
-       css_.out.println("show version                                              Show server
version.");
-       css_.out.println("select ...                                                CQL select
statement (TBD).");
-       css_.out.println("get ...                                                   CQL data
retrieval statement.");
-       css_.out.println("set ...                                                   CQL DML
statement.");
-       css_.out.println("thrift get <tbl>.<cf>['<rowKey>']            
            (will be deprecated)");            
-       css_.out.println("thrift get <tbl>.<cf>['<rowKey>']['<colKey>']
            (will be deprecated)");            
-       css_.out.println("thrift set <tbl>.<cf>['<rowKey>']['<colKey>']
= '<value>' (will be deprecated)");    
+       css_.out.println("?                                                      Same as help.");
+       css_.out.println("connect <hostname>/<port>                          
   Connect to Cassandra's thrift service.");
+       css_.out.println("describe keyspace <keyspacename>                       Describe
keyspace.");
+       css_.out.println("exit                                                   Exit CLI.");
+       css_.out.println("help                                                   Display this
help.");
+       css_.out.println("quit                                                   Exit CLI.");
+       css_.out.println("show config file                                       Display contents
of config file");
+       css_.out.println("show cluster name                                      Display cluster
name.");
+       css_.out.println("show keyspaces                                         Show list
of keyspaces.");
+       css_.out.println("show version                                           Show server
version.");
+       css_.out.println("get <tbl>.<cf>['<rowKey>']                   
         Get a slice of columns.");            
+       css_.out.println("get <tbl>.<cf>['<rowKey>']['<colKey>'] 
               Get a column value.");            
+       css_.out.println("set <tbl>.<cf>['<rowKey>']['<colKey>'] =
'<value>'     Set a column.");    
     }
 
     private void cleanupAndExit()
@@ -143,8 +137,18 @@
             for (ColumnOrSuperColumn cosc : columns)
             {
                 Column column = cosc.column;
-                css_.out.printf("  (column=%s, value=%s; timestamp=%d)\n",
-                                column.name, column.value, column.timestamp);
+                try
+                {
+                    css_.out.printf("  (column=%s, value=%s; timestamp=%d)\n",
+                                    new String(column.name, "UTF-8"),
+                                    new String(column.value, "UTF-8"),
+                                    column.timestamp);
+                }
+                catch (UnsupportedEncodingException e)
+                {
+                    css_.out.printf("Cannot display results (UTF-8 not supported).");
+                    break;
+                }
             }
             css_.out.println("Returned " + size + " rows.");
         }
@@ -184,7 +188,7 @@
         String key           = CliCompiler.getKey(columnFamilySpec);
         String columnFamily  = CliCompiler.getColumnFamily(columnFamilySpec);
         int    columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
-        String value         = Utils.unescapeSQLString(ast.getChild(1).getText());
+        String value         = CliUtils.unescapeSQLString(ast.getChild(1).getText());
 
         // assume simple columnFamily for now
         if (columnSpecCnt == 1)
@@ -293,44 +297,4 @@
         css_.thriftPort = portNumber;
         CliMain.connect(css_.hostName, css_.thriftPort);
     }
-
-    // execute CQL query on server
-    public void executeQueryOnServer(String query) throws TException
-    {
-        if (!CliMain.isConnected())
-            return;
-        
-        CqlResult result = thriftClient_.execute_query(query);
-        
-        if (result == null)
-        {
-            css_.out.println("Unexpected error. Received null result from server.");
-            return;
-        }
-
-        if ((result.error_txt != null) || (result.error_code != 0))
-        {
-            css_.out.println("Error: " + result.error_txt);
-        }
-        else
-        {
-            List<Map<String, String>> rows = result.result_set;
-            
-            if (rows != null)
-            {
-                for (Map<String, String> row : rows)
-                {
-                    for (Iterator<Map.Entry<String, String>> it = row.entrySet().iterator();
it.hasNext(); )
-                    {
-                        Map.Entry<String, String> entry = it.next();
-                        String key = entry.getKey();
-                        String value = entry.getValue();
-                        css_.out.print(key + " = " + value + "; ");
-                    }
-                    css_.out.println();
-                }
-            }
-            css_.out.println("Statement processed.");
-        }
-    }
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompiler.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompiler.java?rev=802909&r1=802908&r2=802909&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompiler.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliCompiler.java Mon Aug 10
19:34:45 2009
@@ -20,7 +20,6 @@
 
 import org.antlr.runtime.*;
 import org.antlr.runtime.tree.*;
-import org.apache.cassandra.cql.common.Utils;
 
 
 public class CliCompiler
@@ -104,7 +103,7 @@
     {
         assert(astNode.getType() == CliParser.NODE_COLUMN_ACCESS);
 
-        return Utils.unescapeSQLString(astNode.getChild(2).getText());
+        return CliUtils.unescapeSQLString(astNode.getChild(2).getText());
     }
 
     public static int numColumnSpecifiers(CommonTree astNode)
@@ -117,7 +116,7 @@
     public static String getColumn(CommonTree astNode, int pos)
     {
         // Skip over table, column family and rowKey
-        return Utils.unescapeSQLString(astNode.getChild(pos + 3).getText()); 
+        return CliUtils.unescapeSQLString(astNode.getChild(pos + 3).getText()); 
     }
  
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java?rev=802909&r1=802908&r2=802909&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java Mon Aug 10 19:34:45
2009
@@ -24,7 +24,6 @@
 
 import jline.*;
 import java.io.*;
-import java.util.*;
 
 import org.apache.cassandra.service.Cassandra;
 
@@ -96,23 +95,6 @@
         }
         return true;
     }
-    
-    private static void processServerQuery(String query)
-    {
-        if (!isConnected())
-            return;
-
-        try
-        {
-            cliClient_.executeQueryOnServer(query);
-        }
-        catch(Exception e)
-        {
-            System.err.println("Exception " + e.getMessage());
-            e.printStackTrace(System.err);
-        }
-        return;
-    }
 
     private static void processCLIStmt(String query)
     {
@@ -128,32 +110,6 @@
         return;
     }
 
-    private static void processLine(String line)
-    {
-        StringTokenizer tokenizer = new StringTokenizer(line);
-        if (tokenizer.hasMoreTokens())
-        {
-            // Use first token for now to determine if this statement is
-            // a CQL statement. Technically, the line could start with
-            // a comment token followed by a CQL statement. That case
-            // isn't handled right now.
-            String token = tokenizer.nextToken().toUpperCase();
-            if (token.startsWith("GET")
-                || token.startsWith("SELECT")
-                || token.startsWith("SET")
-                || token.startsWith("DELETE")
-                || token.startsWith("EXPLAIN")) // explain plan statement
-            {
-                // these are CQL Statements that are compiled and executed on server-side
-                processServerQuery(line);
-            }
-            else 
-            {
-                // These are CLI statements processed locally
-                processCLIStmt(line);
-            }
-        }
-    } 
 
     public static void main(String args[]) throws IOException  
     {
@@ -184,7 +140,7 @@
         String line;
         while ((line = reader.readLine(PROMPT+"> ")) != null)
         {
-            processLine(line);
+            processCLIStmt(line);
         }
     }
 }

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliUtils.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliUtils.java?rev=802909&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliUtils.java (added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/cli/CliUtils.java Mon Aug 10 19:34:45
2009
@@ -0,0 +1,44 @@
+package org.apache.cassandra.cli;
+
+public class CliUtils
+{
+    /*
+     * Strips leading and trailing "'" characters, and handles
+     * and escaped characters such as \n, \r, etc.
+     * [Shameless clone from hive.]
+     */
+    public static String unescapeSQLString(String b) 
+    {
+        assert(b.charAt(0) == '\'');
+        assert(b.charAt(b.length()-1) == '\'');
+        StringBuilder sb = new StringBuilder(b.length());
+        
+        for (int i=1; i+1<b.length(); i++)
+        {
+            if (b.charAt(i) == '\\' && i+2<b.length())
+            {
+                char n=b.charAt(i+1);
+                switch(n)
+                {
+                case '0': sb.append("\0"); break;
+                case '\'': sb.append("'"); break;
+                case '"': sb.append("\""); break;
+                case 'b': sb.append("\b"); break;
+                case 'n': sb.append("\n"); break;
+                case 'r': sb.append("\r"); break;
+                case 't': sb.append("\t"); break;
+                case 'Z': sb.append("\u001A"); break;
+                case '\\': sb.append("\\"); break;
+                case '%': sb.append("%"); break;
+                case '_': sb.append("_"); break;
+                default: sb.append(n);
+                }
+            } 
+            else
+            {
+                sb.append(b.charAt(i));
+            }
+        }
+        return sb.toString();
+    } 
+}



Mime
View raw message