cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1034535 - in /cassandra/trunk: src/java/org/apache/cassandra/cql/QueryProcessor.java test/system/test_cql.py
Date Fri, 12 Nov 2010 19:32:48 GMT
Author: eevans
Date: Fri Nov 12 19:32:48 2010
New Revision: 1034535

URL: http://svn.apache.org/viewvc?rev=1034535&view=rev
Log:
backfill missing system tests

Patch by eevans

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
    cassandra/trunk/test/system/test_cql.py

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=1034535&r1=1034534&r2=1034535&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java Fri Nov 12 19:32:48
2010
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.TimeoutException;
 
@@ -243,6 +244,8 @@ public class QueryProcessor
                     CqlRow avroRow = new CqlRow();
                     avroRow.key = row.key.key;
                     avroRow.columns = avroColumns;
+                    if (select.isColumnsReversed())
+                        Collections.reverse(avroRow.columns);
                     avroRows.add(avroRow);
                 }
                 

Modified: cassandra/trunk/test/system/test_cql.py
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_cql.py?rev=1034535&r1=1034534&r2=1034535&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_cql.py (original)
+++ cassandra/trunk/test/system/test_cql.py Fri Nov 12 19:32:48 2010
@@ -4,8 +4,9 @@ import sys
 
 sys.path.append(join(abspath(dirname(__file__)), '../../drivers/py'))
 
-from cql import Connection
+from cql import Connection, CQLException
 from . import AvroTester
+from avro_utils import assert_raises
 
 def load_sample(dbconn):
     dbconn.execute("""
@@ -47,15 +48,59 @@ class TestCql(AvroTester):
     def test_select_columns(self):
         "retrieve multiple columns"
         conn = init()
-        r = conn.execute("""
-            SELECT "cd1", "col" FROM Standard1 WHERE KEY = "kd"
-        """)
+        r = conn.execute('SELECT "cd1", "col" FROM Standard1 WHERE KEY = "kd"')
         assert "cd1" in [i['name'] for i in r[0]['columns']]
         assert "col" in [i['name'] for i in r[0]['columns']]
 
     def test_select_row_range(self):
         "retrieve a range of rows with columns"
         conn = init()
+        r = conn.execute('SELECT 4L FROM StandardLong1 WHERE KEY > "ad" AND KEY < "ag";')
+        assert len(r) == 3
+        assert r[0]['key'] == "ad"
+        assert r[1]['key'] == "ae"
+        assert r[2]['key'] == "af"
+        assert len(r[0]['columns']) == 1
+        assert len(r[1]['columns']) == 1
+        assert len(r[2]['columns']) == 1
+
+    def test_select_row_range_with_limit(self):
+        "retrieve a limited range of rows with columns"
+        conn = init()
         r = conn.execute("""
-            SELECT "col1" FROM StandardLong1 WHERE KEY > "ad" AND KEY < "ag";
+            SELECT 1L,5L,9L FROM StandardLong1 WHERE KEY > "aa" AND KEY < "ag" LIMIT
3
         """)
+        assert len(r) == 3
+
+    def test_select_columns_slice(self):
+        "range of columns (slice) by row"
+        conn = init()
+        r = conn.execute('SELECT 1L..3L FROM StandardLong1 WHERE KEY = "aa";')
+        assert len(r) == 1
+        assert r[0]['columns'][0]['value'] == "1"
+        assert r[0]['columns'][1]['value'] == "2"
+        assert r[0]['columns'][2]['value'] == "3"
+
+    def test_select_columns_slice_with_limit(self):
+        "range of columns (slice) by row with limit"
+        conn = init()
+        r = conn.execute('SELECT FIRST 1 1L..3L FROM StandardLong1 WHERE KEY = "aa";')
+        assert len(r) == 1
+        assert len(r[0]['columns']) == 1
+        assert r[0]['columns'][0]['value'] == "1"
+
+    def test_select_columns_slice_reversed(self):
+        "range of columns (slice) by row reversed"
+        conn = init()
+        r = conn.execute('SELECT FIRST 2 REVERSED 3L..1L FROM StandardLong1 WHERE KEY = "aa";')
+        assert len(r) == 1, "%d != 1" % len(r)
+        assert len(r[0]['columns']) == 2
+        assert r[0]['columns'][0]['value'] == "3"
+        assert r[0]['columns'][1]['value'] == "2"
+
+    def test_error_on_multiple_key_by(self):
+        "ensure multiple key-bys in where clause excepts"
+        conn = init()
+        query = 'SELECT "col" FROM Standard1 WHERE KEY = "ka" AND KEY = "kb";'
+        assert_raises(CQLException, conn.execute, query)
+



Mime
View raw message