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 <ty...@datastax.com> Authored: Wed Apr 2 14:27:35 2014 -0500 Committer: Tyler Hobbs <ty...@datastax.com> 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);