Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D432518EB1 for ; Tue, 18 Aug 2015 07:05:22 +0000 (UTC) Received: (qmail 28629 invoked by uid 500); 18 Aug 2015 07:05:22 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 28598 invoked by uid 500); 18 Aug 2015 07:05:22 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 28587 invoked by uid 99); 18 Aug 2015 07:05:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Aug 2015 07:05:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7F3ACE057C; Tue, 18 Aug 2015 07:05:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: slebresne@apache.org To: commits@cassandra.apache.org Message-Id: <3c687c9ff86c4f1b873a73e60ded9def@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cassandra git commit: Fix queries on static compact tables Date: Tue, 18 Aug 2015 07:05:22 +0000 (UTC) Repository: cassandra Updated Branches: refs/heads/cassandra-3.0 df65a6c68 -> 235032050 Fix queries on static compact tables patch by slebresne; reviewed by iamaleskey for CASSANDRA-10093 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/23503205 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/23503205 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/23503205 Branch: refs/heads/cassandra-3.0 Commit: 2350320501bcd26085181b929f4718cb12d08b41 Parents: df65a6c Author: Sylvain Lebresne Authored: Mon Aug 17 15:00:41 2015 +0200 Committer: Sylvain Lebresne Committed: Tue Aug 18 09:04:24 2015 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cql3/restrictions/StatementRestrictions.java | 11 ++++++++++- .../cassandra/cql3/statements/SelectStatement.java | 5 ++++- src/java/org/apache/cassandra/db/Clustering.java | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index b4b568c..54a6a07 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.0-beta1 + * Fix query on static compact tables (CASSANDRA-10093) * Fix race during construction of commit log (CASSANDRA-10049) * Add option to only purge repaired tombstones (CASSANDRA-6434) * Change authorization handling for MVs (CASSANDRA-9927) http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java index 1a3b083..36f11ad 100644 --- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java +++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java @@ -35,6 +35,7 @@ import org.apache.cassandra.dht.*; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.btree.BTreeSet; import static org.apache.cassandra.cql3.statements.RequestValidations.checkFalse; import static org.apache.cassandra.cql3.statements.RequestValidations.checkNotNull; @@ -478,6 +479,12 @@ public final class StatementRestrictions */ public NavigableSet getClusteringColumns(QueryOptions options) throws InvalidRequestException { + // If this is a names command and the table is a static compact one, then as far as CQL is concerned we have + // only a single row which internally correspond to the static parts. In which case we want to return an empty + // set (since that's what ClusteringIndexNamesFilter expects). + if (cfm.isStaticCompactTable()) + return BTreeSet.empty(cfm.comparator); + return clusteringColumnsRestrictions.valuesAsClustering(options); } @@ -513,7 +520,9 @@ public final class StatementRestrictions */ public boolean isColumnRange() { - // For static compact tables we need to ignore the fake clustering column. + // For static compact tables we want to ignore the fake clustering column (note that if we weren't special casing, + // this would mean a 'SELECT *' on a static compact table would query whole partitions, even though we'll only return + // the static part as far as CQL is concerned. This is thus mostly an optimization to use the query-by-name path). int numberOfClusteringColumns = cfm.isStaticCompactTable() ? 0 : cfm.clusteringColumns().size(); // it is a range query if it has at least one the column alias for which no relation is defined or is not EQ. return clusteringColumnsRestrictions.size() < numberOfClusteringColumns http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java index 9acbb35..01ce8e6 100644 --- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java @@ -484,7 +484,10 @@ public class SelectStatement implements CQLStatement else { NavigableSet clusterings = getRequestedRows(options); - if (clusterings.isEmpty() && !selection.containsStaticColumns()) // in case of IN () for the last column of the key + // We can have no clusterings if either we're only selecting the static columns, or if we have + // a 'IN ()' for clusterings. In that case, we still want to query if some static columns are + // queried. But we're fine otherwise. + if (clusterings.isEmpty() && queriedColumns.fetchedColumns().statics.isEmpty()) return null; return new ClusteringIndexNamesFilter(clusterings, isReversed); http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/src/java/org/apache/cassandra/db/Clustering.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/Clustering.java b/src/java/org/apache/cassandra/db/Clustering.java index a29ce65..2fb92d9 100644 --- a/src/java/org/apache/cassandra/db/Clustering.java +++ b/src/java/org/apache/cassandra/db/Clustering.java @@ -134,6 +134,7 @@ public class Clustering extends AbstractClusteringPrefix public void serialize(Clustering clustering, DataOutputPlus out, int version, List> types) throws IOException { assert clustering != STATIC_CLUSTERING : "We should never serialize a static clustering"; + assert clustering.size() == types.size() : "Invalid clustering for the table: " + clustering; ClusteringPrefix.serializer.serializeValuesWithoutSize(clustering, out, version, types); }