Search in sources :

Example 26 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithSeveralMultiColumnRestrictions.

@Test
public void testBoundsAsClusteringWithSeveralMultiColumnRestrictions() {
    TableMetadata tableMetadata = newTableMetadata(Sort.ASC, Sort.ASC, Sort.ASC, Sort.ASC);
    ByteBuffer value1 = ByteBufferUtil.bytes(1);
    ByteBuffer value2 = ByteBufferUtil.bytes(2);
    ByteBuffer value3 = ByteBufferUtil.bytes(3);
    ByteBuffer value4 = ByteBufferUtil.bytes(4);
    ByteBuffer value5 = ByteBufferUtil.bytes(5);
    // (clustering_0, clustering_1) = (1, 2) AND (clustering_2, clustering_3) > (3, 4)
    Restriction multiEq = newMultiEq(tableMetadata, 0, value1, value2);
    Restriction multiSlice = newMultiSlice(tableMetadata, 2, Bound.START, false, value3, value4);
    ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
    restrictions = restrictions.mergeWith(multiEq).mergeWith(multiSlice);
    SortedSet<ClusteringBound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertStartBound(get(bounds, 0), false, value1, value2, value3, value4);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), true, value1, value2);
    // (clustering_0, clustering_1) = (1, 2) AND (clustering_2, clustering_3) IN ((3, 4), (4, 5))
    multiEq = newMultiEq(tableMetadata, 0, value1, value2);
    Restriction multiIN = newMultiIN(tableMetadata, 2, asList(value3, value4), asList(value4, value5));
    restrictions = new ClusteringColumnRestrictions(tableMetadata);
    restrictions = restrictions.mergeWith(multiEq).mergeWith(multiIN);
    bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
    assertEquals(2, bounds.size());
    assertStartBound(get(bounds, 0), true, value1, value2, value3, value4);
    assertStartBound(get(bounds, 1), true, value1, value2, value4, value5);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(2, bounds.size());
    assertEndBound(get(bounds, 0), true, value1, value2, value3, value4);
    assertEndBound(get(bounds, 1), true, value1, value2, value4, value5);
    // (clustering_0, clustering_1) = (1, 2) AND (clustering_2, clustering_3) = (3, 4)
    multiEq = newMultiEq(tableMetadata, 0, value1, value2);
    Restriction multiEq2 = newMultiEq(tableMetadata, 2, value3, value4);
    restrictions = new ClusteringColumnRestrictions(tableMetadata);
    restrictions = restrictions.mergeWith(multiEq).mergeWith(multiEq2);
    bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertStartBound(get(bounds, 0), true, value1, value2, value3, value4);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), true, value1, value2, value3, value4);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 27 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithMultiEqAndSingleSliceRestrictions.

/**
     * Test mixing multi equal restrictions with single-column slice restrictions
     * (e.g. clustering_0 = 1 AND (clustering_1, clustering_2) > (2, 3))
     */
@Test
public void testBoundsAsClusteringWithMultiEqAndSingleSliceRestrictions() {
    TableMetadata tableMetadata = newTableMetadata(Sort.ASC, Sort.ASC, Sort.ASC);
    ByteBuffer value1 = ByteBufferUtil.bytes(1);
    ByteBuffer value2 = ByteBufferUtil.bytes(2);
    ByteBuffer value3 = ByteBufferUtil.bytes(3);
    // (clustering_0, clustering_1) = (1, 2) AND clustering_2 > 3
    Restriction multiEq = newMultiEq(tableMetadata, 0, value1, value2);
    Restriction singleSlice = newSingleSlice(tableMetadata, 2, Bound.START, false, value3);
    ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
    restrictions = restrictions.mergeWith(multiEq).mergeWith(singleSlice);
    SortedSet<ClusteringBound> bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertStartBound(get(bounds, 0), false, value1, value2, value3);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), true, value1, value2);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 28 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithMultiSliceRestrictionsWithOneDescendingClusteringColumn.

/**
     * Test multi-column slice restrictions (e.g '(clustering_0) > (1)') with only one clustering column in reverse
     * order
     */
@Test
public void testBoundsAsClusteringWithMultiSliceRestrictionsWithOneDescendingClusteringColumn() {
    TableMetadata tableMetadata = newTableMetadata(Sort.DESC);
    ByteBuffer value1 = ByteBufferUtil.bytes(1);
    ByteBuffer value2 = ByteBufferUtil.bytes(2);
    Restriction slice = newMultiSlice(tableMetadata, 0, Bound.START, false, value1);
    ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
    restrictions = restrictions.mergeWith(slice);
    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());
    assertEndBound(get(bounds, 0), false, value1);
    slice = newMultiSlice(tableMetadata, 0, Bound.START, true, value1);
    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);
    slice = newMultiSlice(tableMetadata, 0, Bound.END, true, value1);
    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);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEmptyEnd(get(bounds, 0));
    slice = newMultiSlice(tableMetadata, 0, Bound.END, false, value1);
    restrictions = new ClusteringColumnRestrictions(tableMetadata);
    restrictions = restrictions.mergeWith(slice);
    bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertStartBound(get(bounds, 0), false, value1);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEmptyEnd(get(bounds, 0));
    slice = newMultiSlice(tableMetadata, 0, Bound.START, false, value1);
    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, value2);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), false, value1);
    slice = newMultiSlice(tableMetadata, 0, Bound.START, true, value1);
    slice2 = newMultiSlice(tableMetadata, 0, Bound.END, true, 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), true, value2);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), true, value1);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 29 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithSliceRestrictionsAndOneClusteringColumn.

/**
     * Test slice restriction (e.g 'clustering_0 > 1') with only one clustering column
     */
@Test
public void testBoundsAsClusteringWithSliceRestrictionsAndOneClusteringColumn() {
    TableMetadata tableMetadata = newTableMetadata(Sort.ASC, Sort.ASC);
    ByteBuffer value1 = ByteBufferUtil.bytes(1);
    ByteBuffer value2 = ByteBufferUtil.bytes(2);
    Restriction slice = newSingleSlice(tableMetadata, 0, Bound.START, false, value1);
    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);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEmptyEnd(get(bounds, 0));
    slice = newSingleSlice(tableMetadata, 0, Bound.START, true, value1);
    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);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEmptyEnd(get(bounds, 0));
    slice = newSingleSlice(tableMetadata, 0, Bound.END, true, value1);
    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);
    slice = newSingleSlice(tableMetadata, 0, Bound.END, false, value1);
    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);
    slice = newSingleSlice(tableMetadata, 0, Bound.START, false, value1);
    Restriction slice2 = newSingleSlice(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);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), false, value2);
    slice = newSingleSlice(tableMetadata, 0, Bound.START, true, value1);
    slice2 = newSingleSlice(tableMetadata, 0, Bound.END, true, 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), true, value1);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), true, value2);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 30 with TableMetadata

use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.

the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithMultiSliceRestrictionsWithTwoDescendingClusteringColumns.

/**
     * Test multi-column slice restrictions with 2 descending clustering columns (e.g '(clustering_0, clustering_1) > (1, 2)')
     */
@Test
public void testBoundsAsClusteringWithMultiSliceRestrictionsWithTwoDescendingClusteringColumns() {
    TableMetadata tableMetadata = newTableMetadata(Sort.DESC, 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(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)
    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());
    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, 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, false, 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), false, value1, value2);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEmptyEnd(get(bounds, 0));
    // (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, value2);
    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, 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, value2, value1);
    bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
    assertEquals(1, bounds.size());
    assertEndBound(get(bounds, 0), true, value1, value2);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ByteBuffer(java.nio.ByteBuffer) 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