use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithOneEqRestrictionsAndTwoClusteringColumns.
/**
* Test 'clustering_1 = 1' with 2 clustering columns
*/
@Test
public void testBoundsAsClusteringWithOneEqRestrictionsAndTwoClusteringColumns() {
TableMetadata tableMetadata = newTableMetadata(Sort.ASC, 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 testBoundsAsClusteringWithSingleEqAndSliceRestrictions.
/**
* Test mixing single equal restrictions with multi-column slice restrictions
* (e.g. clustering_0 = 1 AND (clustering_1, clustering_2) > (2, 3))
*/
@Test
public void testBoundsAsClusteringWithSingleEqAndSliceRestrictions() {
TableMetadata tableMetadata = newTableMetadata(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 = 1 AND (clustering_1, clustering_2) > (2, 3)
Restriction singleEq = newSingleEq(tableMetadata, 0, value1);
Restriction multiSlice = newMultiSlice(tableMetadata, 1, Bound.START, false, value2, value3);
ClusteringColumnRestrictions restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(singleEq).mergeWith(multiSlice);
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);
// clustering_0 = 1 AND (clustering_1, clustering_2) > (2, 3) AND (clustering_1) < (4)
singleEq = newSingleEq(tableMetadata, 0, value1);
multiSlice = newMultiSlice(tableMetadata, 1, Bound.START, false, value2, value3);
Restriction multiSlice2 = newMultiSlice(tableMetadata, 1, Bound.END, false, value4);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(multiSlice2).mergeWith(singleEq).mergeWith(multiSlice);
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), false, value1, value4);
// clustering_0 = 1 AND (clustering_1, clustering_2) => (2, 3) AND (clustering_1, clustering_2) <= (4, 5)
singleEq = newSingleEq(tableMetadata, 0, value1);
multiSlice = newMultiSlice(tableMetadata, 1, Bound.START, true, value2, value3);
multiSlice2 = newMultiSlice(tableMetadata, 1, Bound.END, true, value4, value5);
restrictions = new ClusteringColumnRestrictions(tableMetadata);
restrictions = restrictions.mergeWith(multiSlice2).mergeWith(singleEq).mergeWith(multiSlice);
bounds = restrictions.boundsAsClustering(Bound.START, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertStartBound(get(bounds, 0), true, value1, value2, value3);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), true, value1, value4, value5);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class SecondaryIndexTest method testMultipleIndexesOnOneColumn.
@Test
public void testMultipleIndexesOnOneColumn() throws Throwable {
String indexClassName = StubIndex.class.getName();
createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY ((a), b))");
// uses different options otherwise the two indexes are considered duplicates
createIndex(String.format("CREATE CUSTOM INDEX c_idx_1 ON %%s(c) USING '%s' WITH OPTIONS = {'foo':'a'}", indexClassName));
createIndex(String.format("CREATE CUSTOM INDEX c_idx_2 ON %%s(c) USING '%s' WITH OPTIONS = {'foo':'b'}", indexClassName));
ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
TableMetadata cfm = cfs.metadata();
StubIndex index1 = (StubIndex) cfs.indexManager.getIndex(cfm.indexes.get("c_idx_1").orElseThrow(throwAssert("index not found")));
StubIndex index2 = (StubIndex) cfs.indexManager.getIndex(cfm.indexes.get("c_idx_2").orElseThrow(throwAssert("index not found")));
Object[] row1a = row(0, 0, 0);
Object[] row1b = row(0, 0, 1);
Object[] row2 = row(2, 2, 2);
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", row1a);
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", row1b);
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?)", row2);
assertEquals(2, index1.rowsInserted.size());
assertColumnValue(0, "c", index1.rowsInserted.get(0), cfm);
assertColumnValue(2, "c", index1.rowsInserted.get(1), cfm);
assertEquals(2, index2.rowsInserted.size());
assertColumnValue(0, "c", index2.rowsInserted.get(0), cfm);
assertColumnValue(2, "c", index2.rowsInserted.get(1), cfm);
assertEquals(1, index1.rowsUpdated.size());
assertColumnValue(0, "c", index1.rowsUpdated.get(0).left, cfm);
assertColumnValue(1, "c", index1.rowsUpdated.get(0).right, cfm);
assertEquals(1, index2.rowsUpdated.size());
assertColumnValue(0, "c", index2.rowsUpdated.get(0).left, cfm);
assertColumnValue(1, "c", index2.rowsUpdated.get(0).right, cfm);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class SecondaryIndexTest method testDeletions.
@Test
public void testDeletions() throws Throwable {
// Test for bugs like CASSANDRA-10694. These may not be readily visible with the built-in secondary index
// implementation because of the stale entry handling.
String indexClassName = StubIndex.class.getName();
createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY ((a), b))");
createIndex(String.format("CREATE CUSTOM INDEX c_idx ON %%s(c) USING '%s'", indexClassName));
ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
TableMetadata cfm = cfs.metadata();
StubIndex index1 = (StubIndex) cfs.indexManager.getIndex(cfm.indexes.get("c_idx").orElseThrow(throwAssert("index not found")));
execute("INSERT INTO %s (a, b, c) VALUES (?, ?, ?) USING TIMESTAMP 1", 0, 0, 0);
assertEquals(1, index1.rowsInserted.size());
execute("DELETE FROM %s USING TIMESTAMP 2 WHERE a = ? AND b = ?", 0, 0);
assertEquals(1, index1.rowsUpdated.size());
Pair<Row, Row> update = index1.rowsUpdated.get(0);
Row existingRow = update.left;
Row newRow = update.right;
// check the existing row from the update call
assertTrue(existingRow.deletion().isLive());
assertEquals(DeletionTime.LIVE, existingRow.deletion().time());
assertEquals(1L, existingRow.primaryKeyLivenessInfo().timestamp());
// check the new row from the update call
assertFalse(newRow.deletion().isLive());
assertEquals(2L, newRow.deletion().time().markedForDeleteAt());
assertFalse(newRow.cells().iterator().hasNext());
// delete the same row again
execute("DELETE FROM %s USING TIMESTAMP 3 WHERE a = ? AND b = ?", 0, 0);
assertEquals(2, index1.rowsUpdated.size());
update = index1.rowsUpdated.get(1);
existingRow = update.left;
newRow = update.right;
// check the new row from the update call
assertFalse(existingRow.deletion().isLive());
assertEquals(2L, existingRow.deletion().time().markedForDeleteAt());
assertFalse(existingRow.cells().iterator().hasNext());
// check the new row from the update call
assertFalse(newRow.deletion().isLive());
assertEquals(3L, newRow.deletion().time().markedForDeleteAt());
assertFalse(newRow.cells().iterator().hasNext());
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class ClusteringColumnRestrictionsTest method testBoundsAsClusteringWithMultiSliceRestrictionsWithOneClusteringColumn.
/**
* Test multi-column slice restrictions (e.g '(clustering_0) > (1)') with only one clustering column
*/
@Test
public void testBoundsAsClusteringWithMultiSliceRestrictionsWithOneClusteringColumn() {
TableMetadata tableMetadata = newTableMetadata(Sort.ASC);
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());
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, 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, 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, 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 = 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, value1);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), false, value2);
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, value1);
bounds = restrictions.boundsAsClustering(Bound.END, QueryOptions.DEFAULT);
assertEquals(1, bounds.size());
assertEndBound(get(bounds, 0), true, value2);
}
Aggregations