cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sn...@apache.org
Subject cassandra git commit: Log warning when using an aggregate without partition key
Date Mon, 03 Aug 2015 19:53:30 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 f60abbdd5 -> 5a54d9a62


Log warning when using an aggregate without partition key

patch by Robert Stupp; reviewed by Aleksey Yeschenko for CASSANDRA-9737


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

Branch: refs/heads/cassandra-2.2
Commit: 5a54d9a6240daa9e58dde702245f574002a42783
Parents: f60abbd
Author: Robert Stupp <snazy@snazy.de>
Authored: Mon Aug 3 21:51:34 2015 +0200
Committer: Robert Stupp <snazy@snazy.de>
Committed: Mon Aug 3 21:51:34 2015 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../restrictions/StatementRestrictions.java     |  5 +++++
 .../cql3/statements/SelectStatement.java        | 21 ++++++++++++++++++--
 3 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/5a54d9a6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 401f426..66e5a0c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.1
+ * Log warning when using an aggregate without partition key (CASSANDRA-9737)
  * Avoid grouping sstables for anticompaction with DTCS (CASSANDRA-9900)
  * UDF / UDA execution time in trace (CASSANDRA-9723)
  * Fix broken internode SSL (CASSANDRA-9884)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5a54d9a6/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 c10a56a..55c6808 100644
--- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
+++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java
@@ -256,6 +256,11 @@ public final class StatementRestrictions
         return partitionKeyRestrictions.size() <  cfm.partitionKeyColumns().size();
     }
 
+    public boolean hasPartitionKeyRestrictions()
+    {
+        return !partitionKeyRestrictions.isEmpty();
+    }
+
     /**
      * Returns the partition key components that are not restricted.
      * @return the partition key components that are not restricted.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/5a54d9a6/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 cd0eeaa..3edb7d0 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -25,6 +25,9 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Iterators;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.cassandra.auth.Permission;
 import org.apache.cassandra.config.CFMetaData;
 import org.apache.cassandra.config.ColumnDefinition;
@@ -44,6 +47,7 @@ import org.apache.cassandra.dht.AbstractBounds;
 import org.apache.cassandra.exceptions.*;
 import org.apache.cassandra.serializers.MarshalException;
 import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.service.ClientWarn;
 import org.apache.cassandra.service.QueryState;
 import org.apache.cassandra.service.StorageProxy;
 import org.apache.cassandra.service.pager.Pageable;
@@ -71,6 +75,8 @@ import static org.apache.cassandra.utils.ByteBufferUtil.UNSET_BYTE_BUFFER;
  */
 public class SelectStatement implements CQLStatement
 {
+    private static final Logger logger = LoggerFactory.getLogger(SelectStatement.class);
+
     private static final int DEFAULT_COUNT_PAGE_SIZE = 10000;
 
     private final int boundTerms;
@@ -242,10 +248,21 @@ public class SelectStatement implements CQLStatement
     private ResultMessage.Rows pageAggregateQuery(QueryPager pager, QueryOptions options,
int pageSize, long now)
             throws RequestValidationException, RequestExecutionException
     {
+        if (!restrictions.hasPartitionKeyRestrictions())
+        {
+            logger.warn("Aggregation query used without partition key");
+            ClientWarn.warn("Aggregation query used without partition key");
+        }
+        else if (restrictions.keyIsInRelation())
+        {
+            logger.warn("Aggregation query used on multiple partition keys (IN restriction)");
+            ClientWarn.warn("Aggregation query used on multiple partition keys (IN restriction)");
+        }
+
         Selection.ResultSetBuilder result = selection.resultSetBuilder(now, parameters.isJson);
         while (!pager.isExhausted())
         {
-            for (org.apache.cassandra.db.Row row : pager.fetchPage(pageSize))
+            for (Row row : pager.fetchPage(pageSize))
             {
                 // Not columns match the query, skip
                 if (row.cf == null)
@@ -619,7 +636,7 @@ public class SelectStatement implements CQLStatement
     private ResultSet process(List<Row> rows, QueryOptions options, int limit, long
now) throws InvalidRequestException
     {
         Selection.ResultSetBuilder result = selection.resultSetBuilder(now, parameters.isJson);
-        for (org.apache.cassandra.db.Row row : rows)
+        for (Row row : rows)
         {
             // Not columns match the query, skip
             if (row.cf == null)


Mime
View raw message