http://git-wip-us.apache.org/repos/asf/cassandra/blob/1aa97e30/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java index d738c46,1deeb9e..abbd36b --- a/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java +++ b/test/unit/org/apache/cassandra/cql3/restrictions/PrimaryKeyRestrictionSetTest.java @@@ -28,10 -28,13 +28,11 @@@ import org.apache.cassandra.config.Colu import org.apache.cassandra.cql3.*; import org.apache.cassandra.cql3.Term.MultiItemTerminal; import org.apache.cassandra.cql3.statements.Bound; -import org.apache.cassandra.db.ColumnFamilyType; -import org.apache.cassandra.db.composites.Composite; -import org.apache.cassandra.db.composites.Composite.EOC; -import org.apache.cassandra.db.composites.CompoundSparseCellNameType; ++ +import org.apache.cassandra.db.*; import org.apache.cassandra.db.marshal.AbstractType; import org.apache.cassandra.db.marshal.Int32Type; - import org.apache.cassandra.exceptions.InvalidRequestException; + import org.apache.cassandra.db.marshal.ReversedType; import org.apache.cassandra.utils.ByteBufferUtil; import static java.util.Arrays.asList; @@@ -41,28 -44,28 +42,28 @@@ import static org.junit.Assert.assertTr public class PrimaryKeyRestrictionSetTest { @Test - public void testboundsAsClusteringWithNoRestrictions() throws InvalidRequestException - public void testBoundsAsCompositesWithNoRestrictions() ++ public void testBoundsAsClusteringWithNoRestrictions() { - CFMetaData cfMetaData = newCFMetaData(1); + CFMetaData cfMetaData = newCFMetaData(Sort.ASC); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); + assertEmptyStart(get(bounds, 0)); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); + assertEmptyEnd(get(bounds, 0)); } /** * Test 'clustering_0 = 1' with only one clustering column */ @Test - public void testboundsAsClusteringWithOneEqRestrictionsAndOneClusteringColumn() throws InvalidRequestException - public void testBoundsAsCompositesWithOneEqRestrictionsAndOneClusteringColumn() ++ public void testBoundsAsClusteringWithOneEqRestrictionsAndOneClusteringColumn() { - CFMetaData cfMetaData = newCFMetaData(1); + CFMetaData cfMetaData = newCFMetaData(Sort.ASC); ByteBuffer clustering_0 = ByteBufferUtil.bytes(1); Restriction eq = newSingleEq(cfMetaData, 0, clustering_0); @@@ -83,9 -86,9 +84,9 @@@ * Test 'clustering_1 = 1' with 2 clustering columns */ @Test - public void testboundsAsClusteringWithOneEqRestrictionsAndTwoClusteringColumns() throws InvalidRequestException - public void testBoundsAsCompositesWithOneEqRestrictionsAndTwoClusteringColumns() ++ public void testBoundsAsClusteringWithOneEqRestrictionsAndTwoClusteringColumns() { - CFMetaData cfMetaData = newCFMetaData(2); + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC); ByteBuffer clustering_0 = ByteBufferUtil.bytes(1); Restriction eq = newSingleEq(cfMetaData, 0, clustering_0); @@@ -106,7 -109,7 +107,7 @@@ * Test 'clustering_0 IN (1, 2, 3)' with only one clustering column */ @Test - public void testboundsAsClusteringWithOneInRestrictionsAndOneClusteringColumn() throws InvalidRequestException - public void testBoundsAsCompositesWithOneInRestrictionsAndOneClusteringColumn() ++ public void testBoundsAsClusteringWithOneInRestrictionsAndOneClusteringColumn() { ByteBuffer value1 = ByteBufferUtil.bytes(1); ByteBuffer value2 = ByteBufferUtil.bytes(2); @@@ -136,9 -139,9 +137,9 @@@ * Test slice restriction (e.g 'clustering_0 > 1') with only one clustering column */ @Test - public void testboundsAsClusteringWithSliceRestrictionsAndOneClusteringColumn() throws InvalidRequestException - public void testBoundsAsCompositesWithSliceRestrictionsAndOneClusteringColumn() ++ public void testBoundsAsClusteringWithSliceRestrictionsAndOneClusteringColumn() { - CFMetaData cfMetaData = newCFMetaData(1); + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC); ByteBuffer value1 = ByteBufferUtil.bytes(1); ByteBuffer value2 = ByteBufferUtil.bytes(2); @@@ -219,12 -222,98 +220,98 @@@ } /** + * Test slice restriction (e.g 'clustering_0 > 1') with only one descending clustering column + */ + @Test - public void testBoundsAsCompositesWithSliceRestrictionsAndOneDescendingClusteringColumn() ++ public void testBoundsAsClusteringWithSliceRestrictionsAndOneDescendingClusteringColumn() + { + CFMetaData cfMetaData = newCFMetaData(Sort.DESC, Sort.DESC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + + Restriction slice = newSingleSlice(cfMetaData, 0, Bound.START, false, value1); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1); + + slice = newSingleSlice(cfMetaData, 0, Bound.START, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1); + + slice = newSingleSlice(cfMetaData, 0, Bound.END, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + slice = newSingleSlice(cfMetaData, 0, Bound.END, false, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertStartBound(get(bounds, 0), false, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + slice = newSingleSlice(cfMetaData, 0, Bound.START, false, value1); + Restriction slice2 = newSingleSlice(cfMetaData, 0, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.END); ++ assertStartBound(get(bounds, 0), false, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1); + + slice = newSingleSlice(cfMetaData, 0, Bound.START, true, value1); + slice2 = newSingleSlice(cfMetaData, 0, Bound.END, true, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1); + } + + /** * Test 'clustering_0 = 1 AND clustering_1 IN (1, 2, 3)' */ @Test - public void testboundsAsClusteringWithEqAndInRestrictions() throws InvalidRequestException - public void testBoundsAsCompositesWithEqAndInRestrictions() ++ public void testBoundsAsClusteringWithEqAndInRestrictions() { - CFMetaData cfMetaData = newCFMetaData(2); + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC); ByteBuffer value1 = ByteBufferUtil.bytes(1); ByteBuffer value2 = ByteBufferUtil.bytes(2); @@@ -251,9 -340,9 +338,9 @@@ * Test equal and slice restrictions (e.g 'clustering_0 = 0 clustering_1 > 1') */ @Test - public void testboundsAsClusteringWithEqAndSliceRestrictions() throws InvalidRequestException - public void testBoundsAsCompositesWithEqAndSliceRestrictions() ++ public void testBoundsAsClusteringWithEqAndSliceRestrictions() { - CFMetaData cfMetaData = newCFMetaData(2); + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC); ByteBuffer value1 = ByteBufferUtil.bytes(1); ByteBuffer value2 = ByteBufferUtil.bytes(2); @@@ -262,314 -351,1059 +349,1059 @@@ Restriction eq = newSingleEq(cfMetaData, 0, value3); Restriction slice = newSingleSlice(cfMetaData, 1, Bound.START, false, value1); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); restrictions = restrictions.mergeWith(eq).mergeWith(slice); - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value1, EOC.END); + assertStartBound(get(bounds, 0), false, value3, value1); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), true, value3); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, EOC.END); ++ assertEndBound(get(bounds, 0), true, value3); + + slice = newSingleSlice(cfMetaData, 1, Bound.START, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(eq).mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value3, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, EOC.END); ++ assertEndBound(get(bounds, 0), true, value3); + + slice = newSingleSlice(cfMetaData, 1, Bound.END, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(eq).mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, EOC.START); ++ assertStartBound(get(bounds, 0), true, value3); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value3, value1); + + slice = newSingleSlice(cfMetaData, 1, Bound.END, false, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(eq).mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, EOC.START); ++ assertStartBound(get(bounds, 0), true, value3); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value1, EOC.START); ++ assertEndBound(get(bounds, 0), false, value3, value1); + + slice = newSingleSlice(cfMetaData, 1, Bound.START, false, value1); + Restriction slice2 = newSingleSlice(cfMetaData, 1, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(eq).mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value1, EOC.END); ++ assertStartBound(get(bounds, 0), false, value3, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value2, EOC.START); ++ assertEndBound(get(bounds, 0), false, value3, value2); + + slice = newSingleSlice(cfMetaData, 1, Bound.START, true, value1); + slice2 = newSingleSlice(cfMetaData, 1, Bound.END, true, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(eq).mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value3, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value3, value2, EOC.END); ++ assertEndBound(get(bounds, 0), true, value3, value2); + } + + /** + * Test '(clustering_0, clustering_1) = (1, 2)' with two clustering column + */ + @Test - public void testBoundsAsCompositesWithMultiEqRestrictions() ++ public void testBoundsAsClusteringWithMultiEqRestrictions() + { + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + Restriction eq = newMultiEq(cfMetaData, 0, value1, value2); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(eq); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); ++ assertStartBound(get(bounds, 0), true, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1, value2); + } + + /** + * Test '(clustering_0, clustering_1) IN ((1, 2), (2, 3))' with two clustering column + */ + @Test - public void testBoundsAsCompositesWithMultiInRestrictions() ++ public void testBoundsAsClusteringWithMultiInRestrictions() + { + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + ByteBuffer value3 = ByteBufferUtil.bytes(3); + Restriction in = newMultiIN(cfMetaData, 0, asList(value1, value2), asList(value2, value3)); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(in); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value2, value3, EOC.START); ++ assertStartBound(get(bounds, 0), true, value1, value2); ++ assertStartBound(get(bounds, 1), true, value2, value3); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); - assertComposite(bounds.get(1), value2, value3, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1, value2); ++ assertEndBound(get(bounds, 1), true, value2, value3); + } + + /** + * Test multi-column slice restrictions (e.g '(clustering_0) > (1)') with only one clustering column + */ + @Test - public void testBoundsAsCompositesWithMultiSliceRestrictionsWithOneClusteringColumn() ++ public void testBoundsAsClusteringWithMultiSliceRestrictionsWithOneClusteringColumn() + { + CFMetaData cfMetaData = newCFMetaData(Sort.ASC); + ++ + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + + Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertStartBound(get(bounds, 0), false, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1); + + slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1); + + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1); + Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertStartBound(get(bounds, 0), false, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.START); ++ assertEndBound(get(bounds, 0), false, value2); + + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.END); ++ assertEndBound(get(bounds, 0), true, value2); + } + + /** + * Test multi-column slice restrictions (e.g '(clustering_0) > (1)') with only one clustering column in reverse + * order + */ + @Test - public void testBoundsAsCompositesWithMultiSliceRestrictionsWithOneDescendingClusteringColumn() ++ public void testBoundsAsClusteringWithMultiSliceRestrictionsWithOneDescendingClusteringColumn() + { + CFMetaData cfMetaData = newCFMetaData(Sort.DESC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + + Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1); + + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1); + + slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertStartBound(get(bounds, 0), false, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1); + Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.END); ++ assertStartBound(get(bounds, 0), false, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1); + + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1); + } + + /** + * Test multi-column slice restrictions (e.g '(clustering_0, clustering_1) > (1, 2)') + */ + @Test - public void testBoundsAsCompositesWithMultiSliceRestrictionsWithTwoClusteringColumn() ++ public void testBoundsAsClusteringWithMultiSliceRestrictionsWithTwoClusteringColumn() + { + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + + // (clustering_0, clustering1) > (1, 2) + Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); ++ assertStartBound(get(bounds, 0), false, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + // (clustering_0, clustering1) >= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + // (clustering_0, clustering1) <= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1, value2); + + // (clustering_0, clustering1) < (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1, value2); + + // (clustering_0, clustering1) > (1, 2) AND (clustering_0) < (2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); + Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); ++ assertStartBound(get(bounds, 0), false, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.START); ++ assertEndBound(get(bounds, 0), false, value2); + + // (clustering_0, clustering1) >= (1, 2) AND (clustering_0, clustering1) <= (2, 1) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value2, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value2, value1); + } + + /** + * Test multi-column slice restrictions with 2 descending clustering columns (e.g '(clustering_0, clustering_1) > (1, 2)') + */ + @Test - public void testBoundsAsCompositesWithMultiSliceRestrictionsWithTwoDescendingClusteringColumns() ++ public void testBoundsAsClusteringWithMultiSliceRestrictionsWithTwoDescendingClusteringColumns() + { + CFMetaData cfMetaData = newCFMetaData(Sort.DESC, Sort.DESC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + + // (clustering_0, clustering1) > (1, 2) + Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1, value2); + + // (clustering_0, clustering1) >= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyStart(get(bounds, 0)); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1, value2); + + // (clustering_0, clustering1) <= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + // (clustering_0, clustering1) < (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); ++ assertStartBound(get(bounds, 0), false, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); ++ assertEmptyEnd(get(bounds, 0)); + + + // (clustering_0, clustering1) > (1, 2) AND (clustering_0) < (2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); + Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.END); ++ assertStartBound(get(bounds, 0), false, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1, value2); + + // (clustering_0, clustering1) >= (1, 2) AND (clustering_0, clustering1) <= (2, 1) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value2, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value2, value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value2, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(1, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1, value2); + } + + /** + * Test multi-column slice restrictions with 1 descending clustering column and 1 ascending + * (e.g '(clustering_0, clustering_1) > (1, 2)') + */ + @Test - public void testBoundsAsCompositesWithMultiSliceRestrictionsWithOneDescendingAndOneAscendingClusteringColumns() ++ public void testBoundsAsClusteringWithMultiSliceRestrictionsWithOneDescendingAndOneAscendingClusteringColumns() + { + CFMetaData cfMetaData = newCFMetaData(Sort.DESC, Sort.ASC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + + // (clustering_0, clustering1) > (1, 2) + Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertEmptyComposite(bounds.get(0)); - assertComposite(bounds.get(1), value1, value2, EOC.END); ++ assertEmptyStart(get(bounds, 0)); ++ assertStartBound(get(bounds, 1), false, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1); ++ assertEndBound(get(bounds, 1), true, value1); + + // (clustering_0, clustering1) >= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertEmptyComposite(bounds.get(0)); - assertComposite(bounds.get(1), value1, value2, EOC.NONE); ++ assertEmptyStart(get(bounds, 0)); ++ assertStartBound(get(bounds, 1), true, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1); ++ assertEndBound(get(bounds, 1), true, value1); + + // (clustering_0, clustering1) <= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1); ++ assertStartBound(get(bounds, 1), false, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); - assertEmptyComposite(bounds.get(1)); ++ assertEndBound(get(bounds, 0), true, value1, value2); ++ assertEmptyEnd(get(bounds, 1)); + + // (clustering_0, clustering1) < (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1); ++ assertStartBound(get(bounds, 1), false, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertEmptyComposite(bounds.get(1)); ++ assertEndBound(get(bounds, 0), false, value1, value2); ++ assertEmptyEnd(get(bounds, 1)); + + // (clustering_0, clustering1) > (1, 2) AND (clustering_0) < (2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); + Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.END); - assertComposite(bounds.get(1), value1, value2, EOC.END); ++ assertStartBound(get(bounds, 0), false, value2); ++ assertStartBound(get(bounds, 1), false, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1); ++ assertEndBound(get(bounds, 1), true, value1); + + // (clustering_0) > (1) AND (clustering_0, clustering1) < (2, 1) + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.START); - assertComposite(bounds.get(1), value2, EOC.END); ++ assertStartBound(get(bounds, 0), true, value2); ++ assertStartBound(get(bounds, 1), false, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value2, value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.START); ++ assertEndBound(get(bounds, 0), false, value2, value1); ++ assertEndBound(get(bounds, 1), false, value1); + + // (clustering_0, clustering1) >= (1, 2) AND (clustering_0, clustering1) <= (2, 1) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value2, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); + - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(3, bounds.size()); - assertComposite(bounds.get(0), value2, EOC.START); - assertComposite(bounds.get(1), value2, EOC.END); - assertComposite(bounds.get(2), value1, value2, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value2); ++ assertStartBound(get(bounds, 1), false, value2); ++ assertStartBound(get(bounds, 2), true, value1, value2); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(3, bounds.size()); - assertComposite(bounds.get(0), value2, value1, EOC.END); - assertComposite(bounds.get(1), value1, EOC.START); - assertComposite(bounds.get(2), value1, EOC.END); ++ assertEndBound(get(bounds, 0), true, value2, value1); ++ assertEndBound(get(bounds, 1), false, value1); ++ assertEndBound(get(bounds, 2), true, value1); + } + + /** + * Test multi-column slice restrictions with 1 descending clustering column and 1 ascending + * (e.g '(clustering_0, clustering_1) > (1, 2)') + */ + @Test - public void testBoundsAsCompositesWithMultiSliceRestrictionsWithOneAscendingAndOneDescendingClusteringColumns() ++ public void testBoundsAsClusteringWithMultiSliceRestrictionsWithOneAscendingAndOneDescendingClusteringColumns() + { + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.DESC); + + ByteBuffer value1 = ByteBufferUtil.bytes(1); + ByteBuffer value2 = ByteBufferUtil.bytes(2); + + // (clustering_0, clustering1) > (1, 2) + Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1); ++ assertStartBound(get(bounds, 1), false, value1); + - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertEmptyComposite(bounds.get(1)); ++ assertEndBound(get(bounds, 0), false, value1, value2); ++ assertEmptyEnd(get(bounds, 1)); - slice = newSingleSlice(cfMetaData, 1, Bound.START, true, value1); + // (clustering_0, clustering1) >= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - restrictions = restrictions.mergeWith(eq).mergeWith(slice); + restrictions = restrictions.mergeWith(slice); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), true, value3, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1); ++ assertStartBound(get(bounds, 1), false, value1); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), true, value3); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); - assertEmptyComposite(bounds.get(1)); ++ assertEndBound(get(bounds, 0), true, value1, value2); ++ assertEmptyEnd(get(bounds, 1)); - slice = newSingleSlice(cfMetaData, 1, Bound.END, true, value1); + // (clustering_0, clustering1) <= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - restrictions = restrictions.mergeWith(eq).mergeWith(slice); + restrictions = restrictions.mergeWith(slice); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), true, value3); + assertEquals(2, bounds.size()); - assertEmptyComposite(bounds.get(0)); - assertComposite(bounds.get(1), value1, value2, EOC.NONE); ++ assertEmptyStart(get(bounds, 0)); ++ assertStartBound(get(bounds, 1), true, value1, value2); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), true, value3, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1); ++ assertEndBound(get(bounds, 1), true, value1); - slice = newSingleSlice(cfMetaData, 1, Bound.END, false, value1); + // (clustering_0, clustering1) < (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - restrictions = restrictions.mergeWith(eq).mergeWith(slice); + restrictions = restrictions.mergeWith(slice); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), true, value3); + assertEquals(2, bounds.size()); - assertEmptyComposite(bounds.get(0)); - assertComposite(bounds.get(1), value1, value2, EOC.END); ++ assertEmptyStart(get(bounds, 0)); ++ assertStartBound(get(bounds, 1), false, value1, value2); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), false, value3, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1); ++ assertEndBound(get(bounds, 1), true, value1); - slice = newSingleSlice(cfMetaData, 1, Bound.START, false, value1); - Restriction slice2 = newSingleSlice(cfMetaData, 1, Bound.END, false, value2); + // (clustering_0, clustering1) > (1, 2) AND (clustering_0) < (2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2); + Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - restrictions = restrictions.mergeWith(eq).mergeWith(slice).mergeWith(slice2); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), false, value3, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1); ++ assertStartBound(get(bounds, 1), false, value1); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), false, value3, value2); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value2, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1, value2); ++ assertEndBound(get(bounds, 1), false, value2); - slice = newSingleSlice(cfMetaData, 1, Bound.START, true, value1); - slice2 = newSingleSlice(cfMetaData, 1, Bound.END, true, value2); + // (clustering_0, clustering1) >= (1, 2) AND (clustering_0, clustering1) <= (2, 1) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value2, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - restrictions = restrictions.mergeWith(eq).mergeWith(slice).mergeWith(slice2); + restrictions = restrictions.mergeWith(slice).mergeWith(slice2); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), true, value3, value1); + assertEquals(3, bounds.size()); - assertComposite(bounds.get(0), value1, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); - assertComposite(bounds.get(2), value2, value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1); ++ assertStartBound(get(bounds, 1), false, value1); ++ assertStartBound(get(bounds, 2), true, value2, value1); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), true, value3, value2); + assertEquals(3, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.END); - assertComposite(bounds.get(1), value2, EOC.START); - assertComposite(bounds.get(2), value2, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1, value2); ++ assertEndBound(get(bounds, 1), false, value2); ++ assertEndBound(get(bounds, 2), true, value2); } /** - * Test '(clustering_0, clustering_1) = (1, 2)' with two clustering column + * Test multi-column slice restrictions with 2 ascending clustering column and 2 descending + * (e.g '(clustering_0, clustering1, clustering_3, clustering4) > (1, 2, 3, 4)') */ @Test - public void testboundsAsClusteringWithMultiEqRestrictions() throws InvalidRequestException - public void testBoundsAsCompositesWithMultiSliceRestrictionsWithTwoAscendingAndTwoDescendingClusteringColumns() ++ public void testBoundsAsClusteringWithMultiSliceRestrictionsWithTwoAscendingAndTwoDescendingClusteringColumns() { - CFMetaData cfMetaData = newCFMetaData(2); + CFMetaData cfMetaData = newCFMetaData(Sort.ASC, Sort.ASC, Sort.DESC, Sort.DESC); ByteBuffer value1 = ByteBufferUtil.bytes(1); ByteBuffer value2 = ByteBufferUtil.bytes(2); - Restriction eq = newMultiEq(cfMetaData, 0, value1, value2); + ByteBuffer value3 = ByteBufferUtil.bytes(3); + ByteBuffer value4 = ByteBufferUtil.bytes(4); + + // (clustering_0, clustering1, clustering_2, clustering_3) > (1, 2, 3, 4) + Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2, value3, value4); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - restrictions = restrictions.mergeWith(eq); + restrictions = restrictions.mergeWith(slice); - List<Composite> bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); + assertStartBound(get(bounds, 0), true, value1, value2); ++ assertStartBound(get(bounds, 1), false, value1, value2); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), true, value1, value2); - } - - /** - * Test '(clustering_0, clustering_1) IN ((1, 2), (2, 3))' with two clustering column - */ - @Test - public void testboundsAsClusteringWithMultiInRestrictions() throws InvalidRequestException - { - CFMetaData cfMetaData = newCFMetaData(2); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, value3, value4, EOC.START); - assertEmptyComposite(bounds.get(1)); ++ assertEndBound(get(bounds, 0), false, value1, value2, value3, value4); ++ assertEmptyEnd(get(bounds, 1)); - ByteBuffer value1 = ByteBufferUtil.bytes(1); - ByteBuffer value2 = ByteBufferUtil.bytes(2); - ByteBuffer value3 = ByteBufferUtil.bytes(3); - Restriction in = newMultiIN(cfMetaData, 0, asList(value1, value2), asList(value2, value3)); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - restrictions = restrictions.mergeWith(in); + // clustering_0 = 1 AND (clustering_1, clustering_2, clustering_3) > (2, 3, 4) + Restriction eq = newSingleEq(cfMetaData, 0, value1); + slice = newMultiSlice(cfMetaData, 1, Bound.START, false, value2, value3, value4); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + restrictions = restrictions.mergeWith(eq); - SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); + assertStartBound(get(bounds, 0), true, value1, value2); - assertStartBound(get(bounds, 1), true, value2, value3); ++ assertStartBound(get(bounds, 1), false, value1, value2); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); assertEquals(2, bounds.size()); - assertEndBound(get(bounds, 0), true, value1, value2); - assertEndBound(get(bounds, 1), true, value2, value3); - } - assertComposite(bounds.get(0), value1, value2, value3, value4, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1, value2, value3, value4); ++ assertEndBound(get(bounds, 1), true, value1); - /** - * Test multi-column slice restrictions (e.g '(clustering_0) > (1)') with only one clustering column - */ - @Test - public void testboundsAsClusteringWithMultiSliceRestrictionsWithOneClusteringColumn() throws InvalidRequestException - { - CFMetaData cfMetaData = newCFMetaData(1); - // clustering_0 = 1 AND (clustering_1, clustering_2, clustering_3) > (2, 3, 4) ++ // clustering_0 IN (1, 2) AND (clustering_1, clustering_2, clustering_3) > (2, 3, 4) + Restriction in = newSingleIN(cfMetaData, 0, value1, value2); + slice = newMultiSlice(cfMetaData, 1, Bound.START, false, value2, value3, value4); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); + restrictions = restrictions.mergeWith(slice); + restrictions = restrictions.mergeWith(in); - ByteBuffer value1 = ByteBufferUtil.bytes(1); - ByteBuffer value2 = ByteBufferUtil.bytes(2); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); + assertEquals(4, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); - assertComposite(bounds.get(2), value2, value2, EOC.START); - assertComposite(bounds.get(3), value2, value2, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1, value2); ++ assertStartBound(get(bounds, 1), false, value1, value2); ++ assertStartBound(get(bounds, 2), true, value2, value2); ++ assertStartBound(get(bounds, 3), false, value2, value2); - Restriction slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1); - PrimaryKeyRestrictions restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); + assertEquals(4, bounds.size()); - assertComposite(bounds.get(0), value1, value2, value3, value4, EOC.START); - assertComposite(bounds.get(1), value1, EOC.END); - assertComposite(bounds.get(2), value2, value2, value3, value4, EOC.START); - assertComposite(bounds.get(3), value2, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1, value2, value3, value4); ++ assertEndBound(get(bounds, 1), true, value1); ++ assertEndBound(get(bounds, 2), false, value2, value2, value3, value4); ++ assertEndBound(get(bounds, 3), true, value2); + + // (clustering_0, clustering1) >= (1, 2) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); ++ restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); restrictions = restrictions.mergeWith(slice); - SortedSet<Slice.Bound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); ++ bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), false, value1); - assertComposite(bounds.get(0), value1, value2, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1, value2); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); assertEquals(1, bounds.size()); - assertEmptyComposite(bounds.get(0)); + assertEmptyEnd(get(bounds, 0)); - slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1); + // (clustering_0, clustering1, clustering_2, clustering_3) >= (1, 2, 3, 4) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2, value3, value4); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); restrictions = restrictions.mergeWith(slice); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), true, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1, value2); ++ assertStartBound(get(bounds, 1), false, value1, value2); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEmptyEnd(get(bounds, 0)); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, value3, value4, EOC.END); - assertEmptyComposite(bounds.get(1)); ++ assertEndBound(get(bounds, 0), true, value1, value2, value3, value4); ++ assertEmptyEnd(get(bounds, 1)); - slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1); + // (clustering_0, clustering1, clustering_2, clustering_3) <= (1, 2, 3, 4) + slice = newMultiSlice(cfMetaData, 0, Bound.END, true, value1, value2, value3, value4); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); restrictions = restrictions.mergeWith(slice); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); + assertEquals(2, bounds.size()); - assertEmptyComposite(bounds.get(0)); - assertComposite(bounds.get(1), value1, value2, value3, value4, EOC.NONE); + assertEmptyStart(get(bounds, 0)); ++ assertStartBound(get(bounds, 1), true, value1, value2, value3, value4); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), true, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1, value2); ++ assertEndBound(get(bounds, 1), true, value1, value2); - slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1); + // (clustering_0, clustering1, clustering_2, clustering_3) < (1, 2, 3, 4) + slice = newMultiSlice(cfMetaData, 0, Bound.END, false, value1, value2, value3, value4); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); restrictions = restrictions.mergeWith(slice); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); + assertEquals(2, bounds.size()); - assertEmptyComposite(bounds.get(0)); - assertComposite(bounds.get(1), value1, value2, value3, value4, EOC.END); + assertEmptyStart(get(bounds, 0)); ++ assertStartBound(get(bounds, 1), false, value1, value2, value3, value4); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), false, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); ++ assertEndBound(get(bounds, 0), false, value1, value2); ++ assertEndBound(get(bounds, 1), true, value1, value2); - slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1); - Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2); + // (clustering_0, clustering1, clustering_2, clustering_3) > (1, 2, 3, 4) AND (clustering_0, clustering_1) < (2, 3) + slice = newMultiSlice(cfMetaData, 0, Bound.START, false, value1, value2, value3, value4); + Restriction slice2 = newMultiSlice(cfMetaData, 0, Bound.END, false, value2, value3); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); restrictions = restrictions.mergeWith(slice).mergeWith(slice2); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), false, value1); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); ++ assertStartBound(get(bounds, 0), true, value1, value2); ++ assertStartBound(get(bounds, 1), false, value1, value2); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), false, value2); + assertEquals(2, bounds.size()); - assertComposite(bounds.get(0), value1, value2, value3, value4, EOC.START); - assertComposite(bounds.get(1), value2, value3, EOC.START); ++ assertEndBound(get(bounds, 0), false, value1, value2, value3, value4); ++ assertEndBound(get(bounds, 1), false, value2, value3); - slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1); - slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value2); + // (clustering_0, clustering1, clustering_2, clustering_3) >= (1, 2, 3, 4) AND (clustering_0, clustering1, clustering_2, clustering_3) <= (4, 3, 2, 1) + slice = newMultiSlice(cfMetaData, 0, Bound.START, true, value1, value2, value3, value4); + slice2 = newMultiSlice(cfMetaData, 0, Bound.END, true, value4, value3, value2, value1); - restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator); + restrictions = new PrimaryKeyRestrictionSet(cfMetaData.comparator, false); restrictions = restrictions.mergeWith(slice).mergeWith(slice2); - bounds = restrictions.boundsAsComposites(Bound.START, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertStartBound(get(bounds, 0), true, value1); + assertEquals(3, bounds.size()); - assertComposite(bounds.get(0), value1, value2, EOC.START); - assertComposite(bounds.get(1), value1, value2, EOC.END); - assertComposite(bounds.get(2), value4, value3, value2, value1, EOC.NONE); ++ assertStartBound(get(bounds, 0), true, value1, value2); ++ assertStartBound(get(bounds, 1), false, value1, value2); ++ assertStartBound(get(bounds, 2), true, value4, value3, value2, value1); - bounds = restrictions.boundsAsComposites(Bound.END, QueryOptions.DEFAULT); + bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT); - assertEquals(1, bounds.size()); - assertEndBound(get(bounds, 0), true, value2); + assertEquals(3, bounds.size()); - assertComposite(bounds.get(0), value1, value2, value3, value4, EOC.END); - assertComposite(bounds.get(1), value4, value3, EOC.START); - assertComposite(bounds.get(2), value4, value3, EOC.END); ++ assertEndBound(get(bounds, 0), true, value1, value2, value3, value4); ++ assertEndBound(get(bounds, 1), false, value4, value3); ++ assertEndBound(get(bounds, 2), true, value4, value3); } /** - * Test multi-column slice restrictions (e.g '(clustering_0, clustering_1) > (1, 2)') + * Test multi-column slice restrictions with ascending, descending, ascending and descending columns + * (e.g '(clustering_0, clustering1, clustering_3, clustering4) > (1, 2, 3, 4)') */ @Test - public void testboundsAsClusteringWithMultiSliceRestrictionsWithTwo
<TRUNCATED>