use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.
the class SelectorIntegrationTest method testIterateSuperColumnsFromRowUsingOnlyNext.
@Test
public void testIterateSuperColumnsFromRowUsingOnlyNext() {
Iterator<SuperColumn> iterator = createSelector().iterateSuperColumnsFromRow(SCF, fromLong(50l), null, false, 10, ConsistencyLevel.ONE);
char letter = 'A';
int count = 0;
for (int i = 0; i < 26; i++) {
SuperColumn superColumn = iterator.next();
assertEquals("Wrong super column value returned", letter, Bytes.fromByteArray(superColumn.getName()).toChar());
letter++;
count++;
}
assertEquals("Not all super columns were processed", 26, count);
try {
iterator.next();
fail("The iterator should have thrown a NoSuchElementException exception");
} catch (NoSuchElementException e) {
// expected
}
}
use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.
the class SelectorIntegrationTest method testIterateSuperColumnsFromRow.
@Test
public void testIterateSuperColumnsFromRow() {
for (char letter = 'A'; letter <= 'Z'; letter++) {
}
Iterator<SuperColumn> iterator = createSelector().iterateSuperColumnsFromRow(SCF, fromLong(50l), null, false, 10, ConsistencyLevel.ONE);
char letter = 'A';
int count = 0;
while (iterator.hasNext()) {
SuperColumn superColumn = iterator.next();
assertEquals("Wrong super column value returned", letter, Bytes.fromByteArray(superColumn.getName()).toChar());
letter++;
count++;
}
assertEquals("Not all super columns were processed", 26, count);
}
use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.
the class Mutator method writeSubColumnsInternal.
/**
* Writes multiple sub-column values to a super column.
*
* @param colFamily The column family
* @param rowKey The key of the row to modify
* @param colName The name of the super column
* @param subColumns A list of the sub-columns to write
*/
private void writeSubColumnsInternal(String colFamily, Bytes rowKey, Bytes colName, List<Column> subColumns) {
safeGetRowKey(rowKey);
validateColumnName(colName);
validateColumns(subColumns);
SuperColumn scol = new SuperColumn(nullSafeGet(colName), subColumns);
ColumnOrSuperColumn cosc = new ColumnOrSuperColumn();
cosc.setSuper_column(scol);
Mutation mutation = new Mutation();
mutation.setColumn_or_supercolumn(cosc);
getMutationList(colFamily, rowKey).add(mutation);
}
use of org.apache.cassandra.thrift.SuperColumn in project scale7-pelops by s7.
the class Selector method getPageOfSuperColumnsFromRow.
/**
* Retrieve a page of super columns composed from a segment of the sequence of super columns in a row.
* @param columnFamily The name of the column family containing the super columns
* @param rowKey The key of the row
* @param startBeyondName The sequence of super columns must begin with the smallest super column name greater than this value. Pass <code>null</code> to start at the beginning of the sequence.
* @param reversed Whether the scan should proceed in descending super column name order
* @param count The maximum number of super columns that can be retrieved by the scan
* @param cLevel The Cassandra consistency level with which to perform the operation
* @return A page of super columns
* @throws PelopsException if an error occurs
*/
public List<SuperColumn> getPageOfSuperColumnsFromRow(String columnFamily, Bytes rowKey, Bytes startBeyondName, boolean reversed, int count, ConsistencyLevel cLevel) throws PelopsException {
if (Bytes.nullSafeGet(startBeyondName) == null) {
SlicePredicate predicate = Selector.newColumnsPredicateAll(reversed, count);
return getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
} else {
// cassandra will return the start row but the user is expecting a page of results beyond that point
int incrementedCount = count + 1;
SlicePredicate predicate = Selector.newColumnsPredicate(startBeyondName, Bytes.EMPTY, reversed, incrementedCount);
List<SuperColumn> columns = getSuperColumnsFromRow(columnFamily, rowKey, predicate, cLevel);
if (columns.size() > 0) {
SuperColumn first = columns.get(0);
if (first.name.equals(startBeyondName.getBytes()))
return columns.subList(1, columns.size());
else if (columns.size() == incrementedCount)
return columns.subList(0, columns.size() - 1);
}
return columns;
}
}
Aggregations