Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/java/org/apache/cassandra/db/DataRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ public String toCQLString(TableMetadata metadata, RowFilter rowFilter)
* key are the same. If that is the case, we want to print the query as an equality on the partition key
* rather than a token range, as if it was a partition query, for better readability.
*/
builder.append(ColumnMetadata.toCQLString(metadata.partitionKeyColumns()));
builder.append(" = ");
appendKeyString(builder, metadata.partitionKeyType, ((DecoratedKey) startKey()).getKey());
builder.append(((DecoratedKey) startKey()).toCQLString(metadata));
needAnd = true;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/db/DecoratedKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public String toCQLString(TableMetadata metadata)

private static String toCQLString(ColumnMetadata metadata, ByteBuffer key)
{
return String.format("%s = %s", metadata.name.toCQLString(), metadata.type.toCQLString(key));
return String.format("%s = %s", metadata.name.toCQLString(), metadata.type.getString(key));
}

public Token getToken()
Expand Down
22 changes: 1 addition & 21 deletions src/java/org/apache/cassandra/db/SinglePartitionReadCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.cassandra.concurrent.Stage;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.CqlBuilder;
import org.apache.cassandra.db.marshal.CompositeType;
import org.apache.cassandra.db.filter.ClusteringIndexFilter;
import org.apache.cassandra.db.filter.ClusteringIndexNamesFilter;
import org.apache.cassandra.db.filter.ClusteringIndexSliceFilter;
Expand Down Expand Up @@ -1262,26 +1261,7 @@ protected void appendCQLWhereClause(CqlBuilder builder)
{
builder.append(" WHERE ");

List<ColumnMetadata> pkColumns = metadata().partitionKeyColumns();
if (pkColumns.size() == 1)
{
builder.append(pkColumns.get(0).name.toCQLString()).append(" = ");
builder.append(pkColumns.get(0).type.toCQLString(partitionKey().getKey()));
}
else
{
// Multi-column partition key
CompositeType ct = (CompositeType) metadata().partitionKeyType;
ByteBuffer[] values = ct.split(partitionKey().getKey());
for (int i = 0; i < pkColumns.size(); i++)
{
if (i > 0)
builder.append(" AND ");
builder.append(pkColumns.get(i).name.toCQLString())
.append(" = ")
.append(pkColumns.get(i).type.toCQLString(values[i]));
}
}
builder.append(partitionKey().toCQLString(metadata()));

// For queries with clustering columns in the rowFilter (e.g., ALLOW FILTERING or secondary index),
// remove those conditions to avoid duplication since they'll be handled by the clusteringIndexFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public void testToCQLString()
assertToCQLString("SELECT * FROM %s WHERE v = 0 AND k = 0 AND c1 = 1 AND c2 < 2", "SELECT * FROM %s WHERE k = 0 AND c1 = 1 AND c2 < 2 AND v = 0 ALLOW FILTERING");
assertToCQLString("SELECT * FROM %s WHERE v = 0 AND k = 0 AND c1 = 1 AND c2 >= 2", "SELECT * FROM %s WHERE k = 0 AND c1 = 1 AND c2 >= 2 AND v = 0 ALLOW FILTERING");
assertToCQLString("SELECT * FROM %s WHERE v = 0 AND k = 0 AND c1 = 1 AND c2 <= 2", "SELECT * FROM %s WHERE k = 0 AND c1 = 1 AND c2 <= 2 AND v = 0 ALLOW FILTERING");

// test with multi-column partition key and index
createTable("CREATE TABLE %s (k1 int, k2 int, c int, v int, PRIMARY KEY ((k1, k2), c))");
createIndex("CREATE INDEX ON %s(v)");
assertToCQLString("SELECT * FROM %s WHERE v = 1 AND k1 = 1 AND k2 = 2", "SELECT * FROM %s WHERE k1 = 1 AND k2 = 2 AND v = 1 ALLOW FILTERING");
assertToCQLString("SELECT * FROM %s WHERE v = 1 AND k1 = 1 AND k2 = 2 AND c = 3", "SELECT * FROM %s WHERE k1 = 1 AND k2 = 2 AND c = 3 AND v = 1 ALLOW FILTERING");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public void testToCQLString()
assertToCQLString("SELECT * FROM %s WHERE k = 0 AND c < 0 AND v = 1 ALLOW FILTERING", "SELECT * FROM %s WHERE k = 0 AND c < 0 AND v = 1 ALLOW FILTERING");
assertToCQLString("SELECT * FROM %s WHERE k = 0 AND c >= 0 AND v = 1 ALLOW FILTERING", "SELECT * FROM %s WHERE k = 0 AND c >= 0 AND v = 1 ALLOW FILTERING");
assertToCQLString("SELECT * FROM %s WHERE k = 0 AND c <= 0 AND v = 1 ALLOW FILTERING", "SELECT * FROM %s WHERE k = 0 AND c <= 0 AND v = 1 ALLOW FILTERING");

// test with multi-column partition key (without index to test SinglePartitionReadCommand directly)
createTable("CREATE TABLE %s (k1 int, k2 int, c int, v int, PRIMARY KEY ((k1, k2), c))");
assertToCQLString("SELECT * FROM %s WHERE k1 = 1 AND k2 = 2", "SELECT * FROM %s WHERE k1 = 1 AND k2 = 2 ALLOW FILTERING");
assertToCQLString("SELECT * FROM %s WHERE k1 = 1 AND k2 = 2 AND c = 3", "SELECT * FROM %s WHERE k1 = 1 AND k2 = 2 AND c = 3 ALLOW FILTERING");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.exceptions.InvalidRequestException;
import org.apache.cassandra.io.sstable.format.SSTableFormat;
import org.apache.cassandra.io.sstable.format.SSTableReader;
import org.apache.cassandra.io.sstable.format.Version;
Expand Down