Merge branch 'cassandra-3.11' into trunk

Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/eaa59486
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/eaa59486
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/eaa59486

Branch: refs/heads/trunk
Commit: eaa594865699c7e8e8097a26a744c815981e009d
Parents: 1f7a1dd 87e8c6b
Author: Sam Tunnicliffe <[email protected]>
Authored: Mon Feb 20 12:10:41 2017 +0000
Committer: Sam Tunnicliffe <[email protected]>
Committed: Mon Feb 20 12:10:41 2017 +0000

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/service/QueryPagerTest.java       | 76 +++++++++++++++++++-
 2 files changed, 76 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/eaa59486/CHANGES.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/eaa59486/test/unit/org/apache/cassandra/service/QueryPagerTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/service/QueryPagerTest.java
index d0b7704,2ec074b..56bf59c
--- a/test/unit/org/apache/cassandra/service/QueryPagerTest.java
+++ b/test/unit/org/apache/cassandra/service/QueryPagerTest.java
@@@ -27,9 -27,11 +27,12 @@@ import org.junit.Test
  import org.junit.runner.RunWith;
  
  import org.apache.cassandra.*;
 -import org.apache.cassandra.config.CFMetaData;
 -import org.apache.cassandra.config.ColumnDefinition;
 +import org.apache.cassandra.cql3.statements.CreateTableStatement;
++import org.apache.cassandra.schema.ColumnMetadata;
 +import org.apache.cassandra.schema.TableMetadata;
+ import org.apache.cassandra.cql3.ColumnIdentifier;
  import org.apache.cassandra.db.*;
+ import org.apache.cassandra.db.rows.Cell;
  import org.apache.cassandra.db.rows.Row;
  import org.apache.cassandra.db.rows.RowIterator;
  import org.apache.cassandra.db.filter.*;
@@@ -64,14 -66,20 +68,21 @@@ public class QueryPagerTes
          SchemaLoader.createKeyspace(KEYSPACE1,
                                      KeyspaceParams.simple(1),
                                      SchemaLoader.standardCFMD(KEYSPACE1, 
CF_STANDARD));
 +
          SchemaLoader.createKeyspace(KEYSPACE_CQL,
                                      KeyspaceParams.simple(1),
 -                                    CFMetaData.compile("CREATE TABLE " + 
CF_CQL + " ("
 -                                                     + "k text,"
 -                                                     + "c text,"
 -                                                     + "v text,"
 -                                                     + "PRIMARY KEY (k, c))", 
KEYSPACE_CQL),
 -                                    CFMetaData.compile("CREATE TABLE " + 
CF_CQL_WITH_STATIC + " ("
 -                                                     + "pk text, "
 -                                                     + "ck int, "
 -                                                     + "st int static, "
 -                                                     + "v1 int, "
 -                                                     + "v2 int, "
 -                                                     + "PRIMARY KEY(pk, 
ck))", KEYSPACE_CQL));
 +                                    CreateTableStatement.parse("CREATE TABLE 
" + CF_CQL + " ("
 +                                                               + "k text,"
 +                                                               + "c text,"
 +                                                               + "v text,"
-                                                                + "PRIMARY KEY 
(k, c))", KEYSPACE_CQL));
++                                                               + "PRIMARY KEY 
(k, c))", KEYSPACE_CQL),
++                                    CreateTableStatement.parse("CREATE TABLE 
" + CF_CQL_WITH_STATIC + " ("
++                                                               + "pk text, "
++                                                               + "ck int, "
++                                                               + "st int 
static, "
++                                                               + "v1 int, "
++                                                               + "v2 int, "
++                                                               + "PRIMARY 
KEY(pk, ck))", KEYSPACE_CQL));
          addData();
      }
  
@@@ -441,4 -449,67 +452,67 @@@
              assertRow(partitions.get(0), "k0", "c" + i);
          }
      }
+ 
+     @Test
+     public void pagingReversedQueriesWithStaticColumnsTest() throws Exception
+     {
+         // There was a bug in paging for reverse queries when the schema 
includes static columns in
+         // 2.1 & 2.2. This was never a problem in 3.0, so this test just 
guards against regressions
+         // see CASSANDRA-13222
+ 
+         // insert some rows into a single partition
+         for (int i=0; i < 5; i++)
+             executeInternal(String.format("INSERT INTO %s.%s (pk, ck, st, v1, 
v2) VALUES ('k0', %3$s, %3$s, %3$s, %3$s)",
+                                           KEYSPACE_CQL, CF_CQL_WITH_STATIC, 
i));
+ 
+         // query the table in reverse with page size = 1 & check that the 
returned rows contain the correct cells
 -        CFMetaData cfm = 
Keyspace.open(KEYSPACE_CQL).getColumnFamilyStore(CF_CQL_WITH_STATIC).metadata;
 -        queryAndVerifyCells(cfm, true, "k0");
++        TableMetadata table = 
Keyspace.open(KEYSPACE_CQL).getColumnFamilyStore(CF_CQL_WITH_STATIC).metadata();
++        queryAndVerifyCells(table, true, "k0");
+     }
+ 
 -    private void queryAndVerifyCells(CFMetaData cfm, boolean reversed, String 
key) throws Exception
++    private void queryAndVerifyCells(TableMetadata table, boolean reversed, 
String key) throws Exception
+     {
+         ClusteringIndexFilter rowfilter = new 
ClusteringIndexSliceFilter(Slices.ALL, reversed);
 -        ReadCommand command = SinglePartitionReadCommand.create(cfm, 
nowInSec, Util.dk(key), ColumnFilter.all(cfm), rowfilter);
++        ReadCommand command = SinglePartitionReadCommand.create(table, 
nowInSec, Util.dk(key), ColumnFilter.all(table), rowfilter);
+         QueryPager pager = command.getPager(null, ProtocolVersion.CURRENT);
+ 
 -        ColumnDefinition staticColumn = 
cfm.partitionColumns().statics.getSimple(0);
++        ColumnMetadata staticColumn = table.staticColumns().getSimple(0);
+         assertEquals(staticColumn.name.toCQLString(), "st");
+ 
+         for (int i=0; i<5; i++)
+         {
+             try (ReadExecutionController controller = 
pager.executionController();
+                  PartitionIterator partitions = pager.fetchPageInternal(1, 
controller))
+             {
+                 try (RowIterator partition = partitions.next())
+                 {
+                     assertCell(partition.staticRow(), staticColumn, 4);
+ 
+                     Row row = partition.next();
+                     int cellIndex = !reversed ? i : 4 - i;
+ 
+                     assertEquals(row.clustering().get(0), 
ByteBufferUtil.bytes(cellIndex));
 -                    assertCell(row, cfm.getColumnDefinition(new 
ColumnIdentifier("v1", false)), cellIndex);
 -                    assertCell(row, cfm.getColumnDefinition(new 
ColumnIdentifier("v2", false)), cellIndex);
++                    assertCell(row, table.getColumn(new 
ColumnIdentifier("v1", false)), cellIndex);
++                    assertCell(row, table.getColumn(new 
ColumnIdentifier("v2", false)), cellIndex);
+ 
+                     // the partition/page should contain just a single 
regular row
+                     assertFalse(partition.hasNext());
+                 }
+             }
+         }
+ 
+         // After processing the 5 rows there should be no more rows to return
+         try ( ReadExecutionController controller = 
pager.executionController();
+               PartitionIterator partitions = pager.fetchPageInternal(1, 
controller))
+         {
+             assertFalse(partitions.hasNext());
+         }
+     }
+ 
 -    private void assertCell(Row row, ColumnDefinition column, int value)
++    private void assertCell(Row row, ColumnMetadata column, int value)
+     {
+         Cell cell = row.getCell(column);
+         assertNotNull(cell);
+         assertEquals(value, ByteBufferUtil.toInt(cell.value()));
+     }
  }

Reply via email to