Fix the problem with duplicated rows when using paging with SASI

Patch by Alex Petrov; reviewed by Andrés de la Peña for CASSANDRA-13302
This commit is contained in:
Alex Petrov 2017-04-04 11:41:06 +02:00
parent f0319c88fd
commit 9723db2717
3 changed files with 85 additions and 0 deletions

View File

@ -1,4 +1,5 @@
3.11.0
* Fix the problem with duplicated rows when using paging with SASI (CASSANDRA-13302)
* Allow CONTAINS statements filtering on the partition key and its parts (CASSANDRA-13275)
* Fall back to even ranges calculation in clusters with vnodes when tokens are distributed unevenly (CASSANDRA-13229)
* Fix duration type validation to prevent overflow (CASSANDRA-13218)

View File

@ -110,6 +110,9 @@ public class QueryPlan
if (!keyRange.right.isMinimum() && keyRange.right.compareTo(key) < 0)
return endOfData();
if (!keyRange.inclusiveLeft() && key.compareTo(keyRange.left) == 0)
continue;
try (UnfilteredRowIterator partition = controller.getPartition(key, executionController))
{
Row staticRow = partition.staticRow();

View File

@ -0,0 +1,81 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.index.sasi;
import java.util.List;
import java.util.stream.Collectors;
import com.google.common.collect.Sets;
import org.junit.Test;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import junit.framework.Assert;
import org.apache.cassandra.cql3.CQLTester;
public class SASICQLTest extends CQLTester
{
@Test
public void testPaging() throws Throwable
{
for (boolean forceFlush : new boolean[]{ false, true })
{
createTable("CREATE TABLE %s (pk int primary key, v int);");
createIndex("CREATE CUSTOM INDEX ON %s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex';");
for (int i = 0; i < 10; i++)
execute("INSERT INTO %s (pk, v) VALUES (?, ?);", i, 1);
flush(forceFlush);
Session session = sessionNet();
SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v = 1");
stmt.setFetchSize(5);
List<Row> rs = session.execute(stmt).all();
Assert.assertEquals(10, rs.size());
Assert.assertEquals(Sets.newHashSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
rs.stream().map((i) -> i.getInt("pk")).collect(Collectors.toSet()));
}
}
@Test
public void testPagingWithClustering() throws Throwable
{
for (boolean forceFlush : new boolean[]{ false, true })
{
createTable("CREATE TABLE %s (pk int, ck int, v int, PRIMARY KEY (pk, ck));");
createIndex("CREATE CUSTOM INDEX ON %s (v) USING 'org.apache.cassandra.index.sasi.SASIIndex';");
for (int i = 0; i < 10; i++)
{
execute("INSERT INTO %s (pk, ck, v) VALUES (?, ?, ?);", i, 1, 1);
execute("INSERT INTO %s (pk, ck, v) VALUES (?, ?, ?);", i, 2, 1);
}
flush(forceFlush);
Session session = sessionNet();
SimpleStatement stmt = new SimpleStatement("SELECT * FROM " + KEYSPACE + '.' + currentTable() + " WHERE v = 1");
stmt.setFetchSize(5);
List<Row> rs = session.execute(stmt).all();
Assert.assertEquals(20, rs.size());
}
}
}