Merge branch 'cassandra-3.11' into trunk

This commit is contained in:
Stefania Alborghetti 2017-08-02 10:18:43 +08:00
commit 8174fa510c
6 changed files with 86 additions and 5 deletions

View File

@ -189,6 +189,13 @@ public abstract class AbstractReadCommandBuilder
protected ClusteringIndexFilter makeFilter()
{
// StatementRestrictions.isColumnRange() returns false for static compact tables, which means
// SelectStatement.makeClusteringIndexFilter uses a names filter with no clusterings for static
// compact tables, here we reproduce this behavior (CASSANDRA-11223). Note that this code is only
// called by tests.
if (cfs.metadata().isStaticCompactTable())
return new ClusteringIndexNamesFilter(new TreeSet<>(cfs.metadata().comparator), reversed);
if (clusterings != null)
{
return new ClusteringIndexNamesFilter(clusterings, reversed);

View File

@ -329,7 +329,8 @@ public class PartitionRangeReadCommand extends ReadCommand
@Override
public boolean selectsFullPartition()
{
return dataRange.selectsAllPartition() && !rowFilter().hasExpressionOnClusteringOrRegularColumns();
return metadata().isStaticCompactTable() ||
(dataRange.selectsAllPartition() && !rowFilter().hasExpressionOnClusteringOrRegularColumns());
}
@Override

View File

@ -922,7 +922,8 @@ public class SinglePartitionReadCommand extends ReadCommand
@Override
public boolean selectsFullPartition()
{
return clusteringIndexFilter.selectsAllPartition() && !rowFilter().hasExpressionOnClusteringOrRegularColumns();
return metadata().isStaticCompactTable() ||
(clusteringIndexFilter.selectsAllPartition() && !rowFilter().hasExpressionOnClusteringOrRegularColumns());
}
@Override

View File

@ -72,7 +72,9 @@ public class ClusteringIndexNamesFilter extends AbstractClusteringIndexFilter
public boolean selectsAllPartition()
{
return false;
// if the clusterings set is empty we are selecting a static row and in this case we want to count
// static rows so we return true
return clusterings.isEmpty();
}
public boolean selects(Clustering clustering)

View File

@ -94,6 +94,43 @@ public class SelectLimitTest extends CQLTester
}
@Test
public void testLimitInStaticTable() throws Throwable
{
createTable("CREATE TABLE %s (k int, v int, PRIMARY KEY (k) ) WITH COMPACT STORAGE ");
for (int i = 0; i < 10; i++)
execute("INSERT INTO %s(k, v) VALUES (?, ?)", i, i);
assertRows(execute("SELECT * FROM %s LIMIT 5"),
row(0, 0),
row(1, 1),
row(2, 2),
row(3, 3),
row(4, 4));
assertRows(execute("SELECT v FROM %s LIMIT 5"),
row(0),
row(1),
row(2),
row(3),
row(4));
assertRows(execute("SELECT k FROM %s LIMIT 5"),
row(0),
row(1),
row(2),
row(3),
row(4));
assertRows(execute("SELECT DISTINCT k FROM %s LIMIT 5"),
row(0),
row(1),
row(2),
row(3),
row(4));
}
/**
* Check for #7052 bug,
* migrated from cql_tests.py:TestCQL.limit_compact_table()

View File

@ -30,12 +30,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.cassandra.*;
import org.apache.cassandra.schema.ColumnMetadata;
import org.apache.cassandra.db.marshal.AsciiType;
import org.apache.cassandra.db.rows.Row;
import org.apache.cassandra.db.marshal.IntegerType;
import org.apache.cassandra.db.partitions.*;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.schema.ColumnMetadata;
import org.apache.cassandra.schema.KeyspaceParams;
import org.apache.cassandra.schema.TableMetadata;
import org.apache.cassandra.utils.ByteBufferUtil;
public class PartitionRangeReadTest
@ -44,6 +46,7 @@ public class PartitionRangeReadTest
public static final String KEYSPACE2 = "PartitionRangeReadTest2";
public static final String CF_STANDARD1 = "Standard1";
public static final String CF_STANDARDINT = "StandardInteger1";
public static final String CF_COMPACT1 = "Compact1";
@BeforeClass
public static void defineSchema() throws ConfigurationException
@ -52,7 +55,13 @@ public class PartitionRangeReadTest
SchemaLoader.createKeyspace(KEYSPACE1,
KeyspaceParams.simple(1),
SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD1),
SchemaLoader.denseCFMD(KEYSPACE1, CF_STANDARDINT, IntegerType.instance));
SchemaLoader.denseCFMD(KEYSPACE1, CF_STANDARDINT, IntegerType.instance),
TableMetadata.builder(KEYSPACE1, CF_COMPACT1)
.isCompound(false)
.addPartitionKeyColumn("key", AsciiType.instance)
.addClusteringColumn("column1", AsciiType.instance)
.addRegularColumn("value", AsciiType.instance)
.addStaticColumn("val", AsciiType.instance));
SchemaLoader.createKeyspace(KEYSPACE2,
KeyspaceParams.simple(1),
SchemaLoader.standardCFMD(KEYSPACE2, CF_STANDARD1));
@ -108,6 +117,30 @@ public class PartitionRangeReadTest
assertTrue(row.getCell(cDef).value().equals(ByteBufferUtil.bytes("val2")));
}
@Test
public void testLimits()
{
ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_COMPACT1);
for (int i = 0; i < 10; i++)
{
new RowUpdateBuilder(cfs.metadata(), 0, Integer.toString(i))
.add("val", "abcd")
.build()
.applyUnsafe();
new RowUpdateBuilder(cfs.metadata(), 0, Integer.toString(i))
.clustering("column1")
.add("value", "")
.build()
.applyUnsafe();
}
assertEquals(10, Util.getAll(Util.cmd(cfs).build()).size());
for (int i = 0; i < 10; i++)
assertEquals(i, Util.getAll(Util.cmd(cfs).withLimit(i).build()).size());
}
@Test
public void testRangeSliceInclusionExclusion() throws Throwable
{