use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithOneEqRestrictionsAndOneClusteringColumn.
/**
* Test 'clustering_0 = 1' with only one clustering column
*/
@Test
public void testBoundsAsClusteringWithOneEqRestrictionsAndOneClusteringColumn() {
TableMetadata tableMetadata = newTableMetadata(Sort.ASC);
ByteBuffer clustering_0 = ByteBufferUtil.bytes(1);
Restriction eq = newSingleEq(tableMetadata, 0, clustering_0);
ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(eq);
SortedSet<ClusteringBound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertStartBound(get(bounds, 0), true, clustering_0);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), true, clustering_0);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithEqAndInRestrictions.
/**
* Test 'clustering_0 = 1 AND clustering_1 IN (1, 2, 3)'
*/
@Test
public void testBoundsAsClusteringWithEqAndInRestrictions() {
TableMetadata tableMetadata = newTableMetadata(Sort.ASC, Sort.ASC);
ByteBuffer value1 = ByteBufferUtil.bytes(1);
ByteBuffer value2 = ByteBufferUtil.bytes(2);
ByteBuffer value3 = ByteBufferUtil.bytes(3);
Restriction eq = newSingleEq(tableMetadata, 0, value1);
Restriction in = newSingleIN(tableMetadata, 1, value1, value2, value3);
ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(eq).mergeWith(in);
SortedSet<ClusteringBound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(3, bounds.size());
assertStartBound(get(bounds, 0), true, value1, value1);
assertStartBound(get(bounds, 1), true, value1, value2);
assertStartBound(get(bounds, 2), true, value1, value3);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(3, bounds.size());
assertEndBound(get(bounds, 0), true, value1, value1);
assertEndBound(get(bounds, 1), true, value1, value2);
assertEndBound(get(bounds, 2), true, value1, value3);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithMultiSliceRestrictionsWithTwoClusteringColumn.
/**
* Test multi-column slice restrictions (e.g '(clustering_0, clustering_1) > (1, 2)')
*/
@Test
public void testBoundsAsClusteringWithMultiSliceRestrictionsWithTwoClusteringColumn() {
TableMetadata tableMetadata = newTableMetadata(Sort.ASC, Sort.ASC);
ByteBuffer value1 = ByteBufferUtil.bytes(1);
ByteBuffer value2 = ByteBufferUtil.bytes(2);
// (clustering_0, clustering1) > (1, 2)
Restriction slice = newMultiSlice(tableMetadata, 0, Bound.START, false, value1, value2);
ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
SortedSet<ClusteringBound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertStartBound(get(bounds, 0), false, value1, value2);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEmptyEnd(get(bounds, 0));
// (clustering_0, clustering1) >= (1, 2)
slice = newMultiSlice(tableMetadata, 0, Bound.START, true, value1, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertStartBound(get(bounds, 0), true, value1, value2);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEmptyEnd(get(bounds, 0));
// (clustering_0, clustering1) <= (1, 2)
slice = newMultiSlice(tableMetadata, 0, Bound.END, true, value1, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEmptyStart(get(bounds, 0));
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), true, value1, value2);
// (clustering_0, clustering1) < (1, 2)
slice = newMultiSlice(tableMetadata, 0, Bound.END, false, value1, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEmptyStart(get(bounds, 0));
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), false, value1, value2);
// (clustering_0, clustering1) > (1, 2) AND (clustering_0) < (2)
slice = newMultiSlice(tableMetadata, 0, Bound.START, false, value1, value2);
Restriction slice2 = newMultiSlice(tableMetadata, 0, Bound.END, false, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice).mergeWith(slice2);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertStartBound(get(bounds, 0), false, value1, value2);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), false, value2);
// (clustering_0, clustering1) >= (1, 2) AND (clustering_0, clustering1) <= (2, 1)
slice = newMultiSlice(tableMetadata, 0, Bound.START, true, value1, value2);
slice2 = newMultiSlice(tableMetadata, 0, Bound.END, true, value2, value1);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice).mergeWith(slice2);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertStartBound(get(bounds, 0), true, value1, value2);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), true, value2, value1);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithMultiSliceRestrictionsWithOneAscendingAndOneDescendingClusteringColumns.
/**
* Test multi-column slice restrictions with 1 descending clustering column and 1 ascending
* (e.g '(clustering_0, clustering_1) > (1, 2)')
*/
@Test
public void testBoundsAsClusteringWithMultiSliceRestrictionsWithOneAscendingAndOneDescendingClusteringColumns() {
TableMetadata tableMetadata = newTableMetadata(Sort.ASC, Sort.DESC);
ByteBuffer value1 = ByteBufferUtil.bytes(1);
ByteBuffer value2 = ByteBufferUtil.bytes(2);
// (clustering_0, clustering1) > (1, 2)
Restriction slice = newMultiSlice(tableMetadata, 0, Bound.START, false, value1, value2);
ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
SortedSet<ClusteringBound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertStartBound(get(bounds, 0), true, value1);
assertStartBound(get(bounds, 1), false, value1);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertEndBound(get(bounds, 0), false, value1, value2);
assertEmptyEnd(get(bounds, 1));
// (clustering_0, clustering1) >= (1, 2)
slice = newMultiSlice(tableMetadata, 0, Bound.START, true, value1, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertStartBound(get(bounds, 0), true, value1);
assertStartBound(get(bounds, 1), false, value1);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertEndBound(get(bounds, 0), true, value1, value2);
assertEmptyEnd(get(bounds, 1));
// (clustering_0, clustering1) <= (1, 2)
slice = newMultiSlice(tableMetadata, 0, Bound.END, true, value1, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertEmptyStart(get(bounds, 0));
assertStartBound(get(bounds, 1), true, value1, value2);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertEndBound(get(bounds, 0), false, value1);
assertEndBound(get(bounds, 1), true, value1);
// (clustering_0, clustering1) < (1, 2)
slice = newMultiSlice(tableMetadata, 0, Bound.END, false, value1, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertEmptyStart(get(bounds, 0));
assertStartBound(get(bounds, 1), false, value1, value2);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertEndBound(get(bounds, 0), false, value1);
assertEndBound(get(bounds, 1), true, value1);
// (clustering_0, clustering1) > (1, 2) AND (clustering_0) < (2)
slice = newMultiSlice(tableMetadata, 0, Bound.START, false, value1, value2);
Restriction slice2 = newMultiSlice(tableMetadata, 0, Bound.END, false, value2);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice).mergeWith(slice2);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertStartBound(get(bounds, 0), true, value1);
assertStartBound(get(bounds, 1), false, value1);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(2, bounds.size());
assertEndBound(get(bounds, 0), false, value1, value2);
assertEndBound(get(bounds, 1), false, value2);
// (clustering_0, clustering1) >= (1, 2) AND (clustering_0, clustering1) <= (2, 1)
slice = newMultiSlice(tableMetadata, 0, Bound.START, true, value1, value2);
slice2 = newMultiSlice(tableMetadata, 0, Bound.END, true, value2, value1);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(slice).mergeWith(slice2);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(3, bounds.size());
assertStartBound(get(bounds, 0), true, value1);
assertStartBound(get(bounds, 1), false, value1);
assertStartBound(get(bounds, 2), true, value2, value1);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(3, bounds.size());
assertEndBound(get(bounds, 0), true, value1, value2);
assertEndBound(get(bounds, 1), false, value2);
assertEndBound(get(bounds, 2), true, value2);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithNoRestrictions.
@Test
public void testBoundsAsClusteringWithNoRestrictions() {
TableMetadata tableMetadata = newTableMetadata(Sort.ASC);
ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
SortedSet<ClusteringBound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEmptyStart(get(bounds, 0));
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEmptyEnd(get(bounds, 0));
}
Aggregations