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 5EECB107A1 for ; Wed, 2 Apr 2014 19:56:10 +0000 (UTC) Received: (qmail 58091 invoked by uid 500); 2 Apr 2014 19:56:10 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 57832 invoked by uid 500); 2 Apr 2014 19:56:08 -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 57805 invoked by uid 99); 2 Apr 2014 19:56:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Apr 2014 19:56:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 2CB0892619D; Wed, 2 Apr 2014 19:56:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tylerhobbs@apache.org To: commits@cassandra.apache.org Date: Wed, 02 Apr 2014 19:56:04 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: Handle short slice start/finishes of different lengths Repository: cassandra Updated Branches: refs/heads/cassandra-2.1 5ab1a341a -> e34d1af96 Handle short slice start/finishes of different lengths Patch by Tyler Hobbs; reviewed by Sylvain Lebresne as a follow-up for CASSANDRA-6825 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f4f74177 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f4f74177 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f4f74177 Branch: refs/heads/cassandra-2.1 Commit: f4f7417735e179c73334ecfb3df6aeb1467b6842 Parents: 5aafa98 Author: Tyler Hobbs Authored: Wed Apr 2 14:27:35 2014 -0500 Committer: Tyler Hobbs Committed: Wed Apr 2 14:29:44 2014 -0500 ---------------------------------------------------------------------- src/java/org/apache/cassandra/db/marshal/CompositeType.java | 8 +++++--- .../org/apache/cassandra/db/marshal/CompositeTypeTest.java | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/f4f74177/src/java/org/apache/cassandra/db/marshal/CompositeType.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/marshal/CompositeType.java b/src/java/org/apache/cassandra/db/marshal/CompositeType.java index 7f08219..32fc432 100644 --- a/src/java/org/apache/cassandra/db/marshal/CompositeType.java +++ b/src/java/org/apache/cassandra/db/marshal/CompositeType.java @@ -278,16 +278,18 @@ public class CompositeType extends AbstractCompositeType // We could safely return true here, but there's a minor optimization: if the first component is restricted // to a single value, we can check that the second component falls within the min/max for that component // (and repeat for all components). - for (int i = 0; i < Math.min(Math.min(start.length, finish.length), minColumnNames.size()); i++) + for (int i = 0; i < minColumnNames.size(); i++) { AbstractType t = types.get(i); + ByteBuffer s = i < start.length ? start[i] : ByteBufferUtil.EMPTY_BYTE_BUFFER; + ByteBuffer f = i < finish.length ? finish[i] : ByteBufferUtil.EMPTY_BYTE_BUFFER; // we already know the first component falls within its min/max range (otherwise we wouldn't get here) - if (i > 0 && !t.intersects(minColumnNames.get(i), maxColumnNames.get(i), start[i], finish[i])) + if (i > 0 && !t.intersects(minColumnNames.get(i), maxColumnNames.get(i), s, f)) continue outer; // if this component isn't equal in the start and finish, we don't need to check any more - if (t.compare(start[i], finish[i]) != 0) + if (i >= start.length || i >= finish.length || t.compare(s, f) != 0) break; } return true; http://git-wip-us.apache.org/repos/asf/cassandra/blob/f4f74177/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java b/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java index 20cb5ef..df6f5e1 100644 --- a/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java +++ b/test/unit/org/apache/cassandra/db/marshal/CompositeTypeTest.java @@ -458,6 +458,10 @@ public class CompositeTypeTest extends SchemaLoader filter = new SliceQueryFilter(composite(1, 2), composite(1, 3), false, 1); assertFalse(comparator.intersects(columnNames(1, 0, 0), columnNames(2, 1, 0), filter)); + // same case, but with missing start and end components and different lengths for start and end + filter = new SliceQueryFilter(composite(1, 2), composite(1), false, 1); + assertFalse(comparator.intersects(columnNames(1, 0, 0), columnNames(2, 1, 0), filter)); + // same as the previous set of tests, but the second component is equal in the slice start and end filter = new SliceQueryFilter(composite(1, 2, 0), composite(1, 2, 0), false, 1);