cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1080774 - in /cassandra/trunk/src/java/org/apache/cassandra/cql: Cql.g QueryProcessor.java
Date Fri, 11 Mar 2011 21:57:12 GMT
Author: eevans
Date: Fri Mar 11 21:57:12 2011
New Revision: 1080774

URL: http://svn.apache.org/viewvc?rev=1080774&view=rev
Log:
don't let antlr try to recover on bad input, always throw

Patch by eevans

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
    cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g?rev=1080774&r1=1080773&r2=1080774&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g Fri Mar 11 21:57:12 2011
@@ -37,6 +37,7 @@ options {
 
 @lexer::header {
     package org.apache.cassandra.cql;
+    import org.apache.cassandra.thrift.InvalidRequestException;
 }
 
 @lexer::members {
@@ -53,6 +54,26 @@ options {
             return Token.EOF_TOKEN;
         return tokens.remove(0);
     }
+    
+    private List<String> recognitionErrors = new ArrayList<String>();
+    
+    public void displayRecognitionError(String[] tokenNames, RecognitionException e)
+    {
+        String hdr = getErrorHeader(e);
+        String msg = getErrorMessage(e, tokenNames);
+        recognitionErrors.add(hdr + " " + msg);
+    }
+    
+    public List<String> getRecognitionErrors()
+    {
+        return recognitionErrors;
+    }
+    
+    public void throwLastRecognitionError() throws InvalidRequestException
+    {
+        if (recognitionErrors.size() > 0)
+            throw new InvalidRequestException(recognitionErrors.get((recognitionErrors.size()-1)));
+    }
 }
 
 query returns [CQLStatement stmnt]

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java?rev=1080774&r1=1080773&r2=1080774&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java Fri Mar 11 21:57:12
2011
@@ -439,9 +439,7 @@ public class QueryProcessor
     {
         logger.trace("CQL QUERY: {}", queryString);
         
-        CqlParser parser = getParser(queryString);
-        CQLStatement statement = parser.query();
-        parser.throwLastRecognitionError();
+        CQLStatement statement = getStatement(queryString);
         String keyspace = null;
         
         // Chicken-and-egg; No keyspace to get when we're setting (or creating) one. 
@@ -778,11 +776,22 @@ public class QueryProcessor
         return null;    // We should never get here.
     }
     
-    private static CqlParser getParser(String queryStr)
+    private static CQLStatement getStatement(String queryStr) throws InvalidRequestException,
RecognitionException
     {
+        // Lexer and parser
         CharStream stream = new ANTLRStringStream(queryStr);
         CqlLexer lexer = new CqlLexer(stream);
         TokenStream tokenStream = new CommonTokenStream(lexer);
-        return new CqlParser(tokenStream);
+        CqlParser parser = new CqlParser(tokenStream);
+        
+        // Parse the query string to a statement instance
+        CQLStatement statement = parser.query();
+        
+        // The lexer and parser queue up any errors they may have encountered
+        // along the way, if necessary, we turn them into exceptions here.
+        lexer.throwLastRecognitionError();
+        parser.throwLastRecognitionError();
+        
+        return statement;
     }
 }



Mime
View raw message