Search in sources :

Example 86 with TableMetadata

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 87 with TableMetadata

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 88 with TableMetadata

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 89 with TableMetadata

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 90 with TableMetadata

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));
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Test(org.junit.Test)

Aggregations

TableMetadata (org.apache.cassandra.schema.TableMetadata)129 Test (org.junit.Test)63 ByteBuffer (java.nio.ByteBuffer)29 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)17 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)13 File (java.io.File)10 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)10 Mutation (org.apache.cassandra.db.Mutation)8 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)8 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)8 Descriptor (org.apache.cassandra.io.sstable.Descriptor)7 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)6 IOException (java.io.IOException)5 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)5 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)5 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)5 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)4 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)4 AbstractType (org.apache.cassandra.db.marshal.AbstractType)4 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)4